class Float < Numeric

Float objects represent real numbers using the native architecture's double-precision floating point representation.

instance methods

Arithmetic operations
Performs various arithmetic operations on flt.
flt + aNumeric Addition
flt - aNumeric Subtraction
flt * aNumeric Multiplication
flt / aNumeric Division
flt % aNumeric Modulo
flt ** aNumeric Exponentiation
flt <=> aNumeric → -1, 0, +1
Returns -1, 0, or +1 depending on whether flt is less than, equal to, or greater than aNumeric. This is the basis for the tests in Comparable.
flt.ceil → anInteger
Returns the smallest Integer greater than or equal to flt.
1.2.ceil 2 2.0.ceil 2 (-1.2).ceil -1 (-2.0).ceil -2
flt.finite? → true or false
Returns true if flt is a valid IEEE floating point number (it is not infinite, and nan? is false).
flt.floor → anInteger
Returns the largest integer less than or equal to flt.
1.2.floor 1 2.0.floor 2 (-1.2).floor -2 (-2.0).floor -2
flt.infinite? → nil, -1, +1
Returns nil, -1, or +1 depending on whether flt is finite, -infinity, or +infinity.
(0.0).infinite? nil (-1.0/0.0).infinite? -1 (+1.0/0.0).infinite? 1
flt.nan? → true or false
Returns true if flt is an invalid IEEE floating point number.
a = -1.0 -1.0 a.nan? false a = Math.log(a) NaN a.nan? true
flt.round → anInteger
Rounds flt to the nearest integer. Equivalent to:
def round return floor(self+0.5) if self > 0.0 return ceil(self-0.5) if self < 0.0 return 0.0 end
1.5.round 2 (-1.5).round -2
flt.to_f → flt
Returns flt.
flt.to_i → anInteger
Returns flt truncated to an Integer.
flt.to_s → aString
Returns a string containing a representation of self. As well as a fixed or exponential form of the number, the call may return “NaN”, “Infinity”, and “-Infinity”.
Show this content in its own window