INF, NAN, and NULL - Exception values


INF ("infinity"), NAN ("not a number"), and Null are special-valued system constants that Analytica returns in particular conditions, such as exceptions. These constants can also be used as values in expressions.

Constant Meaning
INF Infinity or a real number larger than can be represented, e.g., 1/0
NAN An indeterminant number, which is a numeric value that is not well-defined, such as 0/0. The code name NAN suffers from an unfortunate historic misnaming in that it stands for "Not A Number"; however, it is considered to be a numeric data type, and hence IsNumber(NAN) is true.
Null The result of an operation where the desired data is not there, such as

X[I = '?'], where index I does not have the value '?'

INF (infinity)

INF is the result of a numerical calculation that is mathematically infinite, such as:

1/0 → INF

INF is also the result of a calculation that would produce a number larger than 1.797 x10+308, which is the largest floating point number that Analytica can represent:

10^1000 → INF

INF can be positive or negative:

-1 * 10^1000 → -INF
-1/0 → -Inf

So -INF means negative infinity (or a number below -1.796E308).

You can perform useful, mathematically correct arithmetic with INF, such as:

INF + 10 → INF
INF/0 → INF
10 - INF → -INF
100/0 = INF → True

NAN (Not a Number)

NaN is the result of an indeterminate numerical calculation, including numerical functions whose parameter is outside their domain, such as"

INF - INF → NAN
0/0 → NAN
INF/INF → NAN
Sqrt(-1) → NAN
ArcSin(2) → NAN

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

It usually gives a warning if you apply a function to a parameter value outside its range, such as the two examples above — unless you have checked “Ignore warnings”.

Any arithmetic operation, comparison, or function applied to NaN returns NaN:

0/0 <> NAN → NAN

Analytica’s representation and treatment of INF and NaN is consistent with ANSI (Association of National Standards Institutes) standards and IEEE Floating point standards. NaN stands for “Not A Number,” which is a bit misleading, since NaN really is a kind of number. You can detect NaN in an expression using the IsNaN() function.

Calculations performed with INF and NaN follow the laws of mathematics:

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

Null

Nullis a result that is ill-defined, usually indicating that there is nothing at the location requested, for example a subscript using a value that does not match a value of the index:

Index I := 1..5
X[I = 6] → Null

Other operations and functions that can return Null include Slice(), Subscript(), Subindex(), and MdTable(), e.g.

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

You can test for Null using the standard = or <> operators, such as:

X[I = 6] = Null → True

or you can use IsNull(X[I = 6]). However, x=Null and IsNull(x) are different when x may be an array. x=Null is a cell-level comparison, where each cell is tested for equality to Null, with the result having the same dimensionality as x, whereas IsNull(x) tests whether the entire value is exactly Null. When x is an array where every cell is equal to Null, IsNull(x) is false.

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).

variable A :=
I ▶
1 2 3 4 5
8 Null 4 Null 0

Then

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.

See Also


Comments


You are not allowed to post comments.