Difference between revisions of "INF, NAN, and Null"

m
 
(24 intermediate revisions by 5 users not shown)
Line 1: Line 1:
 
[[category:Concepts]]
 
[[category:Concepts]]
 +
[[Category:Doc Status C]] <!-- For Lumina use, do not change -->
 +
 +
'''Inf''', '''NAN''', and '''Null'''  are special values, which can be very useful. Analytica returns them under conditions when it can't return a number. You can also type them directly into an expression or Edit table. 
  
These are special values that Analytica returns in special conditions:
+
'''Inf''' means infinity, and is the result of dividing a positive number by zero -- e.g.,
 +
:<code>1/0  &rarr; Inf</code>
  
:'''Inf''' means infinity or a real number larger than can be
+
or computing a number larger than 1.796E308 (the largest number that your computer can represent in 64 bits) -- e.g.  
represented -- e.g., 1/0 or 1.797E307 * 10  (because it can't represent numbers larger than 1.796E308)
+
:<code>1E307 * 100 &rarr; Inf</code>
:'''-Inf''' rmeans negative infinity or a number smaller than can be
 
represented, e.g., -1/0
 
:'''NAN''' means "Not A Number", where the result is numeric, but not a real number or infinity -- e.g., Sqrt(-1) or 0/0
 
:'''Null''' means that there is no such item. Slice, Subscript, Subindex, or MDTable return Null, for example, when trying to Slice out the nth slice over an Index with less than n values.
 
:'''Undefined''' means that a value has never been defined or is uncomputed -- for example, the value of an optional parameter not provided to a function.
 
  
=== Computations with special values ===
+
'''-Inf''' means negative infinity, the result of dividing a negative number by zero (or a number less than -1.796E308) -- e.g.
 +
:<code>-1/0  &rarr; -Inf</code>
  
Analytica follows ANSI (Association of National Standards Institutes) standards for computing with these special values, where applicable.
+
'''NAN''' means "Not A Number". It is the result of a calculation that is not a well-defined number nor infinity -- e.g.
 +
:<code>0/0 &rarr; NAN</code>
 +
:<code>Sqrt(-1) &rarr; NAN</code>
  
:1/Inf &rarr; 0
+
(If you enable [[Complex Numbers]], <code>Sqrt(-1)</code> returns the valid imaginary number, ''1j''.)
:1/(-Inf) &rarr; 0
 
:Inf + Inf &rarr; Inf
 
:Inf - Inf &rarr; NAN
 
  
When NULL appears in scalar operations, it generally produces a warning and evaluates to NULL, for example:
+
'''Null''' means that there is no such value. For example, [[Subscript]] returns <code>Null</code> if the indexing value doesn't match a value of the Index:
:10 + NULL &rarr; NULL
 
:NULL - 10 &rarr; NULL
 
:1 AND NULL &rarr; NULL
 
  
When NULL appears in an array operation, the result should be ignored; however, at present this treatment of NULL is NOT supported by Analytica, and is subject to change toward this standard in the future. When this semantics is fully incorporated, these examples will apply (assume A is indexed by I as indicated.
+
:<code>Index Year := [2015, 2016, 2017]</code>
:{|border="1"
+
:<code>Slice(Year, 4)  &rarr; NULL</code>
! I: !! 1 !! 2 !! 3 !! 4 !! 5
+
:<code>Variable X := Array(Year, [20, 23, 28])</code>
 +
:<code>X[Year = 2018] &rarr; NULL</code>
 +
You can also specify a different default result for an index value that doesn't match the index:
 +
 
 +
<code>X[Year = 2018, defValue: 0] &rarr; 0</code>
 +
 
 +
=== More on INF and NAN ===
 +
 
 +
Calculations using <code>INF</code> and <code>NAN</code> follow ANSI (Association of National Standards Institutes) recommendations, which follow the laws of mathematics as far as possible:
 +
:<code>1/Inf &rarr; 0</code>
 +
:<code>1/(-Inf) &rarr; 0</code>
 +
:<code>Inf + Inf &rarr; Inf</code>
 +
:<code>Inf - Inf &rarr; NAN</code>
 +
 
 +
Expressions taking <code>NAN</code> as an operand or parameter give <code>NAN</code> as their result unless the expression has a well-defined logical or numerical value for any value of <code>NAN</code>:
 +
 
 +
:<code>True OR NAN &rarr; True</code>
 +
:<code>NaN AND False &rarr; False</code>
 +
:<code>IF True THEN 5 ELSE NAN &rarr; 5</code>
 +
 
 +
=== More on NULL ===
 +
 
 +
When <code>Null</code> appears in scalar operations, it generally produces a warning and evaluates to <code>Null</code>, for example:
 +
:<code>10 + NULL &rarr; NULL</code>
 +
:<code>NULL - 10 &rarr; NULL</code>
 +
:<code>1 AND NULL &rarr; NULL</code>
 +
 
 +
[[Sum]], [[Min]], [[Max]], [[ArgMax]], [[JoinText]], [[Npv]], and other [[Array-reducing functions]] ignore <code>Null. For example:</code>
 +
 
 +
:<code>Variable A :=</code>
 +
:{| class="wikitable"
 +
! colspan="5" style="text-align: left;" ! | I &#9654;
 +
|-
 +
!|1
 +
!|2
 +
!|3
 +
!|4
 +
!|5
 
|-
 
|-
! A: || 8 || NULL || 4 || NULL || 0
+
|8
 +
|NULL
 +
|4
 +
|NULL
 +
|0
 
|}
 
|}
  
:Sum(A,I) &rarr; 12
+
:<code>Sum(A, I) &rarr; 12</code>
:Average(A,I) &rarr; 4  
+
:<code>Average(A, I) &rarr; 4</code>
:Join(A,I,',') &rarr; "8,4,0"
+
:<code>JoinText(A, I, ', ') &rarr; "8, 4, 0"</code>
 +
 
 +
Graphs also ignore (do not show) any point whose value is <code>Null</code>.
 +
 
 +
Some  [[Array-reducing functions]], notably [[Sum]], [[Min]] and [[Max]] also accept an optional parameter «IgnoreNaN» to ignore <code>NaN</code> values (which otherwise propagate, i.e. return <code>NaN</code>).
 +
 
 +
[[Regression]] also ignores any data points which have <code>Y = Null</code>, which is useful for missing data.
 +
 
 +
==See Also==
 +
* [[INF, NAN, and NULL - Exception values]]
 +
* [[Undefined]]
 +
* [[IsNaN]]
 +
* [[IsNull]]
 +
* [[Data_Type_Functions#Comparison_to_Null|Comparison to Null]]

Latest revision as of 19:25, 22 February 2019


Inf, NAN, and Null are special values, which can be very useful. Analytica returns them under conditions when it can't return a number. You can also type them directly into an expression or Edit table.

Inf means infinity, and is the result of dividing a positive number by zero -- e.g.,

1/0 → Inf

or computing a number larger than 1.796E308 (the largest number that your computer can represent in 64 bits) -- e.g.

1E307 * 100 → Inf

-Inf means negative infinity, the result of dividing a negative number by zero (or a number less than -1.796E308) -- e.g.

-1/0 → -Inf

NAN means "Not A Number". It is the result of a calculation that is not a well-defined number nor infinity -- e.g.

0/0 → NAN
Sqrt(-1) → NAN

(If you enable Complex Numbers, Sqrt(-1) returns the valid imaginary number, 1j.)

Null means that there is no such value. For example, Subscript returns Null if the indexing value doesn't match a value of the Index:

Index Year := [2015, 2016, 2017]
Slice(Year, 4) → NULL
Variable X := Array(Year, [20, 23, 28])
X[Year = 2018] → NULL

You can also specify a different default result for an index value that doesn't match the index:

X[Year = 2018, defValue: 0] → 0

More on INF and NAN

Calculations using INF and NAN follow ANSI (Association of National Standards Institutes) recommendations, which follow the laws of mathematics as far as possible:

1/Inf → 0
1/(-Inf) → 0
Inf + Inf → Inf
Inf - Inf → NAN

Expressions taking NAN as an operand or parameter give NAN as their result unless the expression has a well-defined logical or numerical value for any value of NAN:

True OR NAN → True
NaN AND False → False
IF True THEN 5 ELSE NAN → 5

More on NULL

When Null appears in scalar operations, it generally produces a warning and evaluates to Null, for example:

10 + NULL → NULL
NULL - 10 → NULL
1 AND NULL → NULL

Sum, Min, Max, ArgMax, JoinText, Npv, and other Array-reducing functions ignore Null. For example:

Variable A :=
I ▶
1 2 3 4 5
8 NULL 4 NULL 0
Sum(A, I) → 12
Average(A, I) → 4
JoinText(A, I, ', ') → "8, 4, 0"

Graphs also ignore (do not show) any point whose value is Null.

Some Array-reducing functions, notably Sum, Min and Max also accept an optional parameter «IgnoreNaN» to ignore NaN values (which otherwise propagate, i.e. return NaN).

Regression also ignores any data points which have Y = Null, which is useful for missing data.

See Also

Comments


You are not allowed to post comments.