How Can I Test For #INF
Posted: Sat Aug 27, 2005 11:20 pm
In a Float Number How do I Test For #INF
like if the program did a division by zero I want to test that?
like if the program did a division by zero I want to test that?
http://www.purebasic.com
https://www.purebasic.fr/english/
Code: Select all
OpenConsole()
x.f=1.0
y.f=0.0
z.f=x/y
Procedure IsInforNaN(x.f)
! mov ebx,dword [esp]
! xor eax, eax
! xor ecx, ecx
! cmp ebx, $ff800000 ;-Inf
! sete cl
! xor edx, edx
! cmp ebx, $7f800000 ;+Inf
! sete dl
! or ecx, edx
! xor edx, edx
! cmp ebx, $ffc00000 ; Ind
! sete dl
! or ecx, edx
! xor edx, edx
! cmp ebx, $7fc00000 ; NaN
! sete dl
! or ecx, edx
! je @
! mov eax, 1
!@:
ProcedureReturn
EndProcedure
PrintN(Str(IsInforNaN(z)))
PrintN("press return key to end")
Input()
CloseConsole()
Code: Select all
x.f=1.0
y.f=0.0
z.f=x/y
a.f=b/c
Debug StrF(z)
Debug StrF(a)
If PeekL(@z)=$7F800000 ;same as 1.#INF00
Debug "Is #INF"
ElseIf PeekL(@z)=$FFC00000 ;same as 1.#IND00
Debug "Is #IND"
Else
Debug "No errors!"
EndIf
If PeekL(@a)=$7F800000 ;same as 1.#INF00
Debug "Is #INF"
ElseIf PeekL(@a)=$FFC00000 ;same as 1.#IND00
Debug "Is #IND"
Else
Debug "No errors!"
EndIf
Code: Select all
If (x=-Infinity) Or (x=+Infinity) Or (x=Indeterminate) Or (x=NaN)
ProcedureReturn 1
Else
ProcedureReturn 0
EndIf
Code: Select all
x.f=-1.0
y.f=0.0
z.f=x/y
Procedure IsInforNaN(x.f)
! mov ebx,dword [esp]
! cmp ebx, $ff800000 ;If -Inf then 1 will be returned
! mov eax, 1
! je @
! cmp ebx, $7f800000 ;If +Inf then 2 will be returned
! mov eax, 2
! je @
! cmp ebx, $ffc00000 ; If Ind then 3 will be returned
! mov eax, 3
! je @
! cmp ebx, $7fc00000 ; If QNaN then 4 will be returned
! mov eax, 4
! je @
! mov eax, 0 ;If float seems ok, return 0
!@:
ProcedureReturn
EndProcedure
Debug IsInforNaN(z)
Debug z