Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
IsNan and IsInf Functions
#1
If one ever needs to determine if a calculation generates a Nan result or an INF result, they can always use the following little snippet of code:

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
#2
Thanks for this Steve. Don't mean to highjack this thread but it also demonstrates the use of different kinds of brackets and I was wondering the correct use of them. They are (), [], and {}. The last one in particular I haven't used at all.
Reply
#3
Only the rounded ones, that you get pressing `SHIFT+9` and `SHIFT+0` have anything to do with this BASIC dialect.

In a few BASIC dialects and other languages, the square brackets is sometimes used like `MID$()` for one character. But not in QB64 at the moment.

Don't let yourself confounded by B.A.M., it was Charlie's choice to use other brackets there and only there.
Reply




Users browsing this thread: 1 Guest(s)