NaN

From REALbasicWiki

Jump to: navigation, search
Overall article skill Skill ranges from beginner (green) to expert (red)

NaN stands for "Not a Number" and consists in a special single or double value to indicate that the result is undefined.

NaNs are defined by the IEEE floating-point standard. See also NaN on Wikipedia.

[edit] Why some special values ?

If you remember your math lessons, there are some cases where a numeric expression gives:

  • Undefined result (such as zero divided by zero)
  • Infinite result, either positive or negative (e.g. one divided by zero)

Such values are not considered as an error because they are mathematically correct and so, they can be used in further computations.

[edit] NaNs in REALbasic

NaNs can be detected in REALbasic by using Str.

dim s as string = Str( Log( -1 ) ) //Log of a negative value is undefined
// result s = "-NAN(000)"

Though not really useful, you can also create a NaN:

dim myNaN as double
dim nullDouble as double

myNaN = Val( "NAN" ) //This actually creates a NaN
nullDouble = Val( "blah blah" ) //This does not make a NaN and nullDouble is just equal to zero

You should be careful that Val("Nanny") (or val("any string beginning with 'nan'")) will return NaN.

[edit] See also

Personal tools
related