Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Working with NAN
#11
Thanks for this Steve. INF I think I have a working solution. NaN's been escaping me. I'm not sure if others who may be following this thread might find your treatment of INF handy.
Reply
#12
(09-09-2023, 06:48 PM)Dimster Wrote: Thanks for this Steve. INF I think I have a working solution. NaN's been escaping me. I'm not sure if others who may be following this thread might find your treatment of INF handy.

Glad to be of service.  Big Grin
Reply
#13
@Dimster You might want to double check my code there.

DECLARE CUSTOMTYPE LIBRARY "isnan"
FUNCTION IsNan% (BYVAL n AS DOUBLE)
END DECLARE

I'm kinda surprised that worked before. We should be passing values BYVAL, and I left that out above. I just had my gallbladder removed yesterday and I'm still on some NICE pain meds for the next few days as I heal up. My brain is probably at 50% capacity so double check anything I say for now. LOL,
Reply
#14
Try this as a properly working version:

Save as isnan.h:
Code: (Select All)
#include <stdio.h>
#include <math.h>
#include <float.h>

int IsNan (long double n);
int IsInf (long double n);

IsNan (long double n) { return -isnan(n); }
IsInf (long double n) { return -isinf(n); }
And the test code to check for NaN and Inf:
Code: (Select All)
DECLARE LIBRARY "isnan"
    FUNCTION IsNan% (BYVAL n AS _FLOAT)
    FUNCTION IsInf% (BYVAL n AS _FLOAT)
END DECLARE

PRINT IsNan(0 / 0), IsInf(0 / 0)
PRINT IsInf(1 / 0), IsInf(1 / 0)
PRINT IsInf(0 / 1), IsInf(0 / 1)

Notice the output is:
0 / 0 is NaN but is *not* INF.
1 / 0 is NaN and is also INF.
0 / 1 is neither NaN, nor is it INF.
Reply
#15
@smcneill this should go on wiki. Heart

Glad your surgery was a success and healing up.
grymmjack (gj!)
GitHubYouTube | Soundcloud | 16colo.rs
Reply
#16
In SICK it is:

Code: (Select All)
5 Rem Qnan.sic
10 Print "-1// equals: ";
20 Print Suffix(-1//) '  as  -1.#IND  (cannot be calculated/NAN - not a number)
30 Print "-(-1//) equals: ";
40 Print Suffix(-(-1//)) '  as  1.#QNAN (results as a quotient not a number)
50 Print "1/0 equals: ";
60 Print Suffix(1/0)  '  as  1.#INF  (underflow) (division by zero)
70 Print "-(1/0) equals: ";
80 Print Suffix(-(1/0)) '  as  -1.#INF  (negative underflow) (division by zero)
Reply




Users browsing this thread: 2 Guest(s)