Andras wrote:Take a look at this, you could write your own Check-Functions:
I could, but I won't. I don't need it for my PB projects, but I used it at work in a project in VB quite successfully last week. It's more a "useful" than "can I have".
Also the checking for equality does not work (within PureBasic?)...
Testing for equality to the special floating point values should always work*. They are one specific value, and should not be any other. The problem with testing for equality with floating point numbers is apparent in any language, and while possible to equate, shouldn't normally be used since rounding errors might prevent the comparison from succeeding.
For example:
Code: Select all
a.f=0.25
If a=0.25
Debug "this might work, dunno haven't tested"
EndIf
For a.f=0 To 0.5 Step 0.01
If a=0.25
Debug "this might not"
EndIf
Next
The first might work because the numbers shoud be easily representable by binary floating point values and no calculations are involved, whereas the loop might not due to rounding errors in the incrementing of the a variable.
I know how floating point stuff works. And writing code would be very easy, e.g.:
Code: Select all
Procedure IsNaN(f.f)
If (PeekL(@f)&$7F80000)=$7F80000 And (PeekL(@f)&$007FFFF)<>0
isnan=1
EndIf
ProcedureReturn isnan
endprocedure
But I'd rather have it as part of the language. Wouldn't it be easier to call IsNan() for any type of floating point value (assuming more than just SP floats are supported in future) rather than having to call IsNaNSP(), IsNaNDP(), IsNaNEP() etc and you as a programmer having to make that choice depending on whether you can remember what types your variables are?
*Edit: at least, the way I'd like to see them in PB. Ignore my explanation, I read your code wrongly. Sorry. PS, direct comparisons to NaN can't work in your code since the mantissa is not any specific value. You'd need bit masking.
If you paint your butt blue and glue the hole shut you just themed your ass but lost the functionality.
(WinXPhSP3 PB5.20b14)