?
=?ISO-8859-1?Q?Martin_J=F8rgensen?=
Hi,
I found the code below from
http://www.blitzbasic.com/Community/posts.php?topic=55633
------
' Check if number is finite.
Local uouble = 2 ' also works for floats
For Local n = 1 To 12
Print isfinite(u) + " " + u
u :* u
Next
Print
Print "What about NaN?"
Print
u = u - u
Print isfinite(u) + " " + u
Function isfinite( xouble ) ' assumes Intel byte order
Const EXP_BITS = %01111111111100000000000000000000
Local bits = ( Int Ptr Varptr x )[1] ' [0] for Mac?
Return ( bits & EXP_BITS ) <> EXP_BITS ' exponent is all 1s for
infinity or NaN
End Function
------
I need something like that - but the author writes that "This is intel
only. Anybody want to make it multiplatform? It shouldn't be difficult,
but I don't have a Mac".
The code above doesn't look like "standard C" to me... But I would like
this function to work *preferable* under both linux, mac and windows
pc's....
My guess is that the code should be changed to something like:
int(double testval)
{
Const EXP_BITS = %01111111111100000000000000000000
return (testval && EXP_BITS); /* returns either 0 or 1 ? */
}
But I guess EXP_BITS is completely wrong defined, so how to make it work
- and are there better existing ways to check for Inf or NaN???
It would be nice with 2 functions: One that tests for plus/minus Inf and
one that checks for NaN, if there's any difference? I didn't really
understood the bit-pattern-difference between NaN and Inf...
Best regards / Med venlig hilsen
Martin Jørgensen
I found the code below from
http://www.blitzbasic.com/Community/posts.php?topic=55633
------
' Check if number is finite.
Local uouble = 2 ' also works for floats
For Local n = 1 To 12
Print isfinite(u) + " " + u
u :* u
Next
Print "What about NaN?"
u = u - u
Print isfinite(u) + " " + u
Function isfinite( xouble ) ' assumes Intel byte order
Const EXP_BITS = %01111111111100000000000000000000
Local bits = ( Int Ptr Varptr x )[1] ' [0] for Mac?
Return ( bits & EXP_BITS ) <> EXP_BITS ' exponent is all 1s for
infinity or NaN
End Function
------
I need something like that - but the author writes that "This is intel
only. Anybody want to make it multiplatform? It shouldn't be difficult,
but I don't have a Mac".
The code above doesn't look like "standard C" to me... But I would like
this function to work *preferable* under both linux, mac and windows
pc's....
My guess is that the code should be changed to something like:
int(double testval)
{
Const EXP_BITS = %01111111111100000000000000000000
return (testval && EXP_BITS); /* returns either 0 or 1 ? */
}
But I guess EXP_BITS is completely wrong defined, so how to make it work
- and are there better existing ways to check for Inf or NaN???
It would be nice with 2 functions: One that tests for plus/minus Inf and
one that checks for NaN, if there's any difference? I didn't really
understood the bit-pattern-difference between NaN and Inf...
Best regards / Med venlig hilsen
Martin Jørgensen