INF, NAN, and NULL - Exception values

Revision as of 00:02, 7 December 2015 by Bbecane (talk | contribs)

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 Not a Number: Actually, the result is known to be “number” but not well

defined, e.g., 0/0

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

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 IsUndef(X[I = 6]).

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.