INF and NAN
TimesTen supports the IEEE floating-point values Inf
(positive infinity), -Inf
(negative infinity), and NaN
(not a number).
Constant Values
You can use constant values in places where a floating-point constant is allowed. The following constants are supported:
-
BINARY_FLOAT_INFINITY
-
-BINARY_FLOAT_INFINITY
-
BINARY_DOUBLE_INFINITY
-
-BINARY_DOUBLE_INFINITY
-
BINARY_FLOAT_NAN
-
BINARY_DOUBLE_NAN
In the following example, a table is created with a column of type BINARY_FLOAT
and a column of type TT_INTEGER
. BINARY_FLOAT_INFINITY
and BINARY_FLOAT_NAN
are inserted into the column of type BINARY_FLOAT
.
Command> CREATE TABLE bfdemo (id BINARY_FLOAT, Ii2 TT_INTEGER); Command> INSERT INTO bfdemo VALUES (BINARY_FLOAT_INFINITY, 50); 1 row inserted. Command> INSERT INTO bfdemo VALUES (BINARY_FLOAT_NAN, 100); 1 row inserted. Command> SELECT * FROM bfdemo; < INF, 50 > < NAN, 100 > 2 rows found.
Primary Key Values
Inf
, -Inf
, and NaN
are acceptable values in columns defined with a primary key. This is different from NULL
, which is not allowed in columns defined with a primary key.
You can only insert Inf
, -Inf
, and NaN
values into BINARY_FLOAT
and BINARY_DOUBLE
columns.
Selecting Inf and NaN (Floating-Point Conditions)
Floating-point conditions determine whether an expression is infinite or is the undefined result of an operation (NaN
, meaning not a number).
Consider the following syntax:
Expression IS [NOT] {NAN|INFINITE}
Expression
must either resolve to a numeric data type or to a data type that can be implicitly converted to a numeric data type.
The following table describes the floating-point conditions.
Condition | Operation | Example |
---|---|---|
|
Returns |
SELECT * FROM bfdemo WHERE id IS NOT NAN; ID, ID2 < INF, 50 > 1 row found. |
|
Returns |
SELECT * FROM bfdemo WHERE id IS NOT INFINITE; ID, ID2 < NAN, 100 > 1 row found. |
Note:
The constant keywords represent specific BINARY_FLOAT
and BINARY_DOUBLE
values. The comparison keywords correspond to properties of a value and are not specific to any type, although they can only evaluate to TRUE
for BINARY_FLOAT
or BINARY_DOUBLE
types or types that can be converted to BINARY_FLOAT
or BINARY_DOUBLE
.
The following rules apply to comparisons with Inf
and NaN
:
-
Comparison between
Inf
(or-Inf
) and a finite value are as expected. For example, 5 >-Inf
. -
(Inf = Inf)
and(Inf > -Inf)
both evaluate toTRUE
. -
(NaN = NaN)
evaluates toTRUE
.
In reference to collating sequences:
-
-Inf
sorts lower than any other value. -
Inf
sorts lower thanNaN
andNULL
and higher than any other value. -
NaN
sorts higher thanInf
. -
NULL
sorts higher thanNaN
.NULL
is always the largest value in any collating sequence.
Expressions Involving Inf and NaN
-
Expressions containing floating-point values may generate
Inf
,-Inf
, orNaN
. This can occur either because the expression generated overflow or exceptional conditions or because one or more of the values in the expression wasInf
,-Inf
, orNaN
.Inf
andNaN
are generated in overflow or division-by-zero conditions. -
Inf
,-Inf
, andNaN
values are not ignored in aggregate functions.NULL
values are. If you want to excludeInf
andNaN
from aggregates, or from anySELECT
result, use both theIS NOT NAN
andIS NOT INFINITE
predicates.