Class Float
In: numeric.c
Parent: Numeric

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

Methods

%   *   **   +   -   -@   /   <   <=   <=>   ==   >   >=   abs   ceil   coerce   divmod   eql?   finite?   floor   hash   induced_from   infinite?   modulo   nan?   round   to_f   to_i   to_int   to_s   truncate   zero?  

Included Modules

Precision

Constants

ROUNDS = INT2FIX(FLT_ROUNDS)
RADIX = INT2FIX(FLT_RADIX)
MANT_DIG = INT2FIX(DBL_MANT_DIG)
DIG = INT2FIX(DBL_DIG)
MIN_EXP = INT2FIX(DBL_MIN_EXP)
MAX_EXP = INT2FIX(DBL_MAX_EXP)
MIN_10_EXP = INT2FIX(DBL_MIN_10_EXP)
MAX_10_EXP = INT2FIX(DBL_MAX_10_EXP)
MIN = rb_float_new(DBL_MIN)
MAX = rb_float_new(DBL_MAX)
EPSILON = rb_float_new(DBL_EPSILON)

Public Class methods

Convert obj to a float.

Public Instance methods

Return the modulo after division of flt by other.

   6543.21.modulo(137)      #=> 104.21
   6543.21.modulo(137.24)   #=> 92.9299999999996

Returns a new float which is the product of float and other.

 flt ** other   => float

Raises float the other power.

Returns a new float which is the sum of float and other.

Returns a new float which is the difference of float and other.

Returns float, negated.

Returns a new float which is the result of dividing float by other.

true if flt is less than other.

true if flt is less than or equal to other.

Returns -1, 0, or +1 depending on whether flt is less than, equal to, or greater than numeric. This is the basis for the tests in Comparable.

Returns true only if obj has the same value as flt. Contrast this with Float#eql?, which requires obj to be a Float.

   1.0 == 1   #=> true

true if flt is greater than other.

true if flt is greater than or equal to other.

Returns the absolute value of flt.

   (-34.56).abs   #=> 34.56
   -34.56.abs     #=> 34.56

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

MISSING: documentation

Returns true only if obj is a Float with the same value as flt. Contrast this with Float#==, which performs type conversions.

   1.0.eql?(1)   #=> false

Returns true if flt is a valid IEEE floating point number (it is not infinite, and nan? is false).

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

Returns a hash code for this float.

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

Return the modulo after division of flt by other.

   6543.21.modulo(137)      #=> 104.21
   6543.21.modulo(137.24)   #=> 92.9299999999996

Returns true if flt is an invalid IEEE floating point number.

   a = -1.0      #=> -1.0
   a.nan?        #=> false
   a = 0.0/0.0   #=> NaN
   a.nan?        #=> true

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

As flt is already a float, returns self.

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’’.

Returns true if flt is 0.0.

To view or add comments on this documentation, please go to the API wiki.

[Validate]