`Double.IsNotANumber` and `Double.IsInfinite` are broken

I recently stumbled upon two new methods added to 2020r1: Double.IsInfinite and Double.IsNotANumber. I currently do these checks extensively in my physics engine but have to use the slow Double.ToString method and then check the String for "nan" or "inf". Unfortunately, these methods are completely broken.


// Infinity
Var posInf As Double = 1.0 / 0.0
Var negInf As Double = -1.0 / 0.0

// Some NaN values.
Var ZeroZero As Double = 0.0 / 0.0
Var infMinusInf As Double = posInf - posInf
Var infMultZero As Double = posInf * 0.0

// These should be set to True but are erroneously set to False.
Var isNanDouble1 As Boolean = ZeroZero.IsNotANumber // False (incorrect)
Var isNanDouble2 As Boolean = infMinusInf.IsNotANumber // False (incorrect)
Var isNanDouble3 As Boolean = infMultZero.IsNotANumber // False (incorrect)

// Test the `Double.IsInfinite` method.
Var isInfDouble1 As Boolean = posInf.IsInfinite // False (incorrect)
Var isInfDouble2 As Boolean = negInf.IsInfinite // False (incorrect)

// Using the slow `Double.ToString` method gives the correct results.
Var isNanString1 As Boolean = If(ZeroZero.ToString.IndexOf("nan") <> -1, True, False) // True (correct)
Var isNanString2 As Boolean = If(infMinusInf.ToString.IndexOf("nan") <> -1, True, False) // True (correct)
Var isNanString3 As Boolean = If(infMultZero.ToString.IndexOf("nan") <> -1, True, False) // True (correct)
Var isInfString1 As Boolean = If(posInf.ToString.IndexOf("inf") <> -1, True, False) // True (correct)
Var isInfString2 As Boolean = If(negInf.ToString.IndexOf("inf") <> -1, True, False) // True (correct)

// Test with an actual real number.
Var d As Double = 100.45
Var isNanDouble4 As Boolean = d.IsNotANumber // False (correct)
Var isNanString4 As Boolean
If d.ToString.IndexOf("nan") <> -1 And d.ToString.IndexOf("inf") <> -1 Then
  isNanString4 = True
  isNanString4 = False
End If


Feedback case: <https://xojo.com/issue/61805>

This is on macOS 10.15.6 running 2020r1.

@William_Yu: I believe you implemented these method of your own accord. Did something break when they were renamed to be API 2.0 compliant (they used to be called Double.IsNaN and Double.IsInfinite)?

1 Like

Thanks, this is definitely broken as it looks like IsInfinite got implemented as IsNotANumber and vice versa.

1 Like

Tilt !