Author Topic: NAN and INFINITY  (Read 2900 times)

0 Members and 1 Guest are viewing this topic.

Aurel

  • Guest
NAN and INFINITY
« on: August 07, 2014, 12:00:59 PM »
wait...
what a heck this string work here...?
#qNAN

this is the string which often jump in string error operations
it looks that is not random sequence of chars....or maybe is  ::)

Mike Lobanovsky

  • Guest
Re: NAN and INFINITY
« Reply #1 on: August 07, 2014, 12:22:19 PM »
Aurel,

NAN stands for not-a-number which is a conventional way to denote a numeric quantity that cannot be expressed correctly in terms of a computer floating-point number using its current exponent and mantissa bit fields. Despite a tremendous variety of possible floating-point numbers, not every value within 32-bit, 64-bit, and 80-bit ranges can be expressed with a given number of bits allowed for the value's exponent and mantissa bit fields.



Charles,

Is this #qNAN thingy just a printable flag for a too-close-to-zero-hence-NAN exception or does it have a definite mathematical meaning in this context? Do you have a matching something for INF?

Charles Pegge

  • Guest
Re: NAN and INFINITY
« Reply #2 on: August 07, 2014, 01:09:09 PM »
John,

It is primarily something to include in source code but could also become a DLL. Passing and returning  C strings to make it more accessible.

Mike,

#qNAN is returned for indeterminate numbers from expressions like 0/0

#INF for positive infinity    1/0
#-INF for negative infinity -1/0  or 1/-0

It is legit to use infinty expressions in Oxygen calculations, but anything that produces #qNAN will always cause the calculation to result in #qNAN

Mike Lobanovsky

  • Guest
Re: NAN and INFINITY
« Reply #3 on: August 07, 2014, 01:33:20 PM »
Thanks Charles!

Are they initialized transparently by the engine or explicitly by the user e.g. as

Code: [Select]
#INF  =  1/0
#-INF = -1/0
#qNAN =  0/0

?

Can #INFinities and #qNAN's be used in (in)equality evaluations as literals?

And finally, why #qNAN?

Pooh! :)
« Last Edit: August 07, 2014, 01:50:23 PM by Mike Lobanovsky »

Charles Pegge

  • Guest
Re: NAN and INFINITY
« Reply #4 on: August 07, 2014, 02:06:34 PM »
These are strings generated internally by float_to_ascii

To use infinities in calculations and comparisons, it is easiest to create variables holding these values:

float zero=0.0, mzero=-0.0, inf=1/0, minf=-1/0, nan=0/0

NAN cannot be used directly in float comparisons, so its bit-coding must be checked instead:

if ?f=?nan ...


PS: qNAN means quiet NAN. It is not disruptive to FPU operations.
« Last Edit: August 07, 2014, 02:16:23 PM by Charles Pegge »

Mike Lobanovsky

  • Guest
Re: NAN and INFINITY
« Reply #5 on: August 07, 2014, 02:21:55 PM »
Thanks again, Charles!

You're in a bad need of a dedicated chroniqueur. Too much valuable info is getting lost and scattered all over the forum. :)

Charles Pegge

  • Guest
Re: NAN and INFINITY
« Reply #6 on: August 08, 2014, 12:25:42 AM »
Well, most of the examples go into OxygenBasic.zip, though we are getting to the stage where a database is needed to manage them :)

Float Case Ranges
Code: [Select]
float zero=0.0, mzero=-0.0, inf=1/0, minf=-1/0, nan=0/0

float f

'f=0.0  'zero
'f=-0.0 'minus zero
'f=1/0  'infinity
'f=-1/0 'minus infinity
'f=0/0  'not a number
'f=.19999999999999999 'range boundary test
 f=.20
'f=.2125
'
'THESE CASES USE DWORD (SYS) MATCHING INSTEAD OF FLOAT EVALUATION
select ?f
case ?zero  : print "zero"
case ?mzero : print "minus zero"
case ?inf   : print "infinity"
case ?minf  : print "minus infinity"
case ?nan   : print "nan (not a number)"
case else
  'CASES USING NORMAL FLOAT EVALUATION
  select f
  case 0.0 to < 0.1 : print "0.0 to < 0.1 :   " str f,2
  case 0.1 to < 0.2 : print "0.1 to < 0.2 :   " str f,2
  case 0.2 to < 0.3 : print "0.2 to < 0.3 :   " str f,2
  end select
end select