Difference between revisions of "INF, Nan, Zero and IEEE/SANE arithmetic"

 
(5 intermediate revisions by 3 users not shown)
Line 1: Line 1:
The IEEE 754 standard for floating point arithmetic (related to a standard called SANE), specifies a standard for finite-precision floating point arithmetic.
+
[[Category: Analytica 4.0]]
  
''Analytica 4.0 complies with IEEE 754 (and SANE).  Note that Analytica 3.1 and earlier differed from this standard when multiplying by zero.  If you have a legacy 3.1 model that relies on multiplication by zero to zero out INFs or NaNs, you will discover that downstream results are NaN in in Analytica 4.0.''
+
[[What's new in Analytica 4.0?]] >
  
To detect this situation, keep the "Show Result Warnings" preference onA warning is displayed in Analytica 4.0 if you multiply INF or NaN by zero.
+
Analytica 4.0 complies with the ''IEEE 754 standard'' (and the related ''SANE standard'') for floating point arithmetic, including in its treatment of infinite valuesAs specified by IEEE 754, Analytica represents three special values:
 +
<pre style="background:white; border:white; margin-left: 1em;">
 +
INF: Infinity
 +
-INF: negative infinity
 +
NaN: Not a Number
 +
</pre>
  
Under IEEE 754 and in Analytica, there are three special values: INF, -INF, and NaN, representing infinity, negative infinity and "Not a Number". The IEEE 754 and SANE standards specify the desired results of arithmetic operations involving these values.  For example:
+
Analytica follows IEEE 754 and SANE standards in the following:
 +
<pre style="background:white; border:white; margin-left: 1em;">
 +
x * INF &rarr; INF for x>0
 +
x * -INF &rarr; INF for x<0
 +
INF - INF &rarr; NaN
 +
x / 0 &rarr; INF for x>0
 +
0 * INF &rarr; NaN
 +
0 / 0 &rarr; NaN
 +
x * NaN &rarr; NaN
 +
</pre>
  
x / 0 = INF for x>0
+
Note: x  > 0 means x is not NaN but may be INF.
0 / 0 = NaN
 
x * INF = INF for x>0
 
0 * INF = NaN
 
INF - INF = NaN
 
x * NaN = NaN
 
  
Note: x>0 means x is not NaN but may be INF.
+
In this, Analytica 4.0 differs from 3.1 and earlier releases which did not comply with the IEEE 754 standard when multiplying INF or Nan by zero. Analytica 3.1 and earlier gave:
 +
<pre style="background:white; border:white; margin-left: 1em;">
 +
0 * INF &rarr; 0
 +
0 * NaN &rarr; 0
 +
</pre>
  
In Analytica 3.1 and earlier, 0*x resulted in 0 for any x, even x=NaN or x=INF.
+
If you find that your model built with Analytica 3.1 or earlier is now generating NaN, where before it generated numbers, this change could be the reason.  Analytica 4.0 will give a warning if it detects such a multiplication of INF or NaN by zero, if you check '''Show Result Warnings''' in the '''Preferences''' dialog from the '''Edit''' menu.  on.  
  
To determine whether x is Nan, use the IsNaN(x) function.  To determine whether x is INF or -INF, use the comparison x=INF or x=-INF.  The IsNumber(x) function returns true for x=INF, x=-INF and x=NaN (but false for text strings, references, null, etc).
+
You can test whether x is Nan or INF in these ways:
 +
<pre style="background:white; border:white; margin-left: 1em;">
 +
x = INF
 +
x = -INF
 +
IsNan(x) &rarr;
 +
    True (1) if x = Nan
 +
IsNumber(x) &rarr;
 +
    True (1) if x is a number, INF, -INF, or Nan, and  
 +
    False (0) if x is a text, reference, Null, Undefined, or other type.
 +
</pre>
 +
Raising a negative number to a fractional power, using the ''x^y'' operator, can also result in NaN.  For example:
 +
:<code>(-1)^0.5 &rarr; NaN</code>
 +
 
 +
This example would be the imaginary number ''i'', but since Analytica does not support imaginary and complex numbers, NaN is returned.  Analytica 4.1 and earlier always returns NaN when x is negative and y is not an integer.  Analytica 4.2 and later will return real-valued results for some combinations of negative x and fractional exponent, see [[Exponentiation of negative numbers]].  Note: Analytica returns 0 for ''0^0'', non NaN (which is appropriate in some contexts and not in others).

Latest revision as of 18:00, 3 May 2016


What's new in Analytica 4.0? >

Analytica 4.0 complies with the IEEE 754 standard (and the related SANE standard) for floating point arithmetic, including in its treatment of infinite values. As specified by IEEE 754, Analytica represents three special values:

INF: Infinity
-INF: negative infinity
NaN: Not a Number

Analytica follows IEEE 754 and SANE standards in the following:

x * INF → INF for x>0
x * -INF → INF for x<0
INF - INF → NaN
x / 0 → INF  for x>0
0 * INF → NaN
0 / 0 → NaN
x * NaN → NaN

Note: x > 0 means x is not NaN but may be INF.

In this, Analytica 4.0 differs from 3.1 and earlier releases which did not comply with the IEEE 754 standard when multiplying INF or Nan by zero. Analytica 3.1 and earlier gave:

0 * INF → 0
0 * NaN → 0

If you find that your model built with Analytica 3.1 or earlier is now generating NaN, where before it generated numbers, this change could be the reason. Analytica 4.0 will give a warning if it detects such a multiplication of INF or NaN by zero, if you check Show Result Warnings in the Preferences dialog from the Edit menu. on.

You can test whether x is Nan or INF in these ways:

x = INF
x = -INF
IsNan(x) → 
    True (1) if x = Nan
IsNumber(x) → 
    True (1) if x is a number, INF, -INF, or Nan, and 
    False (0) if x is a text, reference, Null, Undefined, or other type.

Raising a negative number to a fractional power, using the x^y operator, can also result in NaN. For example:

(-1)^0.5 → NaN

This example would be the imaginary number i, but since Analytica does not support imaginary and complex numbers, NaN is returned. Analytica 4.1 and earlier always returns NaN when x is negative and y is not an integer. Analytica 4.2 and later will return real-valued results for some combinations of negative x and fractional exponent, see Exponentiation of negative numbers. Note: Analytica returns 0 for 0^0, non NaN (which is appropriate in some contexts and not in others).

Comments


You are not allowed to post comments.