Float

The floating-point number class. The implementation of Float is double in C.

Superclass

Methods

self + other
self - other
self * other
self / other
self % other
self ** other

Arithmetic operators that compute the sum, difference, product, quotient, remainder, and exponent, respectively.

self <=> other

Compares self with other and returns a positive integer if self is larger, 0 if the two are equal, and a negative integer if self is smaller.

self == other
self < other
self <= other
self > other
self >= other

Relational operators.

finite?

Returns TRUE if the value is neither infinite nor NaN.

infinite?

Returns 1 when a value is positive and infinite; returns -1 when a value is negative and infinite. Otherwise, returns nil. The floating-point zero ensures infinite division.

inf = 1.0/0
p inf
p inf.infinite?

=> Infinity
   1

inf = -1.0/0
p inf
p inf.infinite?

=> -Infinity
   -1
nan?

Returns true if a value is NaN (not a number). The floating-point zero ensures the result of division by 0 is NaN.

nan = 0.0/0.0
p nan
p nan.nan?

=> NaN
   true