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

m |
|||

Line 5: | Line 5: | ||

'''Inf''' means infinity -- e.g., | '''Inf''' means infinity -- e.g., | ||

− | :1/0 → Inf | + | :<code>1/0 → Inf</code> |

+ | |||

or a number larger than 1.796E308 (the largest number that your computer can represent explicitly) -- e.g. | or a number larger than 1.796E308 (the largest number that your computer can represent explicitly) -- e.g. | ||

− | :1E307 * 100 → Inf | + | :<code>1E307 * 100 → Inf</code> |

+ | |||

'''-Inf''' means negative infinity (or a number less than 1.796E308) -- e.g. | '''-Inf''' means negative infinity (or a number less than 1.796E308) -- e.g. | ||

− | :-1/0 → -Inf | + | :<code>-1/0 → -Inf</code> |

'''NAN''' means "Not A Number" -- i.e. not a well-defined number nor infinity -- e.g. | '''NAN''' means "Not A Number" -- i.e. not a well-defined number nor infinity -- e.g. | ||

− | :0/0 → NAN | + | :<code>0/0 → NAN</code> |

− | :Sqrt(-1) → NAN | + | :<code>Sqrt(-1) → NAN</code> |

− | (If you enable [[Complex Numbers]], Sqrt(-1) returns the valid imaginary number, 1j.) | + | |

+ | (If you enable [[Complex Numbers]], <code>Sqrt(-1)</code> returns the valid imaginary number, ''1j''.) | ||

− | '''Null''' means that there is no such value. For example, [[Slice]] and [[Subscript]] return Null if you try to get the ''n''th slice over an Index with less than ''n'' values. For example: | + | '''Null''' means that there is no such value. For example, [[Slice]] and [[Subscript]] return [[Null]] if you try to get the ''n''th [[slice]] over an Index with less than ''n'' values. For example: |

− | :Index Year := [2015, 2016, 2017] | + | :<code>Index Year := [2015, 2016, 2017]</code> |

− | :Slice(Year, 4) → NULL | + | :<code>Slice(Year, 4) → NULL</code> |

− | :Variable X := Array(Year, [20, 23, 28]) | + | :<code>Variable X := Array(Year, [20, 23, 28])</code> |

− | :X[Year = 2018] → NULL | + | :<code>X[Year = 2018] → NULL</code> |

=== More on INF and NAN === | === More on INF and NAN === | ||

− | Calculations using INF and NAN follow ANSI (Association of National Standards Institutes) standards, which follow the laws of mathematics as far as possible: | + | Calculations using <code>INF</code> and <code>NAN</code> follow ANSI (Association of National Standards Institutes) standards, which follow the laws of mathematics as far as possible: |

− | :1/Inf → 0 | + | :<code>1/Inf → 0</code> |

− | :1/(-Inf) → 0 | + | :<code>1/(-Inf) → 0</code> |

− | :Inf + Inf → Inf | + | :<code>Inf + Inf → Inf</code> |

− | :Inf - Inf → NAN | + | :<code>Inf - Inf → NAN</code> |

− | 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: | + | 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>: |

− | :True OR NAN → True | + | :<code>True OR NAN → True</code> |

− | :NaN AND False → False | + | :<code>NaN AND False → False</code> |

− | :IF True THEN 5 ELSE NAN → 5 | + | :<code>IF True THEN 5 ELSE NAN → 5</code> |

=== More on NULL === | === More on NULL === | ||

− | When | + | When [[Null]] appears in scalar operations, it generally produces a warning and evaluates to [[Null]], for example: |

− | :10 + NULL → NULL | + | :<code>10 + NULL → NULL</code> |

− | :NULL - 10 → NULL | + | :<code>NULL - 10 → NULL</code> |

− | :1 AND NULL → NULL | + | :<code>1 AND NULL → NULL</code> |

− | Array-reducing functions ignore | + | Array-reducing functions ignore [[Null]]. These examples demonstrate (assume <code>A</code> is indexed by <code>I</code> as indicated). |

:{| class="wikitable" | :{| class="wikitable" | ||

! I: !! 1 !! 2 !! 3 !! 4 !! 5 | ! I: !! 1 !! 2 !! 3 !! 4 !! 5 | ||

Line 51: | Line 54: | ||

|} | |} | ||

− | : | + | :<code>Sum(A, I) → 12</code> |

− | : | + | :<code>Average(A, I) → 4</code> |

− | : | + | :<code>JoinText(A, I, ', ') → "8, 4, 0"</code> |

− | Graphs will simply ignore (not show) any point whose value is | + | Graphs will simply ignore (not show) any point whose value is [[Null]]. |

Array-reducing functions include [[Sum]], [[Min]], [[Max]], [[ArgMin]], [[ArgMax]], [[Product]], [[Average]], [[JoinText]], [[Irr]], [[Npv]]. | Array-reducing functions include [[Sum]], [[Min]], [[Max]], [[ArgMin]], [[ArgMax]], [[Product]], [[Average]], [[JoinText]], [[Irr]], [[Npv]]. | ||

− | Array functions [[Sum]], [[Min]] and [[Max]] also accept an optional parameter | + | Array functions [[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 Y=Null, which is useful for missing data. | + | [[Regression]] also ignores any data points which have <code>Y = Null</code>, which is useful for missing data. |

## Revision as of 23:07, 5 January 2016

These are special values that Analytica returns in particular conditions. You can also use them in expressions:

**Inf** means infinity -- e.g.,

`1/0 → Inf`

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

`1E307 * 100 → Inf`

**-Inf** means negative infinity (or a number less than 1.796E308) -- e.g.

`-1/0 → -Inf`

**NAN** means "Not A Number" -- i.e. 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, Slice and Subscript return Null if you try to get the *n*th slice over an Index with less than *n* values. For example:

`Index Year := [2015, 2016, 2017]`

`Slice(Year, 4) → NULL`

`Variable X := Array(Year, [20, 23, 28])`

`X[Year = 2018] → NULL`

### More on INF and NAN

Calculations using `INF`

and `NAN`

follow ANSI (Association of National Standards Institutes) standards, 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`

Array-reducing functions ignore Null. These examples demonstrate (assume `A`

is indexed by `I`

as indicated).

I: 1 2 3 4 5 A: 8 NULL 4 NULL 0

`Sum(A, I) → 12`

`Average(A, I) → 4`

`JoinText(A, I, ', ') → "8, 4, 0"`

Graphs will simply ignore (not show) any point whose value is Null.

Array-reducing functions include Sum, Min, Max, ArgMin, ArgMax, Product, Average, JoinText, Irr, Npv.
Array functions 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.

Enable comment auto-refresher