Jump to content

Literals/Floating point: Difference between revisions

m
→‎{{header|Visual Basic}}: handling not-a-number
m (→‎{{header|Visual Basic}}: handling not-a-number)
Line 1,341:
s = 2! * 10 ^ 3
End Sub</lang>
There is no built-in support for not-a-number, but here's a way to handle that anyway:
<lang vb>Option Explicit
Public Declare Function RtlCompareMemory Lib "ntdll.dll" _
(ByRef Source1 As Any, ByRef Source2 As Any, ByVal Length As Long) As Long
 
Public Function IsNAN(ByRef d As Double) As Boolean
Dim d1 As Double
d1 = NaN()
IsNAN = (RtlCompareMemory(d, d1, 8) = 8)
End Function
 
Public Function NaN() As Double
On Error Resume Next ' ignore the error
NaN = 0 / 0
End Function
 
Sub Main()
Dim d1 As Double
Dim d2 As Double
d1 = NaN()
d2 = d1
Debug.Assert IsNAN(d2)
Debug.Print CStr(d2)
End Sub</lang>
{{out}}
<pre>-1,#IND</pre>
 
=={{header|XPL0}}==
Cookies help us deliver our services. By using our services, you agree to our use of cookies.