I can get Infinity
and NaN
by
n = 9.0 / 0 #=> Infinity
n.class #=> Float
m = 0 / 0.0 #=> NaN
m.class #=> Float
but when I want to access Infinity
or NaN
directly:
Infinity #=> uninitialized constant Infinity (NameError)
NaN #=> uninitialized constant NaN (NameError)
What are Infinity
and NaN
? Are they objects, keywords, or something else?
Infinity and NaN :: Data Types (Programming) MATLAB uses the special values inf , -inf , and NaN to represent values that are positive and negative infinity, and not a number respectively. MATLAB represents infinity by the special value inf .
Contents. 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. An indeterminant number, which is a numeric value that is not well-defined, such as 0/0 .
In floating-point calculations, NaN is not the same as infinity, although both are typically handled as special cases in floating-point representations of real numbers as well as in floating-point operations.
NaN stands for Not A Number and is one of the common ways to represent the missing value in the data. It is a special floating-point value and cannot be converted to any other type than float. NaN value is one of the major problems in Data Analysis.
What you see printed as Infinity
and NaN
are just the string representations for two special instances of the Float
class, not keywords or literals. They are returned by floating point division by 0 or by referencing the constants Float::INFINITY
and Float::NAN
.
Float::INFINITY.class
# => Float
Float::INFINITY.to_s
# => "Infinity"
Float::NAN.class
# => Float
Float::NAN.to_s
# => "NaN"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With