Float objects represent real numbers using the native architecture‘s double-precision floating point representation.
Constants
Name | Description | |
---|---|---|
DIG | = INT2FIX(DBL_DIG) | |
EPSILON | = rb_float_new(DBL_EPSILON) | |
MANT_DIG | = INT2FIX(DBL_MANT_DIG) | |
MAX | = rb_float_new(DBL_MAX) | |
MAX_10_EXP | = INT2FIX(DBL_MAX_10_EXP) | |
MAX_EXP | = INT2FIX(DBL_MAX_EXP) | |
MIN | = rb_float_new(DBL_MIN) | |
MIN_10_EXP | = INT2FIX(DBL_MIN_10_EXP) | |
MIN_EXP | = INT2FIX(DBL_MIN_EXP) | |
RADIX | = INT2FIX(FLT_RADIX) | |
ROUNDS | = INT2FIX(FLT_ROUNDS) |
Methods
Class
Visibility | Signature |
---|---|
public | induced_from (p1) |
Instance
Visibility | Signature |
---|---|
public | % (p1) |
public | * (p1) |
public | ** (p1) |
public | + (p1) |
public | - (p1) |
public | -@ () |
public | / (p1) |
public | < (p1) |
public | <= (p1) |
public | <=> (p1) |
public | == (p1) |
public | > (p1) |
public | >= (p1) |
public | abs () |
public | ceil () |
public | coerce (p1) |
public | dclone () |
public | divmod (p1) |
public | eql? (p1) |
public | finite? () |
public | floor () |
public | hash () |
public | infinite? () |
public | modulo (p1) |
public | nan? () |
public | round () |
public | to_f () |
public | to_i () |
public | to_int () |
public | to_s () |
public | to_yaml ( opts = {} ) |
public | truncate () |
public | zero? () |
Class Method Detail
Float.induced_from(obj) => float
Convert obj to a float.
Instance Method Detail
flt % other => float
flt.modulo(other) => float
Return the modulo after division of flt by other.
6543.21.modulo(137) #=> 104.21 6543.21.modulo(137.24) #=> 92.9299999999996
float * other => float
Returns a new float which is the product of float and other.
flt ** other => float
Raises float the other power.
float + other => float
Returns a new float which is the sum of float and other.
float + other => float
Returns a new float which is the difference of float and other.
-float => float
Returns float, negated.
float / other => float
Returns a new float which is the result of dividing float by other.
flt < other => true or false
true if flt is less than other.
flt <= other => true or false
true if flt is less than or equal to other.
flt <=> numeric => -1, 0, +1
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.
flt == obj => true or false
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
flt > other => true or false
true if flt is greater than other.
flt >= other => true or false
true if flt is greater than or equal to other.
flt.abs => float
Returns the absolute value of flt.
(-34.56).abs #=> 34.56 -34.56.abs #=> 34.56
flt.ceil => integer
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
coerce(p1)
MISSING: documentation
dclone()
flt.divmod(numeric) => array
See Numeric#divmod.
flt.eql?(obj) => true or false
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
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 => integer
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.hash => integer
Returns a hash code for this float.
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 % other => float
flt.modulo(other) => float
Return the modulo after division of flt by other.
6543.21.modulo(137) #=> 104.21 6543.21.modulo(137.24) #=> 92.9299999999996
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 = 0.0/0.0 #=> NaN a.nan? #=> true
flt.round => integer
Rounds flt to the nearest integer. Equivalent to:
def round return (self+0.5).floor if self > 0.0 return (self-0.5).ceil if self < 0.0 return 0 end 1.5.round #=> 2 (-1.5).round #=> -2
flt.to_f => flt
As flt is already a float, returns self.
flt.to_i => integer
flt.to_int => integer
flt.truncate => integer
Returns flt truncated to an Integer.
flt.to_i => integer
flt.to_int => integer
flt.truncate => integer
Returns flt truncated to an Integer.
flt.to_s => string
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’’.
to_yaml( opts = {} )
flt.to_i => integer
flt.to_int => integer
flt.truncate => integer
Returns flt truncated to an Integer.
flt.zero? → true or false
Returns true if flt is 0.0.