How can I check if Float or Double is infinite or NaN?

Java has an API for checking if a number is infinite or NaN .

I can't find anything like this in Scala, and for calling Java functions it looks like I need to set a value or call java.lang.Double static method:

Double.box(x).isNaN

java.lang.Double.isNaN(x)

      

Isn't there really anything native to Scala for checking for infinity / NaN-ness?

+3


source to share


1 answer


These are methods in a box scala.Double

. You don't need to manually install them.



scala> 1.2.isNaN
res1: Boolean = false

scala> 1.2.isInfinity
res2: Boolean = false

scala> (0.0 / 0.0).isNaN
res8: Boolean = true

scala> (1.0 / 0.0).isInfinity
res5: Boolean = true

      

+7


source







All Articles