Class: Float
Overview
Float objects represent inexact real numbers using the native architecture's double-precision floating point representation.
Floating point has a different arithmetic and is a inexact number. So you should know its esoteric system. see following:
Constant Summary
- 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 =
DBL2NUM(DBL_MIN)
- MAX =
DBL2NUM(DBL_MAX)
- EPSILON =
DBL2NUM(DBL_EPSILON)
- INFINITY =
DBL2NUM(INFINITY)
- NAN =
DBL2NUM(NAN)
Instance Method Summary (collapse)
-
- (Object) %
Return the modulo after division of flt by other.
-
- (Float) *(other)
Returns a new float which is the product of float and other.
-
- (Float) **(other)
Raises float the other power.
-
- (Float) +(other)
Returns a new float which is the sum of float and other.
-
- (Float) -(other)
Returns a new float which is the difference of float and other.
-
- (Float) -
Returns float, negated.
-
- (Float) /(other)
Returns a new float which is the result of dividing float by other.
-
- (Boolean) <(real)
true if flt is less than real.
-
- (Boolean) <=(real)
true if flt is less than or equal to real.
-
- (-1, ...) <=>(real)
Returns -1, 0, +1 or nil depending on whether flt is less than, equal to, or greater than real.
-
- (Boolean) ==(obj)
Returns true only if obj has the same value as flt.
-
- (Boolean) ==(obj)
Returns true only if obj has the same value as flt.
-
- (Boolean) >(real)
true if flt is greater than real.
-
- (Boolean) >=(real)
true if flt is greater than or equal to real.
-
- (Object) abs
Returns the absolute value of flt.
-
- (Object) angle
Returns 0 if the value is positive, pi otherwise.
-
- (Object) arg
Returns 0 if the value is positive, pi otherwise.
-
- (Integer) ceil
Returns the smallest Integer greater than or equal to flt.
-
- (Array) coerce(numeric)
Returns an array with both aNumeric and flt represented as Float objects.
-
- (Integer) denominator
Returns the denominator (always positive).
-
- (Array) divmod(numeric)
See Numeric#divmod.
-
- (Boolean) eql?(obj)
Returns true only if obj is a Float with the same value as flt.
-
- (Float) quo(numeric)
Returns float / numeric.
-
- (Boolean) finite?
Returns true if flt is a valid IEEE floating point number (it is not infinite, and nan? is false).
-
- (Integer) floor
Returns the largest integer less than or equal to flt.
-
- (Integer) hash
Returns a hash code for this float.
-
- (nil, ...) infinite?
Returns nil, -1, or +1 depending on whether flt is finite, -infinity, or +infinity.
-
- (Object) magnitude
Returns the absolute value of flt.
-
- (Object) modulo
Return the modulo after division of flt by other.
-
- (Boolean) nan?
Returns true if flt is an invalid IEEE floating point number.
-
- (Integer) numerator
Returns the numerator.
-
- (Object) phase
Returns 0 if the value is positive, pi otherwise.
-
- (Float) quo(numeric)
Returns float / numeric.
-
- (Object) rationalize([eps])
Returns a simpler approximation of the value (flt-|eps| <= result <= flt+|eps|).
-
- (Integer, Float) round([ndigits])
Rounds flt to a given precision in decimal digits (default 0 digits).
-
- (Float) to_f
As flt is already a float, returns self.
-
- (Object) to_i
Returns flt truncated to an Integer.
-
- (Object) to_int
Returns flt truncated to an Integer.
-
- (Object) to_r
Returns the value as a rational.
-
- (String) to_s
Returns a string containing a representation of self.
-
- (Object) truncate
Returns flt truncated to an Integer.
-
- (Boolean) zero?
Returns true if flt is 0.0.
Methods inherited from Numeric
#+@, #abs2, #conj, #conjugate, #div, #i, #imag, #imaginary, #initialize_copy, #integer?, #nonzero?, #polar, #real, #real?, #rect, #rectangular, #remainder, #singleton_method_added, #step, #to_c
Methods included from Comparable
Instance Method Details
- (Float) %(other) - (Float) modulo(other)
Return the modulo after division of flt by other.
6543.21.modulo(137) #=> 104.21
6543.21.modulo(137.24) #=> 92.9299999999996
|
|
# File 'numeric.c'
static VALUE
flo_mod(VALUE x, VALUE y)
{
double fy;
switch (TYPE(y)) {
case T_FIXNUM:
fy = (double)FIX2LONG(y);
break;
case T_BIGNUM:
fy = rb_big2dbl(y);
break;
case T_FLOAT:
fy = RFLOAT_VALUE(y);
break;
default:
return rb_num_coerce_bin(x, y, '%');
}
|
- (Float) *(other)
Returns a new float which is the product of float and other.
|
|
# File 'numeric.c'
static VALUE
flo_mul(VALUE x, VALUE y)
{
switch (TYPE(y)) {
case T_FIXNUM:
return DBL2NUM(RFLOAT_VALUE(x) * (double)FIX2LONG(y));
case T_BIGNUM:
return DBL2NUM(RFLOAT_VALUE(x) * rb_big2dbl(y));
case T_FLOAT:
return DBL2NUM(RFLOAT_VALUE(x) * RFLOAT_VALUE(y));
default:
return rb_num_coerce_bin(x, y, '*');
}
|
- (Float) **(other)
Raises float the other power.
2.0**3 #=> 8.0
|
|
# File 'numeric.c'
static VALUE
flo_pow(VALUE x, VALUE y)
{
switch (TYPE(y)) {
case T_FIXNUM:
return DBL2NUM(pow(RFLOAT_VALUE(x), (double)FIX2LONG(y)));
case T_BIGNUM:
return DBL2NUM(pow(RFLOAT_VALUE(x), rb_big2dbl(y)));
case T_FLOAT:
{
double dx = RFLOAT_VALUE(x);
double dy = RFLOAT_VALUE(y);
if (dx < 0 && dy != round(dy))
return rb_funcall(rb_complex_raw1(x), rb_intern("**"), 1, y);
return DBL2NUM(pow(dx, dy));
}
|
- (Float) +(other)
Returns a new float which is the sum of float and other.
|
|
# File 'numeric.c'
static VALUE
flo_plus(VALUE x, VALUE y)
{
switch (TYPE(y)) {
case T_FIXNUM:
return DBL2NUM(RFLOAT_VALUE(x) + (double)FIX2LONG(y));
case T_BIGNUM:
return DBL2NUM(RFLOAT_VALUE(x) + rb_big2dbl(y));
case T_FLOAT:
return DBL2NUM(RFLOAT_VALUE(x) + RFLOAT_VALUE(y));
default:
return rb_num_coerce_bin(x, y, '+');
}
|
- (Float) -(other)
Returns a new float which is the difference of float and other.
|
|
# File 'numeric.c'
static VALUE
flo_minus(VALUE x, VALUE y)
{
switch (TYPE(y)) {
case T_FIXNUM:
return DBL2NUM(RFLOAT_VALUE(x) - (double)FIX2LONG(y));
case T_BIGNUM:
return DBL2NUM(RFLOAT_VALUE(x) - rb_big2dbl(y));
case T_FLOAT:
return DBL2NUM(RFLOAT_VALUE(x) - RFLOAT_VALUE(y));
default:
return rb_num_coerce_bin(x, y, '-');
}
|
- (Float) -
Returns float, negated.
|
|
# File 'numeric.c'
static VALUE
flo_uminus(VALUE flt)
{
return DBL2NUM(-RFLOAT_VALUE(flt));
}
|
- (Float) /(other)
Returns a new float which is the result of dividing float by other.
|
|
# File 'numeric.c'
static VALUE
flo_div(VALUE x, VALUE y)
{
long f_y;
double d;
switch (TYPE(y)) {
case T_FIXNUM:
f_y = FIX2LONG(y);
return DBL2NUM(RFLOAT_VALUE(x) / (double)f_y);
case T_BIGNUM:
d = rb_big2dbl(y);
return DBL2NUM(RFLOAT_VALUE(x) / d);
case T_FLOAT:
return DBL2NUM(RFLOAT_VALUE(x) / RFLOAT_VALUE(y));
default:
return rb_num_coerce_bin(x, y, '/');
}
|
- (Boolean) <(real)
true if flt is less than real.
|
|
# File 'numeric.c'
static VALUE
flo_lt(VALUE x, VALUE y)
{
double a, b;
a = RFLOAT_VALUE(x);
switch (TYPE(y)) {
case T_FIXNUM:
b = (double)FIX2LONG(y);
break;
case T_BIGNUM:
b = rb_big2dbl(y);
break;
case T_FLOAT:
b = RFLOAT_VALUE(y);
#if defined(_MSC_VER) && _MSC_VER < 1300
if (isnan(b)) return Qfalse;
#endif
break;
default:
return rb_num_coerce_relop(x, y, '<');
}
|
- (Boolean) <=(real)
true if flt is less than or equal to real.
|
|
# File 'numeric.c'
static VALUE
flo_le(VALUE x, VALUE y)
{
double a, b;
a = RFLOAT_VALUE(x);
switch (TYPE(y)) {
case T_FIXNUM:
b = (double)FIX2LONG(y);
break;
case T_BIGNUM:
b = rb_big2dbl(y);
break;
case T_FLOAT:
b = RFLOAT_VALUE(y);
#if defined(_MSC_VER) && _MSC_VER < 1300
if (isnan(b)) return Qfalse;
#endif
break;
default:
return rb_num_coerce_relop(x, y, rb_intern("<="));
}
|
- (-1, ...) <=>(real)
Returns -1, 0, +1 or nil depending on whether flt is less than, equal to, or greater than real. This is the basis for the tests in Comparable.
|
|
# File 'numeric.c'
static VALUE
flo_cmp(VALUE x, VALUE y)
{
double a, b;
VALUE i;
a = RFLOAT_VALUE(x);
if (isnan(a)) return Qnil;
switch (TYPE(y)) {
case T_FIXNUM:
b = (double)FIX2LONG(y);
break;
case T_BIGNUM:
if (isinf(a)) {
if (a > 0.0) return INT2FIX(1);
else return INT2FIX(-1);
}
|
- (Boolean) ==(obj)
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
|
|
# File 'numeric.c'
static VALUE
flo_eq(VALUE x, VALUE y)
{
volatile double a, b;
switch (TYPE(y)) {
case T_FIXNUM:
b = (double)FIX2LONG(y);
break;
case T_BIGNUM:
b = rb_big2dbl(y);
break;
case T_FLOAT:
b = RFLOAT_VALUE(y);
#if defined(_MSC_VER) && _MSC_VER < 1300
if (isnan(b)) return Qfalse;
#endif
break;
default:
return num_equal(x, y);
}
|
- (Boolean) ==(obj)
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
|
|
# File 'numeric.c'
static VALUE
flo_eq(VALUE x, VALUE y)
{
volatile double a, b;
switch (TYPE(y)) {
case T_FIXNUM:
b = (double)FIX2LONG(y);
break;
case T_BIGNUM:
b = rb_big2dbl(y);
break;
case T_FLOAT:
b = RFLOAT_VALUE(y);
#if defined(_MSC_VER) && _MSC_VER < 1300
if (isnan(b)) return Qfalse;
#endif
break;
default:
return num_equal(x, y);
}
|
- (Boolean) >(real)
true if flt is greater than real.
|
|
# File 'numeric.c'
static VALUE
flo_gt(VALUE x, VALUE y)
{
double a, b;
a = RFLOAT_VALUE(x);
switch (TYPE(y)) {
case T_FIXNUM:
b = (double)FIX2LONG(y);
break;
case T_BIGNUM:
b = rb_big2dbl(y);
break;
case T_FLOAT:
b = RFLOAT_VALUE(y);
#if defined(_MSC_VER) && _MSC_VER < 1300
if (isnan(b)) return Qfalse;
#endif
break;
default:
return rb_num_coerce_relop(x, y, '>');
}
|
- (Boolean) >=(real)
true if flt is greater than or equal to real.
|
|
# File 'numeric.c'
static VALUE
flo_ge(VALUE x, VALUE y)
{
double a, b;
a = RFLOAT_VALUE(x);
switch (TYPE(y)) {
case T_FIXNUM:
b = (double)FIX2LONG(y);
break;
case T_BIGNUM:
b = rb_big2dbl(y);
break;
case T_FLOAT:
b = RFLOAT_VALUE(y);
#if defined(_MSC_VER) && _MSC_VER < 1300
if (isnan(b)) return Qfalse;
#endif
break;
default:
return rb_num_coerce_relop(x, y, rb_intern(">="));
}
|
- (Float) abs - (Float) magnitude
Returns the absolute value of flt.
(-34.56).abs #=> 34.56
-34.56.abs #=> 34.56
|
|
# File 'numeric.c'
static VALUE
flo_abs(VALUE flt)
{
double val = fabs(RFLOAT_VALUE(flt));
return DBL2NUM(val);
}
|
- (0, Float) arg - (0, Float) angle - (0, Float) phase
Returns 0 if the value is positive, pi otherwise.
|
|
# File 'complex.c'
static VALUE
float_arg(VALUE self)
{
if (isnan(RFLOAT_VALUE(self)))
return self;
if (f_tpositive_p(self))
return INT2FIX(0);
return rb_const_get(rb_mMath, id_PI);
}
|
- (0, Float) arg - (0, Float) angle - (0, Float) phase
Returns 0 if the value is positive, pi otherwise.
|
|
# File 'complex.c'
static VALUE
float_arg(VALUE self)
{
if (isnan(RFLOAT_VALUE(self)))
return self;
if (f_tpositive_p(self))
return INT2FIX(0);
return rb_const_get(rb_mMath, id_PI);
}
|
- (Integer) ceil
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
|
|
# File 'numeric.c'
static VALUE
flo_ceil(VALUE num)
{
double f = ceil(RFLOAT_VALUE(num));
long val;
if (!FIXABLE(f)) {
return rb_dbl2big(f);
}
|
- (Array) coerce(numeric)
Returns an array with both aNumeric and flt represented as Float objects. This is achieved by converting aNumeric to a Float.
1.2.coerce(3) #=> [3.0, 1.2]
2.5.coerce(1.1) #=> [1.1, 2.5]
|
|
# File 'numeric.c'
static VALUE
flo_coerce(VALUE x, VALUE y)
{
return rb_assoc_new(rb_Float(y), x);
}
|
- (Integer) denominator
Returns the denominator (always positive). The result is machine dependent.
See numerator.
|
|
# File 'rational.c'
static VALUE
float_denominator(VALUE self)
{
double d = RFLOAT_VALUE(self);
if (isinf(d) || isnan(d))
return INT2FIX(1);
return rb_call_super(0, 0);
}
|
- (Array) divmod(numeric)
See Numeric#divmod.
|
|
# File 'numeric.c'
static VALUE
flo_divmod(VALUE x, VALUE y)
{
double fy, div, mod;
volatile VALUE a, b;
switch (TYPE(y)) {
case T_FIXNUM:
fy = (double)FIX2LONG(y);
break;
case T_BIGNUM:
fy = rb_big2dbl(y);
break;
case T_FLOAT:
fy = RFLOAT_VALUE(y);
break;
default:
return rb_num_coerce_bin(x, y, rb_intern("divmod"));
}
|
- (Boolean) eql?(obj)
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
|
|
# File 'numeric.c'
static VALUE
flo_eql(VALUE x, VALUE y)
{
if (TYPE(y) == T_FLOAT) {
double a = RFLOAT_VALUE(x);
double b = RFLOAT_VALUE(y);
#if defined(_MSC_VER) && _MSC_VER < 1300
if (isnan(a) || isnan(b)) return Qfalse;
#endif
if (a == b)
return Qtrue;
}
|
- (Float) quo(numeric)
Returns float / numeric.
|
|
# File 'numeric.c'
static VALUE
flo_quo(VALUE x, VALUE y)
{
return rb_funcall(x, '/', 1, y);
}
|
- (Boolean) finite?
Returns true if flt is a valid IEEE floating point number (it is not infinite, and nan? is false).
|
|
# File 'numeric.c'
static VALUE
flo_is_finite_p(VALUE num)
{
double value = RFLOAT_VALUE(num);
#if HAVE_FINITE
if (!finite(value))
return Qfalse;
#else
if (isinf(value) || isnan(value))
return Qfalse;
#endif
return Qtrue;
}
|
- (Integer) floor
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
|
|
# File 'numeric.c'
static VALUE
flo_floor(VALUE num)
{
double f = floor(RFLOAT_VALUE(num));
long val;
if (!FIXABLE(f)) {
return rb_dbl2big(f);
}
|
- (Integer) hash
Returns a hash code for this float.
|
|
# File 'numeric.c'
static VALUE
flo_hash(VALUE num)
{
double d;
st_index_t hash;
d = RFLOAT_VALUE(num);
/* normalize -0.0 to 0.0 */
if (d == 0.0) d = 0.0;
hash = rb_memhash(&d, sizeof(d));
return LONG2FIX(hash);
}
|
- (nil, ...) infinite?
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
|
|
# File 'numeric.c'
static VALUE
flo_is_infinite_p(VALUE num)
{
double value = RFLOAT_VALUE(num);
if (isinf(value)) {
return INT2FIX( value < 0 ? -1 : 1 );
}
|
- (Float) abs - (Float) magnitude
Returns the absolute value of flt.
(-34.56).abs #=> 34.56
-34.56.abs #=> 34.56
|
|
# File 'numeric.c'
static VALUE
flo_abs(VALUE flt)
{
double val = fabs(RFLOAT_VALUE(flt));
return DBL2NUM(val);
}
|
- (Float) %(other) - (Float) modulo(other)
Return the modulo after division of flt by other.
6543.21.modulo(137) #=> 104.21
6543.21.modulo(137.24) #=> 92.9299999999996
|
|
# File 'numeric.c'
static VALUE
flo_mod(VALUE x, VALUE y)
{
double fy;
switch (TYPE(y)) {
case T_FIXNUM:
fy = (double)FIX2LONG(y);
break;
case T_BIGNUM:
fy = rb_big2dbl(y);
break;
case T_FLOAT:
fy = RFLOAT_VALUE(y);
break;
default:
return rb_num_coerce_bin(x, y, '%');
}
|
- (Boolean) nan?
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
|
|
# File 'numeric.c'
static VALUE
flo_is_nan_p(VALUE num)
{
double value = RFLOAT_VALUE(num);
return isnan(value) ? Qtrue : Qfalse;
}
|
- (Integer) numerator
Returns the numerator. The result is machine dependent.
For example:
n = 0.3.numerator #=> 5404319552844595
d = 0.3.denominator #=> 18014398509481984
n.fdiv(d) #=> 0.3
|
|
# File 'rational.c'
static VALUE
float_numerator(VALUE self)
{
double d = RFLOAT_VALUE(self);
if (isinf(d) || isnan(d))
return self;
return rb_call_super(0, 0);
}
|
- (0, Float) arg - (0, Float) angle - (0, Float) phase
Returns 0 if the value is positive, pi otherwise.
|
|
# File 'complex.c'
static VALUE
float_arg(VALUE self)
{
if (isnan(RFLOAT_VALUE(self)))
return self;
if (f_tpositive_p(self))
return INT2FIX(0);
return rb_const_get(rb_mMath, id_PI);
}
|
- (Float) quo(numeric)
Returns float / numeric.
|
|
# File 'numeric.c'
static VALUE
flo_quo(VALUE x, VALUE y)
{
return rb_funcall(x, '/', 1, y);
}
|
- (Object) rationalize([eps])
Returns a simpler approximation of the value (flt-|eps| <= result <= flt+|eps|). if eps is not given, it will be chosen automatically.
For example:
0.3.rationalize #=> (3/10)
1.333.rationalize #=> (1333/1000)
1.333.rationalize(0.01) #=> (4/3)
|
|
# File 'rational.c'
static VALUE
float_rationalize(int argc, VALUE *argv, VALUE self)
{
VALUE e, a, b, p, q;
if (f_negative_p(self))
return f_negate(float_rationalize(argc, argv, f_abs(self)));
rb_scan_args(argc, argv, "01", &e);
if (argc != 0) {
e = f_abs(e);
a = f_sub(self, e);
b = f_add(self, e);
}
|
- (Integer, Float) round([ndigits])
Rounds flt to a given precision in decimal digits (default 0 digits). Precision may be negative. Returns a floating point number when ndigits is more than zero.
1.4.round #=> 1
1.5.round #=> 2
1.6.round #=> 2
(-1.5).round #=> -2
1.234567.round(2) #=> 1.23
1.234567.round(3) #=> 1.235
1.234567.round(4) #=> 1.2346
1.234567.round(5) #=> 1.23457
34567.89.round(-5) #=> 0
34567.89.round(-4) #=> 30000
34567.89.round(-3) #=> 35000
34567.89.round(-2) #=> 34600
34567.89.round(-1) #=> 34570
34567.89.round(0) #=> 34568
34567.89.round(1) #=> 34567.9
34567.89.round(2) #=> 34567.89
34567.89.round(3) #=> 34567.89
|
|
# File 'numeric.c'
static VALUE
flo_round(int argc, VALUE *argv, VALUE num)
{
VALUE nd;
double number, f;
int ndigits = 0;
int binexp;
enum {float_dig = DBL_DIG+2}
|
- (Float) to_f
As flt is already a float, returns self.
|
|
# File 'numeric.c'
static VALUE
flo_to_f(VALUE num)
{
return num;
}
|
- (Integer) to_i - (Integer) to_int - (Integer) truncate
Returns flt truncated to an Integer.
|
|
# File 'numeric.c'
static VALUE
flo_truncate(VALUE num)
{
double f = RFLOAT_VALUE(num);
long val;
if (f > 0.0) f = floor(f);
if (f < 0.0) f = ceil(f);
if (!FIXABLE(f)) {
return rb_dbl2big(f);
}
|
- (Integer) to_i - (Integer) to_int - (Integer) truncate
Returns flt truncated to an Integer.
|
|
# File 'numeric.c'
static VALUE
flo_truncate(VALUE num)
{
double f = RFLOAT_VALUE(num);
long val;
if (f > 0.0) f = floor(f);
if (f < 0.0) f = ceil(f);
if (!FIXABLE(f)) {
return rb_dbl2big(f);
}
|
- (Object) to_r
Returns the value as a rational.
NOTE: 0.3.to_r isn't the same as '0.3'.to_r. The latter is equivalent to '3/10'.to_r, but the former isn't so.
For example:
2.0.to_r #=> (2/1)
2.5.to_r #=> (5/2)
-0.75.to_r #=> (-3/4)
0.0.to_r #=> (0/1)
|
|
# File 'rational.c'
static VALUE
float_to_r(VALUE self)
{
VALUE f, n;
float_decode_internal(self, &f, &n);
#if FLT_RADIX == 2
{
long ln = FIX2LONG(n);
if (ln == 0)
return f_to_r(f);
if (ln > 0)
return f_to_r(f_lshift(f, n));
ln = -ln;
return rb_rational_new2(f, f_lshift(ONE, INT2FIX(ln)));
}
|
- (String) to_s
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".
|
|
# File 'numeric.c'
static VALUE
flo_to_s(VALUE flt)
{
char *ruby_dtoa(double d_, int mode, int ndigits, int *decpt, int *sign, char **rve);
enum {decimal_mant = DBL_MANT_DIG-DBL_DIG}
|
- (Integer) to_i - (Integer) to_int - (Integer) truncate
Returns flt truncated to an Integer.
|
|
# File 'numeric.c'
static VALUE
flo_truncate(VALUE num)
{
double f = RFLOAT_VALUE(num);
long val;
if (f > 0.0) f = floor(f);
if (f < 0.0) f = ceil(f);
if (!FIXABLE(f)) {
return rb_dbl2big(f);
}
|
- (Boolean) zero?
Returns true if flt is 0.0.
|
|
# File 'numeric.c'
static VALUE
flo_zero_p(VALUE num)
{
if (RFLOAT_VALUE(num) == 0.0) {
return Qtrue;
}
|