Float

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

Arithmetic operator. Computes the sum, difference, product, quotient, remainder, and exponent.

self <=> other

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

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

Relational operator.

finite?

Returns TRUE even if the value is infinite, unless it is also 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 when 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

Last updated