1. check for inf/nan [SOLVED]
- Posted by petelomax Nov 04, 2022
- 747 views
- Last edited Nov 10, 2022
I recently made a couple of (admitedly a tad silly) tweaks to printf() so that it would print powers of 2 (from -1074 to +1024) perfectly.
Not exactly surprisingly it came a bit of a cropper when presented with +/-inf/nan, so as a "quick fix" I slapped in:
and atom_to_float64(o)[$]!=127 -- not [+/-]nan/inf
which has solved the immediate issue, however I wanted to ask if anyone knows the "proper" way to check.
My attempts at googling this ran me straight into language-specific isnan()-style functions, but I couldn't find the nitty-gritty.
I need something that works with 64 and 80-bit floats.
Also, that (from -1074 to +1024) was lifted straight from an article on dealing with said for 64-bit floats, and
I wouldn't mind knowing what the equivalent limits are for 80-bit floats.
2. Re: check for inf/nan
- Posted by SDPringle Nov 07, 2022
- 607 views
Take a look at std/scinot.e at the contents of the scientific_to_float() routine.
3. Re: check for inf/nan
- Posted by petelomax Nov 10, 2022
- 562 views
That was all a bit more effort than anticipated... Took a while to sink in that IEEE 754 does not fully specify NaN, as it says right there on the wikipedia page.
Anyway, Phix has now got proper working builtin is_nan() and is_inf() functions.