{: rooto:"YARD::CodeObjects::RootObject:@childrenIC:&YARD::CodeObjects::CodeObjectList[o:#YARD::CodeObjects::ClassObject;IC;[=o:&YARD::CodeObjects::ConstantObject:@files[[I"numeric.c:ETi:@current_file_has_commentsF:
@name:ROUNDS:@source_type:c:@visibility:public:
@tags[ :@docstrings{ :@docstringIC:YARD::Docstring"-1:: Indeterminable
0:: Rounding towards zero
1:: Rounding to the nearest number
2:: Rounding towards positive infinity
3:: Rounding towards negative infinity
;T;[ :@ref_tags[ : @allI"-1:: Indeterminable
0:: Rounding towards zero
1:: Rounding to the nearest number
2:: Rounding towards positive infinity
3:: Rounding towards negative infinity
;T:@unresolved_reference0:@object@
:@hash_flagF:@line_rangeo:
Range: exclT:
begini:endi:@namespace@:
@pathI"Float::ROUNDS;F:@valueI"Represents the rounding mode for floating point addition.
Usually defaults to 1, rounding to the nearest number.
Other modes include;To;
;[[@
i;
F;:
RADIX;;;;;[ ;{ ;IC;"The base of the floating point, or number of unique digits used to
represent the number.
Usually defaults to 2 on most systems, which would represent a base-10 decimal.
;T;[ ;[ ;I"The base of the floating point, or number of unique digits used to
represent the number.
Usually defaults to 2 on most systems, which would represent a base-10 decimal.
;T;0;@;F;o;;T; i;!i;"@;#I"Float::RADIX;F;$I"INT2FIX(FLT_RADIX);To;
;[[@
i;
F;:
MANT_DIG;;;;;[ ;{ ;IC;"SThe number of base digits for the +double+ data type.
Usually defaults to 53.
;T;[ ;[ ;I"TThe number of base digits for the +double+ data type.
Usually defaults to 53.
;T;0;@#;F;o;;T; i;!i;"@;#I"Float::MANT_DIG;F;$I"INT2FIX(DBL_MANT_DIG);To;
;[[@
i;
F;:DIG;;;;;[ ;{ ;IC;"`The number of decimal digits in a double-precision floating point.
Usually defaults to 15.
;T;[ ;[ ;I"aThe number of decimal digits in a double-precision floating point.
Usually defaults to 15.
;T;0;@/;F;o;;T; i;!i;"@;#I"Float::DIG;F;$I"INT2FIX(DBL_DIG);To;
;[[@
i;
F;:MIN_EXP;;;;;[ ;{ ;IC;"jThe smallest posable exponent value in a double-precision floating
point.
Usually defaults to -1021.
;T;[ ;[ ;I"kThe smallest posable exponent value in a double-precision floating
point.
Usually defaults to -1021.
;T;0;@;;F;o;;T; i;!i;"@;#I"Float::MIN_EXP;F;$I"INT2FIX(DBL_MIN_EXP);To;
;[[@
i;
F;:MAX_EXP;;;;;[ ;{ ;IC;"iThe largest possible exponent value in a double-precision floating
point.
Usually defaults to 1024.
;T;[ ;[ ;I"jThe largest possible exponent value in a double-precision floating
point.
Usually defaults to 1024.
;T;0;@G;F;o;;T; i;!i;"@;#I"Float::MAX_EXP;F;$I"INT2FIX(DBL_MAX_EXP);To;
;[[@
i;
F;:MIN_10_EXP;;;;;[ ;{ ;IC;"The smallest negative exponent in a double-precision floating point
where 10 raised to this power minus 1.
Usually defaults to -307.
;T;[ ;[ ;I"The smallest negative exponent in a double-precision floating point
where 10 raised to this power minus 1.
Usually defaults to -307.
;T;0;@S;F;o;;T; i;!i;"@;#I"Float::MIN_10_EXP;F;$I"INT2FIX(DBL_MIN_10_EXP);To;
;[[@
i;
F;:MAX_10_EXP;;;;;[ ;{ ;IC;"The largest positive exponent in a double-precision floating point where
10 raised to this power minus 1.
Usually defaults to 308.
;T;[ ;[ ;I"The largest positive exponent in a double-precision floating point where
10 raised to this power minus 1.
Usually defaults to 308.
;T;0;@_;F;o;;T; i;!i;"@;#I"Float::MAX_10_EXP;F;$I"INT2FIX(DBL_MAX_10_EXP);To;
;[[@
i;
F;:MIN;;;;;[ ;{ ;IC;"vThe smallest positive integer in a double-precision floating point.
Usually defaults to 2.2250738585072014e-308.
;T;[ ;[ ;I"wThe smallest positive integer in a double-precision floating point.
Usually defaults to 2.2250738585072014e-308.
;T;0;@k;F;o;;T; i;!i;"@;#I"Float::MIN;F;$I"DBL2NUM(DBL_MIN);To;
;[[@
i;
F;:MAX;;;;;[ ;{ ;IC;"|The largest possible integer in a double-precision floating point number.
Usually defaults to 1.7976931348623157e+308.
;T;[ ;[ ;I"}The largest possible integer in a double-precision floating point number.
Usually defaults to 1.7976931348623157e+308.
;T;0;@w;F;o;;T; i;!i;"@;#I"Float::MAX;F;$I"DBL2NUM(DBL_MAX);To;
;[[@
i;
F;:EPSILON;;;;;[ ;{ ;IC;"~The difference between 1 and the smallest double-precision floating
point number.
Usually defaults to 2.2204460492503131e-16.
;T;[ ;[ ;I"The difference between 1 and the smallest double-precision floating
point number.
Usually defaults to 2.2204460492503131e-16.
;T;0;@~;F;o;;T; i;!i;"@;#I"Float::EPSILON;F;$I"DBL2NUM(DBL_EPSILON);To;
;[[@
i;
F;:
INFINITY;;;;;[ ;{ ;IC;"2An expression representing positive infinity.
;T;[ ;[ ;I"3An expression representing positive infinity.
;T;0;@;F;o;;T; i;!i;"@;#I"Float::INFINITY;F;$I"DBL2NUM(INFINITY);To;
;[[@
i;
F;:NAN;;;;;[ ;{ ;IC;"@An expression representing a value which is "not a number".
;T;[ ;[ ;I"AAn expression representing a value which is "not a number".
;T;0;@;F;o;;T; i;!i;"@;#I"Float::NAN;F;$I"DBL2NUM(NAN);To:$YARD::CodeObjects::MethodObject:@module_functionF:@scope:
instance;;;#I"Float#to_s;F:@parameters[ ;[[@
i;
T;: to_s;0;[ ;{ ;IC;"Returns a string containing a representation of self. As well as a fixed or
exponential form of the +float+, the call may return +NaN+, +Infinity+, and
+-Infinity+.
;T;[o:YARD::Tags::OverloadTag
:@tag_nameI"
overload;F:
@text0;;6:@types0:@signatureI" to_s;T;IC;" ;T;[o:YARD::Tags::Tag
;8I"return;F;9I" ;T;0;:[I"String;T;@;[ ;I"@return [String];T;0;@;F:@ref_tag_recurse_counti :
@summary0;5[ ;@;[ ;I"Returns a string containing a representation of self. As well as a fixed or
exponential form of the +float+, the call may return +NaN+, +Infinity+, and
+-Infinity+.
@overload to_s
@return [String];T;0;o;1;2F;3;4;;;#I"Float#inspect;F;5[ ;[[@
i;
F;:inspect;: ruby;[ ;{ ;@;"@;;I"static VALUE;T:@sourceI"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};
enum {float_dig = DBL_DIG+1};
char buf[float_dig + (decimal_mant + CHAR_BIT - 1) / CHAR_BIT + 10];
double value = RFLOAT_VALUE(flt);
VALUE s;
char *p, *e;
int sign, decpt, digs;
if (isinf(value))
return rb_usascii_str_new2(value < 0 ? "-Infinity" : "Infinity");
else if (isnan(value))
return rb_usascii_str_new2("NaN");
p = ruby_dtoa(value, 0, 0, &decpt, &sign, &e);
s = sign ? rb_usascii_str_new_cstr("-") : rb_usascii_str_new(0, 0);
if ((digs = (int)(e - p)) >= (int)sizeof(buf)) digs = (int)sizeof(buf) - 1;
memcpy(buf, p, digs);
xfree(p);
if (decpt > 0) {
if (decpt < digs) {
memmove(buf + decpt + 1, buf + decpt, digs - decpt);
buf[decpt] = '.';
rb_str_cat(s, buf, digs + 1);
}
else if (decpt <= DBL_DIG) {
long len;
char *ptr;
rb_str_cat(s, buf, digs);
rb_str_resize(s, (len = RSTRING_LEN(s)) + decpt - digs + 2);
ptr = RSTRING_PTR(s) + len;
if (decpt > digs) {
memset(ptr, '0', decpt - digs);
ptr += decpt - digs;
}
memcpy(ptr, ".0", 2);
}
else {
goto exp;
}
}
else if (decpt > -4) {
long len;
char *ptr;
rb_str_cat(s, "0.", 2);
rb_str_resize(s, (len = RSTRING_LEN(s)) - decpt + digs);
ptr = RSTRING_PTR(s);
memset(ptr += len, '0', -decpt);
memcpy(ptr -= decpt, buf, digs);
}
else {
exp:
if (digs > 1) {
memmove(buf + 2, buf + 1, digs - 1);
}
else {
buf[2] = '0';
digs++;
}
buf[1] = '.';
rb_str_cat(s, buf, digs + 1);
rb_str_catf(s, "e%+03d", decpt - 1);
}
return s;
};T;F;o;;T; i;!i;"@;;@;AI"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};
enum {float_dig = DBL_DIG+1};
char buf[float_dig + (decimal_mant + CHAR_BIT - 1) / CHAR_BIT + 10];
double value = RFLOAT_VALUE(flt);
VALUE s;
char *p, *e;
int sign, decpt, digs;
if (isinf(value))
return rb_usascii_str_new2(value < 0 ? "-Infinity" : "Infinity");
else if (isnan(value))
return rb_usascii_str_new2("NaN");
p = ruby_dtoa(value, 0, 0, &decpt, &sign, &e);
s = sign ? rb_usascii_str_new_cstr("-") : rb_usascii_str_new(0, 0);
if ((digs = (int)(e - p)) >= (int)sizeof(buf)) digs = (int)sizeof(buf) - 1;
memcpy(buf, p, digs);
xfree(p);
if (decpt > 0) {
if (decpt < digs) {
memmove(buf + decpt + 1, buf + decpt, digs - decpt);
buf[decpt] = '.';
rb_str_cat(s, buf, digs + 1);
}
else if (decpt <= DBL_DIG) {
long len;
char *ptr;
rb_str_cat(s, buf, digs);
rb_str_resize(s, (len = RSTRING_LEN(s)) + decpt - digs + 2);
ptr = RSTRING_PTR(s) + len;
if (decpt > digs) {
memset(ptr, '0', decpt - digs);
ptr += decpt - digs;
}
memcpy(ptr, ".0", 2);
}
else {
goto exp;
}
}
else if (decpt > -4) {
long len;
char *ptr;
rb_str_cat(s, "0.", 2);
rb_str_resize(s, (len = RSTRING_LEN(s)) - decpt + digs);
ptr = RSTRING_PTR(s);
memset(ptr += len, '0', -decpt);
memcpy(ptr -= decpt, buf, digs);
}
else {
exp:
if (digs > 1) {
memmove(buf + 2, buf + 1, digs - 1);
}
else {
buf[2] = '0';
digs++;
}
buf[1] = '.';
rb_str_cat(s, buf, digs + 1);
rb_str_catf(s, "e%+03d", decpt - 1);
}
return s;
};T:@explicitT@o;1;2F;3;4;;;#I"Float#coerce;F;5[[I"y;T0;[[@
i;
T;:coerce;0;[ ;{ ;IC;"Returns an array with both a +numeric+ and a +float+ represented as Float
objects.
This is achieved by converting a +numeric+ to a Float.
1.2.coerce(3) #=> [3.0, 1.2]
2.5.coerce(1.1) #=> [1.1, 2.5]
;T;[o;7
;8I"
overload;F;90;;C;:0;;I"coerce(numeric);T;IC;" ;T;[o;<
;8I"return;F;9I" ;T;0;:[I"
Array;T;@;[ ;I"@return [Array];T;0;@;F;=i ;>0;5[[I"numeric;T0;@;[ ;I"Returns an array with both a +numeric+ and a +float+ represented as Float
objects.
This is achieved by converting a +numeric+ to a Float.
1.2.coerce(3) #=> [3.0, 1.2]
2.5.coerce(1.1) #=> [1.1, 2.5]
@overload coerce(numeric)
@return [Array];T;0;@;F;o;;T; i;!i;"@;;I"static VALUE;T;AI"[static VALUE
flo_coerce(VALUE x, VALUE y)
{
return rb_assoc_new(rb_Float(y), x);
};T;BTo;1;2F;3;4;;;#I"
Float#-@;F;5[ ;[[@
i;
T;:-@;0;[ ;{ ;IC;"Returns float, negated.
;T;[o;7
;8I"
overload;F;90;:-;:0;;I"-float;T;IC;" ;T;[o;<
;8I"return;F;9I" ;T;0;:[I"
Float;T;@;[ ;I"@return [Float];T;0;@;F;=i ;>0;5[ ;@;[ ;I"AReturns float, negated.
@overload -float
@return [Float];T;0;@;F;o;;T; i;!i;"@;;I"static VALUE;T;AI"Sstatic VALUE
flo_uminus(VALUE flt)
{
return DBL2NUM(-RFLOAT_VALUE(flt));
};T;BTo;1;2F;3;4;;;#I"Float#+;F;5[[I"y;T0;[[@
i ;
T;:+;0;[ ;{ ;IC;"AReturns a new float which is the sum of +float+ and +other+.
;T;[o;7
;8I"
overload;F;90;;F;:0;;I"
+(other);T;IC;" ;T;[o;<
;8I"return;F;9I" ;T;0;:[I"
Float;T;@;[ ;I"@return [Float];T;0;@;F;=i ;>0;5[[I"
other;T0;@;[ ;I"hReturns a new float which is the sum of +float+ and +other+.
@overload +(other)
@return [Float];T;0;@;F;o;;T; i;!i;"@;;I"static VALUE;T;AI"static VALUE
flo_plus(VALUE x, VALUE y)
{
if (RB_TYPE_P(y, T_FIXNUM)) {
return DBL2NUM(RFLOAT_VALUE(x) + (double)FIX2LONG(y));
}
else if (RB_TYPE_P(y, T_BIGNUM)) {
return DBL2NUM(RFLOAT_VALUE(x) + rb_big2dbl(y));
}
else if (RB_TYPE_P(y, T_FLOAT)) {
return DBL2NUM(RFLOAT_VALUE(x) + RFLOAT_VALUE(y));
}
else {
return rb_num_coerce_bin(x, y, '+');
}
};T;BTo;1;2F;3;4;;;#I"Float#-;F;5[[I"y;T0;[[@
i;
T;;E;0;[ ;{ ;IC;"HReturns a new float which is the difference of +float+ and +other+.
;T;[o;7
;8I"
overload;F;90;;E;:0;;I"
-(other);T;IC;" ;T;[o;<
;8I"return;F;9I" ;T;0;:[I"
Float;T;@;[ ;I"@return [Float];T;0;@;F;=i ;>0;5[[I"
other;T0;@;[ ;I"oReturns a new float which is the difference of +float+ and +other+.
@overload -(other)
@return [Float];T;0;@;F;o;;T; i;!i;"@;;I"static VALUE;T;AI"static VALUE
flo_minus(VALUE x, VALUE y)
{
if (RB_TYPE_P(y, T_FIXNUM)) {
return DBL2NUM(RFLOAT_VALUE(x) - (double)FIX2LONG(y));
}
else if (RB_TYPE_P(y, T_BIGNUM)) {
return DBL2NUM(RFLOAT_VALUE(x) - rb_big2dbl(y));
}
else if (RB_TYPE_P(y, T_FLOAT)) {
return DBL2NUM(RFLOAT_VALUE(x) - RFLOAT_VALUE(y));
}
else {
return rb_num_coerce_bin(x, y, '-');
}
};T;BTo;1;2F;3;4;;;#I"Float#*;F;5[[I"y;T0;[[@
i0;
T;:*;0;[ ;{ ;IC;"EReturns a new float which is the product of +float+ and +other+.
;T;[o;7
;8I"
overload;F;90;;G;:0;;I"
*(other);T;IC;" ;T;[o;<
;8I"return;F;9I" ;T;0;:[I"
Float;T;@=;[ ;I"@return [Float];T;0;@=;F;=i ;>0;5[[I"
other;T0;@=;[ ;I"lReturns a new float which is the product of +float+ and +other+.
@overload *(other)
@return [Float];T;0;@=;F;o;;T; i);!i-;"@;;I"static VALUE;T;AI"static VALUE
flo_mul(VALUE x, VALUE y)
{
if (RB_TYPE_P(y, T_FIXNUM)) {
return DBL2NUM(RFLOAT_VALUE(x) * (double)FIX2LONG(y));
}
else if (RB_TYPE_P(y, T_BIGNUM)) {
return DBL2NUM(RFLOAT_VALUE(x) * rb_big2dbl(y));
}
else if (RB_TYPE_P(y, T_FLOAT)) {
return DBL2NUM(RFLOAT_VALUE(x) * RFLOAT_VALUE(y));
}
else {
return rb_num_coerce_bin(x, y, '*');
}
};T;BTo;1;2F;3;4;;;#I"Float#/;F;5[[I"y;T0;[[@
iH;
T;:/;0;[ ;{ ;IC;"LReturns a new float which is the result of dividing +float+ by +other+.
;T;[o;7
;8I"
overload;F;90;;H;:0;;I"
/(other);T;IC;" ;T;[o;<
;8I"return;F;9I" ;T;0;:[I"
Float;T;@\;[ ;I"@return [Float];T;0;@\;F;=i ;>0;5[[I"
other;T0;@\;[ ;I"sReturns a new float which is the result of dividing +float+ by +other+.
@overload /(other)
@return [Float];T;0;@\;F;o;;T; iA;!iE;"@;;I"static VALUE;T;AI"static VALUE
flo_div(VALUE x, VALUE y)
{
long f_y;
double d;
if (RB_TYPE_P(y, T_FIXNUM)) {
f_y = FIX2LONG(y);
return DBL2NUM(RFLOAT_VALUE(x) / (double)f_y);
}
else if (RB_TYPE_P(y, T_BIGNUM)) {
d = rb_big2dbl(y);
return DBL2NUM(RFLOAT_VALUE(x) / d);
}
else if (RB_TYPE_P(y, T_FLOAT)) {
return DBL2NUM(RFLOAT_VALUE(x) / RFLOAT_VALUE(y));
}
else {
return rb_num_coerce_bin(x, y, '/');
}
};T;BTo;1;2F;3;4;;;#I"Float#quo;F;5[[I"y;T0;[[@
if;
T;:quo;0;[ ;{ ;IC;";Returns float / numeric
, same as Float#/.
;T;[o;7
;8I"
overload;F;90;: fdiv;:0;;I"fdiv(numeric);T;IC;" ;T;[o;<
;8I"return;F;9I" ;T;0;:[I"
Float;T;@{;[ ;I"@return [Float];T;0;@{;F;=i ;>0;5[[I"numeric;T0;@{o;7
;8I"
overload;F;90;;I;:0;;I"quo(numeric);T;IC;" ;T;[o;<
;8I"return;F;9I" ;T;0;:[I"
Float;T;@{;[ ;I"@return [Float];T;0;@{;F;=i ;>0;5[[I"numeric;T0;@{;[ ;I"Returns float / numeric
, same as Float#/.
@overload fdiv(numeric)
@return [Float]
@overload quo(numeric)
@return [Float];T;0;@{;F;o;;T; i^;!id;"@;;I"static VALUE;T;AI"Tstatic VALUE
flo_quo(VALUE x, VALUE y)
{
return rb_funcall(x, '/', 1, y);
};T;BTo;1;2F;3;4;;;#I"Float#fdiv;F;5[[I"y;T0;[[@
if;
T;;J;0;[ ;{ ;IC;";Returns float / numeric
, same as Float#/.
;T;[o;7
;8I"
overload;F;90;;J;:0;;I"fdiv(numeric);T;IC;" ;T;[o;<
;8I"return;F;9I" ;T;0;:[I"
Float;T;@;[ ;I"@return [Float];T;0;@;F;=i ;>0;5[[I"numeric;T0;@o;7
;8I"
overload;F;90;;I;:0;;I"quo(numeric);T;IC;" ;T;[o;<
;8I"return;F;9I" ;T;0;:[I"
Float;T;@;[ ;I"@return [Float];T;0;@;F;=i ;>0;5[[I"numeric;T0;@;[ ;@;0;@;F;o;;T; i^;!id;"@;;I"static VALUE;T;AI"Tstatic VALUE
flo_quo(VALUE x, VALUE y)
{
return rb_funcall(x, '/', 1, y);
};T;BTo;1;2F;3;4;;;#I"Float#%;F;5[[I"y;T0;[[@
i;
T;:%;0;[ ;{ ;IC;"Return the modulo after division of +float+ by +other+.
6543.21.modulo(137) #=> 104.21
6543.21.modulo(137.24) #=> 92.9299999999996
;T;[o;7
;8I"
overload;F;90;;K;:0;;I"
%(other);T;IC;" ;T;[o;<
;8I"return;F;9I" ;T;0;:[I"
Float;T;@;[ ;I"@return [Float];T;0;@;F;=i ;>0;5[[I"
other;T0;@o;7
;8I"
overload;F;90;:modulo;:0;;I"modulo(other);T;IC;" ;T;[o;<
;8I"return;F;9I" ;T;0;:[I"
Float;T;@;[ ;I"@return [Float];T;0;@;F;=i ;>0;5[[I"
other;T0;@;[ ;I"Return the modulo after division of +float+ by +other+.
6543.21.modulo(137) #=> 104.21
6543.21.modulo(137.24) #=> 92.9299999999996
@overload %(other)
@return [Float]
@overload modulo(other)
@return [Float];T;0;@;F;o;;T; i;!i;"@;;I"static VALUE;T;AI"rstatic VALUE
flo_mod(VALUE x, VALUE y)
{
double fy;
if (RB_TYPE_P(y, T_FIXNUM)) {
fy = (double)FIX2LONG(y);
}
else if (RB_TYPE_P(y, T_BIGNUM)) {
fy = rb_big2dbl(y);
}
else if (RB_TYPE_P(y, T_FLOAT)) {
fy = RFLOAT_VALUE(y);
}
else {
return rb_num_coerce_bin(x, y, '%');
}
return DBL2NUM(ruby_float_mod(RFLOAT_VALUE(x), fy));
};T;BTo;1;2F;3;4;;;#I"Float#modulo;F;5[[I"y;T0;[[@
i;
T;;L;0;[ ;{ ;IC;"Return the modulo after division of +float+ by +other+.
6543.21.modulo(137) #=> 104.21
6543.21.modulo(137.24) #=> 92.9299999999996
;T;[o;7
;8I"
overload;F;90;;K;:0;;I"
%(other);T;IC;" ;T;[o;<
;8I"return;F;9I" ;T;0;:[I"
Float;T;@;[ ;I"@return [Float];T;0;@;F;=i ;>0;5[[I"
other;T0;@o;7
;8I"
overload;F;90;;L;:0;;I"modulo(other);T;IC;" ;T;[o;<
;8I"return;F;9I" ;T;0;:[I"
Float;T;@;[ ;I"@return [Float];T;0;@;F;=i ;>0;5[[I"
other;T0;@;[ ;@ ;0;@;F;o;;T; i;!i;"@;;I"static VALUE;T;AI"rstatic VALUE
flo_mod(VALUE x, VALUE y)
{
double fy;
if (RB_TYPE_P(y, T_FIXNUM)) {
fy = (double)FIX2LONG(y);
}
else if (RB_TYPE_P(y, T_BIGNUM)) {
fy = rb_big2dbl(y);
}
else if (RB_TYPE_P(y, T_FLOAT)) {
fy = RFLOAT_VALUE(y);
}
else {
return rb_num_coerce_bin(x, y, '%');
}
return DBL2NUM(ruby_float_mod(RFLOAT_VALUE(x), fy));
};T;BTo;1;2F;3;4;;;#I"Float#divmod;F;5[[I"y;T0;[[@
i;
T;:divmod;0;[ ;{ ;IC;"WSee Numeric#divmod.
42.0.divmod 6 #=> [7, 0.0]
42.0.divmod 5 #=> [8, 2.0]
;T;[o;7
;8I"
overload;F;90;;M;:0;;I"divmod(numeric);T;IC;" ;T;[o;<
;8I"return;F;9I" ;T;0;:[I"
Array;T;@1;[ ;I"@return [Array];T;0;@1;F;=i ;>0;5[[I"numeric;T0;@1;[ ;I"See Numeric#divmod.
42.0.divmod 6 #=> [7, 0.0]
42.0.divmod 5 #=> [8, 2.0]
@overload divmod(numeric)
@return [Array];T;0;@1;F;o;;T; i;!i;"@;;I"static VALUE;T;AI"static VALUE
flo_divmod(VALUE x, VALUE y)
{
double fy, div, mod;
volatile VALUE a, b;
if (RB_TYPE_P(y, T_FIXNUM)) {
fy = (double)FIX2LONG(y);
}
else if (RB_TYPE_P(y, T_BIGNUM)) {
fy = rb_big2dbl(y);
}
else if (RB_TYPE_P(y, T_FLOAT)) {
fy = RFLOAT_VALUE(y);
}
else {
return rb_num_coerce_bin(x, y, rb_intern("divmod"));
}
flodivmod(RFLOAT_VALUE(x), fy, &div, &mod);
a = dbl2ival(div);
b = DBL2NUM(mod);
return rb_assoc_new(a, b);
};T;BTo;1;2F;3;4;;;#I"
Float#**;F;5[[I"y;T0;[[@
i;
T;:**;0;[ ;{ ;IC;"DRaises +float+ to the power of +other+.
2.0**3 #=> 8.0
;T;[o;7
;8I"
overload;F;90;;N;:0;;I"**(other);T;IC;" ;T;[o;<
;8I"return;F;9I" ;T;0;:[I"
Float;T;@P;[ ;I"@return [Float];T;0;@P;F;=i ;>0;5[[I"
other;T0;@P;[ ;I"lRaises +float+ to the power of +other+.
2.0**3 #=> 8.0
@overload **(other)
@return [Float];T;0;@P;F;o;;T; i;!i;"@;;I"static VALUE;T;AI"0static VALUE
flo_pow(VALUE x, VALUE y)
{
if (RB_TYPE_P(y, T_FIXNUM)) {
return DBL2NUM(pow(RFLOAT_VALUE(x), (double)FIX2LONG(y)));
}
else if (RB_TYPE_P(y, T_BIGNUM)) {
return DBL2NUM(pow(RFLOAT_VALUE(x), rb_big2dbl(y)));
}
else if (RB_TYPE_P(y, 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));
}
}
else {
return rb_num_coerce_bin(x, y, rb_intern("**"));
}
};T;BTo;1;2F;3;4;;;#I"
Float#==;F;5[[I"y;T0;[[@
i<;
T;:==;0;[ ;{ ;IC;"Returns +true+ only if +obj+ has the same value as +float+. Contrast this
with Float#eql?, which requires obj to be a Float.
The result of NaN == NaN
is undefined, so the
implementation-dependent value is returned.
1.0 == 1 #=> true
;T;[o;7
;8I"
overload;F;90;;O;:0;;I"==(obj);T;IC;" ;T;[o;<
;8I"return;F;9I" ;T;0;:[I"Boolean;T;@o;[ ;I"@return [Boolean];T;0;@o;F;=i ;>0;5[[I"obj;T0;@o;[ ;I"%Returns +true+ only if +obj+ has the same value as +float+. Contrast this
with Float#eql?, which requires obj to be a Float.
The result of NaN == NaN
is undefined, so the
implementation-dependent value is returned.
1.0 == 1 #=> true
@overload ==(obj)
@return [Boolean];T;0;@o;F;o;;T; i.;!i9;"@;;I"static VALUE;T;AI"static VALUE
flo_eq(VALUE x, VALUE y)
{
volatile double a, b;
if (RB_TYPE_P(y, T_FIXNUM) || RB_TYPE_P(y, T_BIGNUM)) {
return rb_integer_float_eq(y, x);
}
else if (RB_TYPE_P(y, T_FLOAT)) {
b = RFLOAT_VALUE(y);
#if defined(_MSC_VER) && _MSC_VER < 1300
if (isnan(b)) return Qfalse;
#endif
}
else {
return num_equal(x, y);
}
a = RFLOAT_VALUE(x);
#if defined(_MSC_VER) && _MSC_VER < 1300
if (isnan(a)) return Qfalse;
#endif
return (a == b)?Qtrue:Qfalse;
};T;BTo;1;2F;3;4;;;#I"Float#===;F;5[[I"y;T0;[[@
i<;
T;:===;0;[ ;{ ;IC;"Returns +true+ only if +obj+ has the same value as +float+. Contrast this
with Float#eql?, which requires obj to be a Float.
The result of NaN == NaN
is undefined, so the
implementation-dependent value is returned.
1.0 == 1 #=> true
;T;[o;7
;8I"
overload;F;90;;O;:0;;I"==(obj);T;IC;" ;T;[o;<
;8I"return;F;9I" ;T;0;:[I"Boolean;T;@;[ ;I"@return [Boolean];T;0;@;F;=i ;>0;5[[I"obj;T0;@;[ ;@;0;@;F;o;;T; i.;!i9;"@;;I"static VALUE;T;AI"static VALUE
flo_eq(VALUE x, VALUE y)
{
volatile double a, b;
if (RB_TYPE_P(y, T_FIXNUM) || RB_TYPE_P(y, T_BIGNUM)) {
return rb_integer_float_eq(y, x);
}
else if (RB_TYPE_P(y, T_FLOAT)) {
b = RFLOAT_VALUE(y);
#if defined(_MSC_VER) && _MSC_VER < 1300
if (isnan(b)) return Qfalse;
#endif
}
else {
return num_equal(x, y);
}
a = RFLOAT_VALUE(x);
#if defined(_MSC_VER) && _MSC_VER < 1300
if (isnan(a)) return Qfalse;
#endif
return (a == b)?Qtrue:Qfalse;
};T;BTo;1;2F;3;4;;;#I"Float#<=>;F;5[[I"y;T0;[[@
i;
T;:<=>;0;[ ;{ ;IC;"4Returns -1, 0, +1 or nil depending on whether +float+ is less than, equal
to, or greater than +real+. This is the basis for the tests in Comparable.
The result of NaN <=> NaN
is undefined, so the
implementation-dependent value is returned.
+nil+ is returned if the two values are incomparable.
;T;[o;7
;8I"
overload;F;90;;Q;:0;;I"<=>(real);T;IC;" ;T;[o;<
;8I"return;F;9I" ;T;0;:[ I"-1;TI"0;TI"+1;TI"nil;T;@;[ ;I" @return [ -1, 0, +1, nil];T;0;@;F;=i ;>0;5[[I" real;T0;@;[ ;I"hReturns -1, 0, +1 or nil depending on whether +float+ is less than, equal
to, or greater than +real+. This is the basis for the tests in Comparable.
The result of NaN <=> NaN
is undefined, so the
implementation-dependent value is returned.
+nil+ is returned if the two values are incomparable.
@overload <=>(real)
@return [ -1, 0, +1, nil];T;0;@;F;o;;T; iv;!i;"@;;I"static VALUE;T;AI"static VALUE
flo_cmp(VALUE x, VALUE y)
{
double a, b;
VALUE i;
a = RFLOAT_VALUE(x);
if (isnan(a)) return Qnil;
if (RB_TYPE_P(y, T_FIXNUM) || RB_TYPE_P(y, T_BIGNUM)) {
VALUE rel = rb_integer_float_cmp(y, x);
if (FIXNUM_P(rel))
return INT2FIX(-FIX2INT(rel));
return rel;
}
else if (RB_TYPE_P(y, T_FLOAT)) {
b = RFLOAT_VALUE(y);
}
else {
if (isinf(a) && (i = rb_check_funcall(y, rb_intern("infinite?"), 0, 0)) != Qundef) {
if (RTEST(i)) {
int j = rb_cmpint(i, x, y);
j = (a > 0.0) ? (j > 0 ? 0 : +1) : (j < 0 ? 0 : -1);
return INT2FIX(j);
}
if (a > 0.0) return INT2FIX(1);
return INT2FIX(-1);
}
return rb_num_coerce_cmp(x, y, id_cmp);
}
return rb_dbl_cmp(a, b);
};T;BTo;1;2F;3;4;;;#I"Float#>;F;5[[I"y;T0;[[@
i;
T;:>;0;[ ;{ ;IC;"Returns +true+ if +float+ is greater than +real+.
The result of NaN > NaN
is undefined, so the
implementation-dependent value is returned.
;T;[o;7
;8I"
overload;F;90;;R;:0;;I">(real);T;IC;" ;T;[o;<
;8I"return;F;9I" ;T;0;:[I"Boolean;T;@;[ ;I"@return [Boolean];T;0;@;F;=i ;>0;5[[I" real;T0;@;[ ;I"Returns +true+ if +float+ is greater than +real+.
The result of NaN > NaN
is undefined, so the
implementation-dependent value is returned.
@overload >(real)
@return [Boolean];T;0;@;F;o;;T; i;!i;"@;;I"static VALUE;T;AI"jstatic VALUE
flo_gt(VALUE x, VALUE y)
{
double a, b;
a = RFLOAT_VALUE(x);
if (RB_TYPE_P(y, T_FIXNUM) || RB_TYPE_P(y, T_BIGNUM)) {
VALUE rel = rb_integer_float_cmp(y, x);
if (FIXNUM_P(rel))
return -FIX2INT(rel) > 0 ? Qtrue : Qfalse;
return Qfalse;
}
else if (RB_TYPE_P(y, T_FLOAT)) {
b = RFLOAT_VALUE(y);
#if defined(_MSC_VER) && _MSC_VER < 1300
if (isnan(b)) return Qfalse;
#endif
}
else {
return rb_num_coerce_relop(x, y, '>');
}
#if defined(_MSC_VER) && _MSC_VER < 1300
if (isnan(a)) return Qfalse;
#endif
return (a > b)?Qtrue:Qfalse;
};T;BTo;1;2F;3;4;;;#I"
Float#>=;F;5[[I"y;T0;[[@
i;
T;:>=;0;[ ;{ ;IC;"Returns +true+ if +float+ is greater than or equal to +real+.
The result of NaN >= NaN
is undefined, so the
implementation-dependent value is returned.
;T;[o;7
;8I"
overload;F;90;;S;:0;;I"
>=(real);T;IC;" ;T;[o;<
;8I"return;F;9I" ;T;0;:[I"Boolean;T;@;[ ;I"@return [Boolean];T;0;@;F;=i ;>0;5[[I" real;T0;@;[ ;I"Returns +true+ if +float+ is greater than or equal to +real+.
The result of NaN >= NaN
is undefined, so the
implementation-dependent value is returned.
@overload >=(real)
@return [Boolean];T;0;@;F;o;;T; i;!i;"@;;I"static VALUE;T;AI"xstatic VALUE
flo_ge(VALUE x, VALUE y)
{
double a, b;
a = RFLOAT_VALUE(x);
if (RB_TYPE_P(y, T_FIXNUM) || RB_TYPE_P(y, T_BIGNUM)) {
VALUE rel = rb_integer_float_cmp(y, x);
if (FIXNUM_P(rel))
return -FIX2INT(rel) >= 0 ? Qtrue : Qfalse;
return Qfalse;
}
else if (RB_TYPE_P(y, T_FLOAT)) {
b = RFLOAT_VALUE(y);
#if defined(_MSC_VER) && _MSC_VER < 1300
if (isnan(b)) return Qfalse;
#endif
}
else {
return rb_num_coerce_relop(x, y, rb_intern(">="));
}
#if defined(_MSC_VER) && _MSC_VER < 1300
if (isnan(a)) return Qfalse;
#endif
return (a >= b)?Qtrue:Qfalse;
};T;BTo;1;2F;3;4;;;#I"Float#<;F;5[[I"y;T0;[[@
i;
T;:<;0;[ ;{ ;IC;"Returns +true+ if +float+ is less than +real+.
The result of NaN < NaN
is undefined, so the
implementation-dependent value is returned.
;T;[o;7
;8I"
overload;F;90;;T;:0;;I"<(real);T;IC;" ;T;[o;<
;8I"return;F;9I" ;T;0;:[I"Boolean;T;@;[ ;I"@return [Boolean];T;0;@;F;=i ;>0;5[[I" real;T0;@;[ ;I"Returns +true+ if +float+ is less than +real+.
The result of NaN < NaN
is undefined, so the
implementation-dependent value is returned.
@overload <(real)
@return [Boolean];T;0;@;F;o;;T; i;!i;"@;;I"static VALUE;T;AI"jstatic VALUE
flo_lt(VALUE x, VALUE y)
{
double a, b;
a = RFLOAT_VALUE(x);
if (RB_TYPE_P(y, T_FIXNUM) || RB_TYPE_P(y, T_BIGNUM)) {
VALUE rel = rb_integer_float_cmp(y, x);
if (FIXNUM_P(rel))
return -FIX2INT(rel) < 0 ? Qtrue : Qfalse;
return Qfalse;
}
else if (RB_TYPE_P(y, T_FLOAT)) {
b = RFLOAT_VALUE(y);
#if defined(_MSC_VER) && _MSC_VER < 1300
if (isnan(b)) return Qfalse;
#endif
}
else {
return rb_num_coerce_relop(x, y, '<');
}
#if defined(_MSC_VER) && _MSC_VER < 1300
if (isnan(a)) return Qfalse;
#endif
return (a < b)?Qtrue:Qfalse;
};T;BTo;1;2F;3;4;;;#I"
Float#<=;F;5[[I"y;T0;[[@
i;
T;:<=;0;[ ;{ ;IC;"Returns +true+ if +float+ is less than or equal to +real+.
The result of NaN <= NaN
is undefined, so the
implementation-dependent value is returned.
;T;[o;7
;8I"
overload;F;90;;U;:0;;I"
<=(real);T;IC;" ;T;[o;<
;8I"return;F;9I" ;T;0;:[I"Boolean;T;@+;[ ;I"@return [Boolean];T;0;@+;F;=i ;>0;5[[I" real;T0;@+;[ ;I"Returns +true+ if +float+ is less than or equal to +real+.
The result of NaN <= NaN
is undefined, so the
implementation-dependent value is returned.
@overload <=(real)
@return [Boolean];T;0;@+;F;o;;T; i;!i;"@;;I"static VALUE;T;AI"xstatic VALUE
flo_le(VALUE x, VALUE y)
{
double a, b;
a = RFLOAT_VALUE(x);
if (RB_TYPE_P(y, T_FIXNUM) || RB_TYPE_P(y, T_BIGNUM)) {
VALUE rel = rb_integer_float_cmp(y, x);
if (FIXNUM_P(rel))
return -FIX2INT(rel) <= 0 ? Qtrue : Qfalse;
return Qfalse;
}
else if (RB_TYPE_P(y, T_FLOAT)) {
b = RFLOAT_VALUE(y);
#if defined(_MSC_VER) && _MSC_VER < 1300
if (isnan(b)) return Qfalse;
#endif
}
else {
return rb_num_coerce_relop(x, y, rb_intern("<="));
}
#if defined(_MSC_VER) && _MSC_VER < 1300
if (isnan(a)) return Qfalse;
#endif
return (a <= b)?Qtrue:Qfalse;
};T;BTo;1;2F;3;4;;;#I"Float#eql?;F;5[[I"y;T0;[[@
iD;
T;: eql?;0;[ ;{ ;IC;"Returns +true+ only if +obj+ is a Float with the same value as +float+.
Contrast this with Float#==, which performs type conversions.
The result of NaN.eql?(NaN)
is undefined, so the
implementation-dependent value is returned.
1.0.eql?(1) #=> false
;T;[o;7
;8I"
overload;F;90;;V;:0;;I"eql?(obj);T;IC;" ;T;[o;<
;8I"return;F;9I" ;T;0;:[I"Boolean;T;@J;[ ;I"@return [Boolean];T;0;@J;F;=i ;>0;5[[I"obj;T0;@Jo;<
;8I"return;F;9I" ;T;0;:[I"Boolean;T;@J;[ ;I"6Returns +true+ only if +obj+ is a Float with the same value as +float+.
Contrast this with Float#==, which performs type conversions.
The result of NaN.eql?(NaN)
is undefined, so the
implementation-dependent value is returned.
1.0.eql?(1) #=> false
@overload eql?(obj)
@return [Boolean];T;0;@J;F;o;;T; i7;!iA;"@;;I"static VALUE;T;AI"static VALUE
flo_eql(VALUE x, VALUE y)
{
if (RB_TYPE_P(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;
}
return Qfalse;
};T;BTo;1;2F;3;4;;;#I"Float#hash;F;5[ ;[[@
i[;
T;: hash;0;[ ;{ ;IC;"(Returns a hash code for this float.
;T;[o;7
;8I"
overload;F;90;;W;:0;;I" hash;T;IC;" ;T;[o;<
;8I"return;F;9I" ;T;0;:[I"Integer;T;@n;[ ;I"@return [Integer];T;0;@n;F;=i ;>0;5[ ;@n;[ ;I"MReturns a hash code for this float.
@overload hash
@return [Integer];T;0;@n;F;o;;T; iT;!iX;"@;;I"static VALUE;T;AI"Tstatic VALUE
flo_hash(VALUE num)
{
return rb_dbl_hash(RFLOAT_VALUE(num));
};T;BTo;1;2F;3;4;;;#I"Float#to_f;F;5[ ;[[@
iZ;
T;: to_f;0;[ ;{ ;IC;"6Since +float+ is already a float, returns +self+.
;T;[o;7
;8I"
overload;F;90;;X;:0;;I" to_f;T;IC;" ;T;[o;<
;8I"return;F;9I" ;T;0;:[I" self;T;@;[ ;I"@return [self];T;0;@;F;=i ;>0;5[ ;@;[ ;I"XSince +float+ is already a float, returns +self+.
@overload to_f
@return [self];T;0;@;F;o;;T; iS;!iW;"@;;I"static VALUE;T;AI"9static VALUE
flo_to_f(VALUE num)
{
return num;
};T;BTo;1;2F;3;4;;;#I"Float#abs;F;5[ ;[[@
il;
T;:abs;0;[ ;{ ;IC;"dReturns the absolute value of +float+.
(-34.56).abs #=> 34.56
-34.56.abs #=> 34.56
;T;[o;7
;8I"
overload;F;90;;Y;:0;;I"abs;T;IC;" ;T;[o;<
;8I"return;F;9I" ;T;0;:[I"
Float;T;@;[ ;I"@return [Float];T;0;@;F;=i ;>0;5[ ;@o;7
;8I"
overload;F;90;:magnitude;:0;;I"magnitude;T;IC;" ;T;[o;<
;8I"return;F;9I" ;T;0;:[I"
Float;T;@;[ ;I"@return [Float];T;0;@;F;=i ;>0;5[ ;@;[ ;I"Returns the absolute value of +float+.
(-34.56).abs #=> 34.56
-34.56.abs #=> 34.56
@overload abs
@return [Float]
@overload magnitude
@return [Float];T;0;@;F;o;;T; i`;!ij;"@;;I"static VALUE;T;AI"kstatic VALUE
flo_abs(VALUE flt)
{
double val = fabs(RFLOAT_VALUE(flt));
return DBL2NUM(val);
};T;BTo;1;2F;3;4;;;#I"Float#magnitude;F;5[ ;[[@
il;
T;;Z;0;[ ;{ ;IC;"dReturns the absolute value of +float+.
(-34.56).abs #=> 34.56
-34.56.abs #=> 34.56
;T;[o;7
;8I"
overload;F;90;;Y;:0;;I"abs;T;IC;" ;T;[o;<
;8I"return;F;9I" ;T;0;:[I"
Float;T;@;[ ;I"@return [Float];T;0;@;F;=i ;>0;5[ ;@o;7
;8I"
overload;F;90;;Z;:0;;I"magnitude;T;IC;" ;T;[o;<
;8I"return;F;9I" ;T;0;:[I"
Float;T;@;[ ;I"@return [Float];T;0;@;F;=i ;>0;5[ ;@;[ ;@;0;@;F;o;;T; i`;!ij;"@;;I"static VALUE;T;AI"kstatic VALUE
flo_abs(VALUE flt)
{
double val = fabs(RFLOAT_VALUE(flt));
return DBL2NUM(val);
};T;BTo;1;2F;3;4;;;#I"Float#zero?;F;5[ ;[[@
i{;
T;:
zero?;0;[ ;{ ;IC;"&Returns +true+ if +float+ is 0.0.
;T;[o;7
;8I"
overload;F;90;;[;:0;;I"
zero?;T;IC;" ;T;[o;<
;8I"return;F;9I" ;T;0;:[I"Boolean;T;@;[ ;I"@return [Boolean];T;0;@;F;=i ;>0;5[ ;@o;<
;8I"return;F;9@f;0;:[@h;@;[ ;I"MReturns +true+ if +float+ is 0.0.
@overload zero?
@return [Boolean];T;0;@;F;o;;T; is;!ix;"@;;I"static VALUE;T;AI"wstatic VALUE
flo_zero_p(VALUE num)
{
if (RFLOAT_VALUE(num) == 0.0) {
return Qtrue;
}
return Qfalse;
};T;BTo;1;2F;3;4;;;#I"Float#to_i;F;5[ ;[[@
i;
T;: to_i;0;[ ;{ ;IC;"^Returns the +float+ truncated to an Integer.
Synonyms are #to_i, #to_int, and #truncate.
;T;[o;7
;8I"
overload;F;90;;\;:0;;I" to_i;T;IC;" ;T;[o;<
;8I"return;F;9I" ;T;0;:[I"Integer;T;@;[ ;I"@return [Integer];T;0;@;F;=i ;>0;5[ ;@o;7
;8I"
overload;F;90;:to_int;:0;;I"to_int;T;IC;" ;T;[o;<
;8I"return;F;9I" ;T;0;:[I"Integer;T;@;[ ;I"@return [Integer];T;0;@;F;=i ;>0;5[ ;@o;7
;8I"
overload;F;90;:
truncate;:0;;I"
truncate;T;IC;" ;T;[o;<
;8I"return;F;9I" ;T;0;:[I"Integer;T;@;[ ;I"@return [Integer];T;0;@;F;=i ;>0;5[ ;@;[ ;I"Returns the +float+ truncated to an Integer.
Synonyms are #to_i, #to_int, and #truncate.
@overload to_i
@return [Integer]
@overload to_int
@return [Integer]
@overload truncate
@return [Integer];T;0;@;F;o;;T; iz;!i;"@;;I"static VALUE;T;AI"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);
}
val = (long)f;
return LONG2FIX(val);
};T;BTo;1;2F;3;4;;;#I"Float#to_int;F;5[ ;[[@
i;
T;;];0;[ ;{ ;IC;"^Returns the +float+ truncated to an Integer.
Synonyms are #to_i, #to_int, and #truncate.
;T;[o;7
;8I"
overload;F;90;;\;:0;;I" to_i;T;IC;" ;T;[o;<
;8I"return;F;9I" ;T;0;:[I"Integer;T;@F;[ ;I"@return [Integer];T;0;@F;F;=i ;>0;5[ ;@Fo;7
;8I"
overload;F;90;;];:0;;I"to_int;T;IC;" ;T;[o;<
;8I"return;F;9I" ;T;0;:[I"Integer;T;@F;[ ;I"@return [Integer];T;0;@F;F;=i ;>0;5[ ;@Fo;7
;8I"
overload;F;90;;^;:0;;I"
truncate;T;IC;" ;T;[o;<
;8I"return;F;9I" ;T;0;:[I"Integer;T;@F;[ ;I"@return [Integer];T;0;@F;F;=i ;>0;5[ ;@F;[ ;@B;0;@F;F;o;;T; iz;!i;"@;;I"static VALUE;T;AI"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);
}
val = (long)f;
return LONG2FIX(val);
};T;BTo;1;2F;3;4;;;#I"Float#floor;F;5[ ;[[@
i;
T;:
floor;0;[ ;{ ;IC;"Returns the largest integer less than or equal to +float+.
1.2.floor #=> 1
2.0.floor #=> 2
(-1.2).floor #=> -2
(-2.0).floor #=> -2
;T;[o;7
;8I"
overload;F;90;;_;:0;;I"
floor;T;IC;" ;T;[o;<
;8I"return;F;9I" ;T;0;:[I"Integer;T;@z;[ ;I"@return [Integer];T;0;@z;F;=i ;>0;5[ ;@z;[ ;I"Returns the largest integer less than or equal to +float+.
1.2.floor #=> 1
2.0.floor #=> 2
(-1.2).floor #=> -2
(-2.0).floor #=> -2
@overload floor
@return [Integer];T;0;@z;F;o;;T; i;!i;"@;;I"static VALUE;T;AI"static VALUE
flo_floor(VALUE num)
{
double f = floor(RFLOAT_VALUE(num));
long val;
if (!FIXABLE(f)) {
return rb_dbl2big(f);
}
val = (long)f;
return LONG2FIX(val);
};T;BTo;1;2F;3;4;;;#I"Float#ceil;F;5[ ;[[@
i;
T;: ceil;0;[ ;{ ;IC;"Returns the smallest Integer greater than or equal to +float+.
1.2.ceil #=> 2
2.0.ceil #=> 2
(-1.2).ceil #=> -1
(-2.0).ceil #=> -2
;T;[o;7
;8I"
overload;F;90;;`;:0;;I" ceil;T;IC;" ;T;[o;<
;8I"return;F;9I" ;T;0;:[I"Integer;T;@;[ ;I"@return [Integer];T;0;@;F;=i ;>0;5[ ;@;[ ;I"Returns the smallest Integer greater than or equal to +float+.
1.2.ceil #=> 2
2.0.ceil #=> 2
(-1.2).ceil #=> -1
(-2.0).ceil #=> -2
@overload ceil
@return [Integer];T;0;@;F;o;;T; i;!i;"@;;I"static VALUE;T;AI"static VALUE
flo_ceil(VALUE num)
{
double f = ceil(RFLOAT_VALUE(num));
long val;
if (!FIXABLE(f)) {
return rb_dbl2big(f);
}
val = (long)f;
return LONG2FIX(val);
};T;BTo;1;2F;3;4;;;#I"Float#round;F;5[[I"
*args;T0;[[@
iI;
T;:
round;0;[ ;{ ;IC;"Rounds +float+ 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
;T;[o;7
;8I"
overload;F;90;;a;:0;;I"round([ndigits]);T;IC;" ;T;[o;<
;8I"return;F;9I" ;T;0;:[I"Integer;TI"
Float;T;@;[ ;I"@return [Integer, Float];T;0;@;F;=i ;>0;5[[I"[ndigits];T0;@;[ ;I"Rounds +float+ 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
@overload round([ndigits])
@return [Integer, Float];T;0;@;F;o;;T; i*;!iF;"@;;I"static VALUE;T;AI"ystatic 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};
if (argc > 0 && rb_scan_args(argc, argv, "01", &nd) == 1) {
ndigits = NUM2INT(nd);
}
if (ndigits < 0) {
return int_round_0(flo_truncate(num), ndigits);
}
number = RFLOAT_VALUE(num);
if (ndigits == 0) {
return dbl2ival(number);
}
frexp(number, &binexp);
/* Let `exp` be such that `number` is written as:"0.#{digits}e#{exp}",
i.e. such that 10 ** (exp - 1) <= |number| < 10 ** exp
Recall that up to float_dig digits can be needed to represent a double,
so if ndigits + exp >= float_dig, the intermediate value (number * 10 ** ndigits)
will be an integer and thus the result is the original number.
If ndigits + exp <= 0, the result is 0 or "1e#{exp}", so
if ndigits + exp < 0, the result is 0.
We have:
2 ** (binexp-1) <= |number| < 2 ** binexp
10 ** ((binexp-1)/log_2(10)) <= |number| < 10 ** (binexp/log_2(10))
If binexp >= 0, and since log_2(10) = 3.322259:
10 ** (binexp/4 - 1) < |number| < 10 ** (binexp/3)
floor(binexp/4) <= exp <= ceil(binexp/3)
If binexp <= 0, swap the /4 and the /3
So if ndigits + floor(binexp/(4 or 3)) >= float_dig, the result is number
If ndigits + ceil(binexp/(3 or 4)) < 0 the result is 0
*/
if (isinf(number) || isnan(number) ||
(ndigits >= float_dig - (binexp > 0 ? binexp / 4 : binexp / 3 - 1))) {
return num;
}
if (ndigits < - (binexp > 0 ? binexp / 3 + 1 : binexp / 4)) {
return DBL2NUM(0);
}
f = pow(10, ndigits);
return DBL2NUM(round(number * f) / f);
};T;BTo;1;2F;3;4;;;#I"Float#truncate;F;5[ ;[[@
i;
T;;^;0;[ ;{ ;IC;"^Returns the +float+ truncated to an Integer.
Synonyms are #to_i, #to_int, and #truncate.
;T;[o;7
;8I"
overload;F;90;;\;:0;;I" to_i;T;IC;" ;T;[o;<
;8I"return;F;9I" ;T;0;:[I"Integer;T;@;[ ;I"@return [Integer];T;0;@;F;=i ;>0;5[ ;@o;7
;8I"
overload;F;90;;];:0;;I"to_int;T;IC;" ;T;[o;<
;8I"return;F;9I" ;T;0;:[I"Integer;T;@;[ ;I"@return [Integer];T;0;@;F;=i ;>0;5[ ;@o;7
;8I"
overload;F;90;;^;:0;;I"
truncate;T;IC;" ;T;[o;<
;8I"return;F;9I" ;T;0;:[I"Integer;T;@;[ ;I"@return [Integer];T;0;@;F;=i ;>0;5[ ;@;[ ;@B;0;@;F;o;;T; iz;!i;"@;;I"static VALUE;T;AI"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);
}
val = (long)f;
return LONG2FIX(val);
};T;BTo;1;2F;3;4;;;#I"Float#nan?;F;5[ ;[[@
i;
T;: nan?;0;[ ;{ ;IC;"Returns +true+ if +float+ is an invalid IEEE floating point number.
a = -1.0 #=> -1.0
a.nan? #=> false
a = 0.0/0.0 #=> NaN
a.nan? #=> true
;T;[o;7
;8I"
overload;F;90;;b;:0;;I" nan?;T;IC;" ;T;[o;<
;8I"return;F;9I" ;T;0;:[I"Boolean;T;@;[ ;I"@return [Boolean];T;0;@;F;=i ;>0;5[ ;@o;<
;8I"return;F;9@f;0;:[@h;@;[ ;I"Returns +true+ if +float+ is an invalid IEEE floating point number.
a = -1.0 #=> -1.0
a.nan? #=> false
a = 0.0/0.0 #=> NaN
a.nan? #=> true
@overload nan?
@return [Boolean];T;0;@;F;o;;T; i;!i;"@;;I"static VALUE;T;AI"~static VALUE
flo_is_nan_p(VALUE num)
{
double value = RFLOAT_VALUE(num);
return isnan(value) ? Qtrue : Qfalse;
};T;BTo;1;2F;3;4;;;#I"Float#infinite?;F;5[ ;[[@
i;
T;:infinite?;0;[ ;{ ;IC;"Return values corresponding to the value of +float+:
+finite+:: +nil+
+-Infinity+:: +-1+
++Infinity+:: +1+
For example:
(0.0).infinite? #=> nil
(-1.0/0.0).infinite? #=> -1
(+1.0/0.0).infinite? #=> 1
;T;[o;7
;8I"
overload;F;90;;c;:0;;I"infinite?;T;IC;" ;T;[o;<
;8I"return;F;9I" ;T;0;:[I"nil;TI"-1;TI"+1;T;@";[ ;I"@return [nil, -1, +1];T;0;@";F;=i ;>0;5[ ;@"o;<
;8I"return;F;9@f;0;:[@h;@";[ ;I"Return values corresponding to the value of +float+:
+finite+:: +nil+
+-Infinity+:: +-1+
++Infinity+:: +1+
For example:
(0.0).infinite? #=> nil
(-1.0/0.0).infinite? #=> -1
(+1.0/0.0).infinite? #=> 1
@overload infinite?
@return [nil, -1, +1];T;0;@";F;o;;T; i;!i;"@;;I"static VALUE;T;AI"static VALUE
flo_is_infinite_p(VALUE num)
{
double value = RFLOAT_VALUE(num);
if (isinf(value)) {
return INT2FIX( value < 0 ? -1 : 1 );
}
return Qnil;
};T;BTo;1;2F;3;4;;;#I"Float#finite?;F;5[ ;[[@
i;
T;:finite?;0;[ ;{ ;IC;"uReturns +true+ if +float+ is a valid IEEE floating point number (it is not
infinite, and Float#nan? is +false+).
;T;[o;7
;8I"
overload;F;90;;d;:0;;I"finite?;T;IC;" ;T;[o;<
;8I"return;F;9I" ;T;0;:[I"Boolean;T;@B;[ ;I"@return [Boolean];T;0;@B;F;=i ;>0;5[ ;@Bo;<
;8I"return;F;9@f;0;:[@h;@B;[ ;I"Returns +true+ if +float+ is a valid IEEE floating point number (it is not
infinite, and Float#nan? is +false+).
@overload finite?
@return [Boolean];T;0;@B;F;o;;T; i;!i;"@;;I"static VALUE;T;AI"static VALUE
flo_is_finite_p(VALUE num)
{
double value = RFLOAT_VALUE(num);
#if HAVE_ISFINITE
if (!isfinite(value))
return Qfalse;
#else
if (isinf(value) || isnan(value))
return Qfalse;
#endif
return Qtrue;
};T;BTo;1;2F;3;4;;;#I"Float#arg;F;5[ ;[[I"complex.c;Ti;
T;:arg;0;[ ;{ ;IC;"6Returns 0 if the value is positive, pi otherwise.
;T;[o;7
;8I"
overload;F;90;;e;:0;;I"arg;T;IC;" ;T;[o;<
;8I"return;F;9I" ;T;0;:[I"0;TI"
Float;T;@`;[ ;I"@return [ 0, Float];T;0;@`;F;=i ;>0;5[ ;@`o;7
;8I"
overload;F;90;:
angle;:0;;I"
angle;T;IC;" ;T;[o;<
;8I"return;F;9I" ;T;0;:[I"0;TI"
Float;T;@`;[ ;I"@return [ 0, Float];T;0;@`;F;=i ;>0;5[ ;@`o;7
;8I"
overload;F;90;:
phase;:0;;I"
phase;T;IC;" ;T;[o;<
;8I"return;F;9I" ;T;0;:[I"0;TI"
Float;T;@`;[ ;I"@return [ 0, Float];T;0;@`;F;=i ;>0;5[ ;@`;[ ;I"Returns 0 if the value is positive, pi otherwise.
@overload arg
@return [ 0, Float]
@overload angle
@return [ 0, Float]
@overload phase
@return [ 0, Float];T;0;@`;F;o;;T; i;!i;"@;;I"static VALUE;T;AI"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);
};T;BTo;1;2F;3;4;;;#I"Float#angle;F;5[ ;[[@ei;
T;;f;0;[ ;{ ;IC;"6Returns 0 if the value is positive, pi otherwise.
;T;[o;7
;8I"
overload;F;90;;e;:0;;I"arg;T;IC;" ;T;[o;<
;8I"return;F;9I" ;T;0;:[I"0;TI"
Float;T;@;[ ;I"@return [ 0, Float];T;0;@;F;=i ;>0;5[ ;@o;7
;8I"
overload;F;90;;f;:0;;I"
angle;T;IC;" ;T;[o;<
;8I"return;F;9I" ;T;0;:[I"0;TI"
Float;T;@;[ ;I"@return [ 0, Float];T;0;@;F;=i ;>0;5[ ;@o;7
;8I"
overload;F;90;;g;:0;;I"
phase;T;IC;" ;T;[o;<
;8I"return;F;9I" ;T;0;:[I"0;TI"
Float;T;@;[ ;I"@return [ 0, Float];T;0;@;F;=i ;>0;5[ ;@;[ ;@;0;@;F;o;;T; i;!i;"@;;I"static VALUE;T;AI"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);
};T;BTo;1;2F;3;4;;;#I"Float#phase;F;5[ ;[[@ei;
T;;g;0;[ ;{ ;IC;"6Returns 0 if the value is positive, pi otherwise.
;T;[o;7
;8I"
overload;F;90;;e;:0;;I"arg;T;IC;" ;T;[o;<
;8I"return;F;9I" ;T;0;:[I"0;TI"
Float;T;@;[ ;I"@return [ 0, Float];T;0;@;F;=i ;>0;5[ ;@o;7
;8I"
overload;F;90;;f;:0;;I"
angle;T;IC;" ;T;[o;<
;8I"return;F;9I" ;T;0;:[I"0;TI"
Float;T;@;[ ;I"@return [ 0, Float];T;0;@;F;=i ;>0;5[ ;@o;7
;8I"
overload;F;90;;g;:0;;I"
phase;T;IC;" ;T;[o;<
;8I"return;F;9I" ;T;0;:[I"0;TI"
Float;T;@;[ ;I"@return [ 0, Float];T;0;@;F;=i ;>0;5[ ;@;[ ;@;0;@;F;o;;T; i;!i;"@;;I"static VALUE;T;AI"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);
};T;BTo;1;2F;3;4;;;#I"Float#numerator;F;5[ ;[[I"rational.c;TiR;
T;:numerator;0;[ ;{ ;IC;"Returns the numerator. The result is machine dependent.
n = 0.3.numerator #=> 5404319552844595
d = 0.3.denominator #=> 18014398509481984
n.fdiv(d) #=> 0.3
;T;[o;7
;8I"
overload;F;90;;h;:0;;I"numerator;T;IC;" ;T;[o;<
;8I"return;F;9I" ;T;0;:[I"Integer;T;@;[ ;I"@return [Integer];T;0;@;F;=i ;>0;5[ ;@;[ ;I"Returns the numerator. The result is machine dependent.
n = 0.3.numerator #=> 5404319552844595
d = 0.3.denominator #=> 18014398509481984
n.fdiv(d) #=> 0.3
@overload numerator
@return [Integer];T;0;@;F;o;;T; iH;!iP;"@;;I"static VALUE;T;AI"static VALUE
float_numerator(VALUE self)
{
double d = RFLOAT_VALUE(self);
if (isinf(d) || isnan(d))
return self;
return rb_call_super(0, 0);
};T;BTo;1;2F;3;4;;;#I"Float#denominator;F;5[ ;[[@id;
T;:denominator;0;[ ;{ ;IC;"aReturns the denominator (always positive). The result is machine
dependent.
See numerator.
;T;[o;7
;8I"
overload;F;90;;i;:0;;I"denominator;T;IC;" ;T;[o;<
;8I"return;F;9I" ;T;0;:[I"Integer;T;@#;[ ;I"@return [Integer];T;0;@#;F;=i ;>0;5[ ;@#;[ ;I"Returns the denominator (always positive). The result is machine
dependent.
See numerator.
@overload denominator
@return [Integer];T;0;@#;F;o;;T; i[;!ib;"@;;I"static VALUE;T;AI"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);
};T;BTo;1;2F;3;4;;;#I"Float#to_r;F;5[ ;[[@i;
T;: to_r;0;[ ;{ ;IC;" 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.
2.0.to_r #=> (2/1)
2.5.to_r #=> (5/2)
-0.75.to_r #=> (-3/4)
0.0.to_r #=> (0/1)
See rationalize.
;T;[o;7
;8I"
overload;F;90;;j;:0;;I" to_r;T;IC;" ;T;[ ;[ ;I" ;T;0;@>;F;=i ;>0;5[ ;@>;[ ;I"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.
2.0.to_r #=> (2/1)
2.5.to_r #=> (5/2)
-0.75.to_r #=> (-3/4)
0.0.to_r #=> (0/1)
See rationalize.
@overload to_r;T;0;@>;F;o;;T; i;!i;"@;;I"static VALUE;T;AI"|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)));
}
#else
return f_to_r(f_mul(f, f_expt(INT2FIX(FLT_RADIX), n)));
#endif
};T;BTo;1;2F;3;4;;;#I"Float#rationalize;F;5[[@0;[[@i);
T;:rationalize;0;[ ;{ ;IC;"Returns a simpler approximation of the value (flt-|eps| <= result
<= flt+|eps|). if the optional eps is not given, it will be chosen
automatically.
0.3.rationalize #=> (3/10)
1.333.rationalize #=> (1333/1000)
1.333.rationalize(0.01) #=> (4/3)
See to_r.
;T;[o;7
;8I"
overload;F;90;;k;:0;;I"rationalize([eps]);T;IC;" ;T;[ ;[ ;I" ;T;0;@T;F;=i ;>0;5[[I"
[eps];T0;@T;[ ;I"8Returns a simpler approximation of the value (flt-|eps| <= result
<= flt+|eps|). if the optional eps is not given, it will be chosen
automatically.
0.3.rationalize #=> (3/10)
1.333.rationalize #=> (1333/1000)
1.333.rationalize(0.01) #=> (4/3)
See to_r.
@overload rationalize([eps]);T;0;@T;F;o;;T; i;!i&;"@;;I"static VALUE;T;AI"istatic VALUE
float_rationalize(int argc, VALUE *argv, VALUE self)
{
VALUE e;
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) {
return rb_flt_rationalize_with_prec(self, e);
}
else {
return rb_flt_rationalize(self);
}
};T;BT:@owner@:@class_mixinsIC;[ ;l@:@instance_mixinsIC;[ ;l@:@attributesIC:SymbolHash{:
classIC;p{ :@symbolize_valueT;4IC;p{ ;rT;rT:
@aliases{@;6:@groups[ ;[[@
ir[@
i;
T;:
Float;;@;;;[ ;{ ;IC;"******************************************************************
Float objects represent inexact real numbers using the native
architecture's double-precision floating point representation.
Floating point has a different arithmetic and is an inexact number.
So you should know its esoteric system. see following:
- http://docs.sun.com/source/806-3568/ncg_goldberg.html
- http://wiki.github.com/rdp/ruby_tutorials_core/ruby-talk-faq#wiki-floats_imprecise
- http://en.wikipedia.org/wiki/Floating_point#Accuracy_problems;T;[ ;[ ;I"******************************************************************
Float objects represent inexact real numbers using the native
architecture's double-precision floating point representation.
Floating point has a different arithmetic and is an inexact number.
So you should know its esoteric system. see following:
- http://docs.sun.com/source/806-3568/ncg_goldberg.html
- http://wiki.github.com/rdp/ruby_tutorials_core/ruby-talk-faq#wiki-floats_imprecise
- http://en.wikipedia.org/wiki/Floating_point#Accuracy_problems
;T;0;@;F;o;;T; ir;!i~;=i ;"@;#I"
Float;F:@superclasso; ;IC;[/o;1;2F;3;4;;;#I"#Numeric#singleton_method_added;F;5[[I" name;T0;[[@
i>;
T;:singleton_method_added;0;[ ;{ ;IC;"Trap attempts to add methods to Numeric objects. Always raises a TypeError.
Numerics should be values; singleton_methods should not be added to them.
;T;[ ;[ ;I"Trap attempts to add methods to Numeric objects. Always raises a TypeError.
Numerics should be values; singleton_methods should not be added to them.
;T;0;@;F;o;;T; i8;!i;;"@;;I"static VALUE;T;AI"nstatic VALUE
num_sadded(VALUE x, VALUE name)
{
ID mid = rb_to_id(name);
/* ruby_frame = ruby_frame->prev; */ /* pop frame for "singleton_method_added" */
rb_remove_method_id(rb_singleton_class(x), mid);
rb_raise(rb_eTypeError,
"can't define singleton method \"%s\" for %s",
rb_id2name(mid),
rb_obj_classname(x));
UNREACHABLE;
};T;BTo;1;2F;3;4;;;#I"Numeric#initialize_copy;F;5[[I"y;T0;[[@
iQ;
T;:initialize_copy;0;[ ;{ ;IC;"Numerics are immutable values, which should not be copied.
Any attempt to use this method on a Numeric will raise a TypeError.
;T;[ ;[ ;I"Numerics are immutable values, which should not be copied.
Any attempt to use this method on a Numeric will raise a TypeError.
;T;0;@;F;o;;T; iL;!iO;"@;;I"static VALUE;T;AI"static VALUE
num_init_copy(VALUE x, VALUE y)
{
rb_raise(rb_eTypeError, "can't copy %s", rb_obj_classname(x));
UNREACHABLE;
};T;BTo;1;2F;3;4;;;#I"Numeric#coerce;F;5[[I"y;T0;[[@
i;
T;;C;0;[ ;{ ;IC;"If a +numeric is the same type as +num+, returns an array containing
+numeric+ and +num+. Otherwise, returns an array with both a +numeric+ and
+num+ represented as Float objects.
This coercion mechanism is used by Ruby to handle mixed-type numeric
operations: it is intended to find a compatible common type between the two
operands of the operator.
1.coerce(2.5) #=> [2.5, 1.0]
1.2.coerce(3) #=> [3.0, 1.2]
1.coerce(2) #=> [2, 1]
;T;[o;7
;8I"
overload;F;90;;C;:0;;I"coerce(numeric);T;IC;" ;T;[o;<
;8I"return;F;9I" ;T;0;:[I"
Array;T;@;[ ;I"@return [Array];T;0;@;F;=i ;>0;5[[I"numeric;T0;@;[ ;I"If a +numeric is the same type as +num+, returns an array containing
+numeric+ and +num+. Otherwise, returns an array with both a +numeric+ and
+num+ represented as Float objects.
This coercion mechanism is used by Ruby to handle mixed-type numeric
operations: it is intended to find a compatible common type between the two
operands of the operator.
1.coerce(2.5) #=> [2.5, 1.0]
1.2.coerce(3) #=> [3.0, 1.2]
1.coerce(2) #=> [2, 1]
@overload coerce(numeric)
@return [Array];T;0;@;F;o;;T; i;!i;"@;;I"static VALUE;T;AI"static VALUE
num_coerce(VALUE x, VALUE y)
{
if (CLASS_OF(x) == CLASS_OF(y))
return rb_assoc_new(y, x);
x = rb_Float(x);
y = rb_Float(y);
return rb_assoc_new(y, x);
};T;BTo;1;2F;3;4;;;#I"Numeric#i;F;5[ ;[[@
in;
T;:i;0;[ ;{ ;IC;"SReturns the corresponding imaginary number.
Not available for complex numbers.
;T;[o;7
;8I"
overload;F;90;;y;:0;;I"i;T;IC;" ;T;[o;<
;8I"return;F;9I"Complex(0];T;0;:[I"Complex(0];T;@;[ ;I"@return [ Complex(0];T;0;@;F;=i ;>0;5[ ;@;[ ;I"xReturns the corresponding imaginary number.
Not available for complex numbers.
@overload i
@return [ Complex(0];T;0;@;F;o;;T; if;!ik;"@;;I"static VALUE;T;AI"Zstatic VALUE
num_imaginary(VALUE num)
{
return rb_complex_new(INT2FIX(0), num);
};T;BTo;1;2F;3;4;;;#I"Numeric#+@;F;5[ ;[[@
i`;
T;:+@;0;[ ;{ ;IC;"/Unary Plus---Returns the receiver's value.
;T;[o;7
;8I"
overload;F;90;;F;:0;;I" +num;T;IC;" ;T;[o;<
;8I"return;F;9I" ;T;0;:[I"Numeric;T;@;[ ;I"@return [Numeric];T;0;@;F;=i ;>0;5[ ;@;[ ;I"TUnary Plus---Returns the receiver's value.
@overload +num
@return [Numeric];T;0;@;F;o;;T; iY;!i];"@;;I"static VALUE;T;AI":static VALUE
num_uplus(VALUE num)
{
return num;
};T;BTo;1;2F;3;4;;;#I"Numeric#-@;F;5[ ;[[@
i|;
T;;D;0;[ ;{ ;IC;"9Unary Minus---Returns the receiver's value, negated.
;T;[o;7
;8I"
overload;F;90;;E;:0;;I" -num;T;IC;" ;T;[o;<
;8I"return;F;9I" ;T;0;:[I"Numeric;T;@;[ ;I"@return [Numeric];T;0;@;F;=i ;>0;5[ ;@;[ ;I"^Unary Minus---Returns the receiver's value, negated.
@overload -num
@return [Numeric];T;0;@;F;o;;T; iu;!iy;"@;;I"static VALUE;T;AI"static VALUE
num_uminus(VALUE num)
{
VALUE zero;
zero = INT2FIX(0);
do_coerce(&zero, &num, TRUE);
return rb_funcall(zero, '-', 1, num);
};T;BTo;1;2F;3;4;;;#I"Numeric#<=>;F;5[[I"y;T0;[[@
i ;
T;;Q;0;[ ;{ ;IC;"mReturns zero if +number+ equals +other+, otherwise +nil+ is returned if the
two values are incomparable.
;T;[o;7
;8I"
overload;F;90;;Q;:0;;I"<=>(other);T;IC;" ;T;[o;<
;8I"return;F;9I" ;T;0;:[I"0;TI"nil;T;@;[ ;I"@return [ 0, nil];T;0;@;F;=i ;>0;5[[I"
other;T0;@;[ ;I"Returns zero if +number+ equals +other+, otherwise +nil+ is returned if the
two values are incomparable.
@overload <=>(other)
@return [ 0, nil];T;0;@;F;o;;T; i;!i;"@;;I"static VALUE;T;AI"cstatic VALUE
num_cmp(VALUE x, VALUE y)
{
if (x == y) return INT2FIX(0);
return Qnil;
};T;BTo;1;2F;3;4;;;#I"Numeric#eql?;F;5[[I"y;T0;[[@
i;
T;;V;0;[ ;{ ;IC;"Returns +true+ if +num+ and +numeric+ are the same type and have equal
values.
1 == 1.0 #=> true
1.eql?(1.0) #=> false
(1.0).eql?(1.0) #=> true
;T;[o;7
;8I"
overload;F;90;;V;:0;;I"eql?(numeric);T;IC;" ;T;[o;<
;8I"return;F;9I" ;T;0;:[I"Boolean;T;@1;[ ;I"@return [Boolean];T;0;@1;F;=i ;>0;5[[I"numeric;T0;@1o;<
;8I"return;F;9@f;0;:[@h;@1;[ ;I"Returns +true+ if +num+ and +numeric+ are the same type and have equal
values.
1 == 1.0 #=> true
1.eql?(1.0) #=> false
(1.0).eql?(1.0) #=> true
@overload eql?(numeric)
@return [Boolean];T;0;@1;F;o;;T; i;!i
;"@;;I"static VALUE;T;AI"vstatic VALUE
num_eql(VALUE x, VALUE y)
{
if (TYPE(x) != TYPE(y)) return Qfalse;
return rb_equal(x, y);
};T;BTo;1;2F;3;4;;;#I"Numeric#fdiv;F;5[[I"y;T0;[[@
i;
T;;J;0;[ ;{ ;IC;"Returns float division.
;T;[o;7
;8I"
overload;F;90;;J;:0;;I"fdiv(numeric);T;IC;" ;T;[o;<
;8I"return;F;9I" ;T;0;:[I"
Float;T;@S;[ ;I"@return [Float];T;0;@S;F;=i ;>0;5[[I"numeric;T0;@S;[ ;I"HReturns float division.
@overload fdiv(numeric)
@return [Float];T;0;@S;F;o;;T; i;!i;"@;;I"static VALUE;T;AI"_static VALUE
num_fdiv(VALUE x, VALUE y)
{
return rb_funcall(rb_Float(x), '/', 1, y);
};T;BTo;1;2F;3;4;;;#I"Numeric#div;F;5[[I"y;T0;[[@
i;
T;:div;0;[ ;{ ;IC;"Uses +/+ to perform division, then converts the result to an integer.
+numeric+ does not define the +/+ operator; this is left to subclasses.
Equivalent to num.divmod(numeric)[0]
.
See Numeric#divmod.
;T;[o;7
;8I"
overload;F;90;;{;:0;;I"div(numeric);T;IC;" ;T;[o;<
;8I"return;F;9I" ;T;0;:[I"Integer;T;@r;[ ;I"@return [Integer];T;0;@r;F;=i ;>0;5[[I"numeric;T0;@r;[ ;I"Uses +/+ to perform division, then converts the result to an integer.
+numeric+ does not define the +/+ operator; this is left to subclasses.
Equivalent to num.divmod(numeric)[0]
.
See Numeric#divmod.
@overload div(numeric)
@return [Integer];T;0;@r;F;o;;T; i;!i;"@;;I"static VALUE;T;AI"static VALUE
num_div(VALUE x, VALUE y)
{
if (rb_equal(INT2FIX(0), y)) rb_num_zerodiv();
return rb_funcall(rb_funcall(x, '/', 1, y), rb_intern("floor"), 0);
};T;BTo;1;2F;3;4;;;#I"Numeric#divmod;F;5[[I"y;T0;[[@
i;
T;;M;0;[ ;{ ;IC;"3Returns an array containing the quotient and modulus obtained by dividing
+num+ by +numeric+.
If q, r = * x.divmod(y)
, then
q = floor(x/y)
x = q*y+r
The quotient is rounded toward -infinity, as shown in the following table:
a | b | a.divmod(b) | a/b | a.modulo(b) | a.remainder(b)
------+-----+---------------+---------+-------------+---------------
13 | 4 | 3, 1 | 3 | 1 | 1
------+-----+---------------+---------+-------------+---------------
13 | -4 | -4, -3 | -4 | -3 | 1
------+-----+---------------+---------+-------------+---------------
-13 | 4 | -4, 3 | -4 | 3 | -1
------+-----+---------------+---------+-------------+---------------
-13 | -4 | 3, -1 | 3 | -1 | -1
------+-----+---------------+---------+-------------+---------------
11.5 | 4 | 2, 3.5 | 2.875 | 3.5 | 3.5
------+-----+---------------+---------+-------------+---------------
11.5 | -4 | -3, -0.5 | -2.875 | -0.5 | 3.5
------+-----+---------------+---------+-------------+---------------
-11.5 | 4 | -3, 0.5 | -2.875 | 0.5 | -3.5
------+-----+---------------+---------+-------------+---------------
-11.5 | -4 | 2, -3.5 | 2.875 | -3.5 | -3.5
Examples
11.divmod(3) #=> [3, 2]
11.divmod(-3) #=> [-4, -1]
11.divmod(3.5) #=> [3, 0.5]
(-11).divmod(3.5) #=> [-4, 3.0]
(11.5).divmod(3.5) #=> [3, 1.0]
;T;[o;7
;8I"
overload;F;90;;M;:0;;I"divmod(numeric);T;IC;" ;T;[o;<
;8I"return;F;9I" ;T;0;:[I"
Array;T;@;[ ;I"@return [Array];T;0;@;F;=i ;>0;5[[I"numeric;T0;@;[ ;I"aReturns an array containing the quotient and modulus obtained by dividing
+num+ by +numeric+.
If q, r = * x.divmod(y)
, then
q = floor(x/y)
x = q*y+r
The quotient is rounded toward -infinity, as shown in the following table:
a | b | a.divmod(b) | a/b | a.modulo(b) | a.remainder(b)
------+-----+---------------+---------+-------------+---------------
13 | 4 | 3, 1 | 3 | 1 | 1
------+-----+---------------+---------+-------------+---------------
13 | -4 | -4, -3 | -4 | -3 | 1
------+-----+---------------+---------+-------------+---------------
-13 | 4 | -4, 3 | -4 | 3 | -1
------+-----+---------------+---------+-------------+---------------
-13 | -4 | 3, -1 | 3 | -1 | -1
------+-----+---------------+---------+-------------+---------------
11.5 | 4 | 2, 3.5 | 2.875 | 3.5 | 3.5
------+-----+---------------+---------+-------------+---------------
11.5 | -4 | -3, -0.5 | -2.875 | -0.5 | 3.5
------+-----+---------------+---------+-------------+---------------
-11.5 | 4 | -3, 0.5 | -2.875 | 0.5 | -3.5
------+-----+---------------+---------+-------------+---------------
-11.5 | -4 | 2, -3.5 | 2.875 | -3.5 | -3.5
Examples
11.divmod(3) #=> [3, 2]
11.divmod(-3) #=> [-4, -1]
11.divmod(3.5) #=> [3, 0.5]
(-11).divmod(3.5) #=> [-4, 3.0]
(11.5).divmod(3.5) #=> [3, 1.0]
@overload divmod(numeric)
@return [Array];T;0;@;F;o;;T; i;!i;"@;;I"static VALUE;T;AI"lstatic VALUE
num_divmod(VALUE x, VALUE y)
{
return rb_assoc_new(num_div(x, y), num_modulo(x, y));
};T;BTo;1;2F;3;4;;;#I"Numeric#%;F;5[[I"y;T0;[[@
i;
T;;K;0;[ ;{ ;IC;"ox.modulo(y) means x-y*(x/y).floor
Equivalent to num.divmod(numeric)[1]
.
See Numeric#divmod.
;T;[o;7
;8I"
overload;F;90;;L;:0;;I"modulo(numeric);T;IC;" ;T;[ ;[ ;I" ;T;0;@;F;=i ;>0;5[[I"numeric;T0;@;[ ;I" x.modulo(y) means x-y*(x/y).floor
Equivalent to num.divmod(numeric)[1]
.
See Numeric#divmod.
@overload modulo(numeric);T;0;@;F;o;;T; i;!i;"@;;I"static VALUE;T;AI"static VALUE
num_modulo(VALUE x, VALUE y)
{
return rb_funcall(x, '-', 1,
rb_funcall(y, '*', 1,
rb_funcall(x, rb_intern("div"), 1, y)));
};T;BTo;1;2F;3;4;;;#I"Numeric#modulo;F;5[[I"y;T0;[[@
i;
T;;L;0;[ ;{ ;IC;"ox.modulo(y) means x-y*(x/y).floor
Equivalent to num.divmod(numeric)[1]
.
See Numeric#divmod.
;T;[o;7
;8I"
overload;F;90;;L;:0;;I"modulo(numeric);T;IC;" ;T;[ ;[ ;I" ;T;0;@;F;=i ;>0;5[[I"numeric;T0;@;[ ;@;0;@;F;o;;T; i;!i;"@;;I"static VALUE;T;AI"static VALUE
num_modulo(VALUE x, VALUE y)
{
return rb_funcall(x, '-', 1,
rb_funcall(y, '*', 1,
rb_funcall(x, rb_intern("div"), 1, y)));
};T;BTo;1;2F;3;4;;;#I"Numeric#remainder;F;5[[I"y;T0;[[@
i;
T;:remainder;0;[ ;{ ;IC;"Ax.remainder(y) means x-y*(x/y).truncate
See Numeric#divmod.
;T;[o;7
;8I"
overload;F;90;;|;:0;;I"remainder(numeric);T;IC;" ;T;[ ;[ ;I" ;T;0;@;F;=i ;>0;5[[I"numeric;T0;@;[ ;I"c x.remainder(y) means x-y*(x/y).truncate
See Numeric#divmod.
@overload remainder(numeric);T;0;@;F;o;;T; i;!i;"@;;I"static VALUE;T;AI"static VALUE
num_remainder(VALUE x, VALUE y)
{
VALUE z = rb_funcall(x, '%', 1, y);
if ((!rb_equal(z, INT2FIX(0))) &&
((negative_int_p(x) &&
positive_int_p(y)) ||
(positive_int_p(x) &&
negative_int_p(y)))) {
return rb_funcall(z, '-', 1, y);
}
return z;
};T;BTo;1;2F;3;4;;;#I"Numeric#abs;F;5[ ;[[@
i/;
T;;Y;0;[ ;{ ;IC;"Returns the absolute value of +num+.
12.abs #=> 12
(-34.56).abs #=> 34.56
-34.56.abs #=> 34.56
Numeric#magnitude is an alias of Numeric#abs.
;T;[o;7
;8I"
overload;F;90;;Y;:0;;I"abs;T;IC;" ;T;[o;<
;8I"return;F;9I" ;T;0;:[I"Numeric;T;@;[ ;I"@return [Numeric];T;0;@;F;=i ;>0;5[ ;@o;7
;8I"
overload;F;90;;Z;:0;;I"magnitude;T;IC;" ;T;[o;<
;8I"return;F;9I" ;T;0;:[I"Numeric;T;@;[ ;I"@return [Numeric];T;0;@;F;=i ;>0;5[ ;@;[ ;I"Returns the absolute value of +num+.
12.abs #=> 12
(-34.56).abs #=> 34.56
-34.56.abs #=> 34.56
Numeric#magnitude is an alias of Numeric#abs.
@overload abs
@return [Numeric]
@overload magnitude
@return [Numeric];T;0;@;F;o;;T; i!;!i-;"@;;I"static VALUE;T;AI"static VALUE
num_abs(VALUE num)
{
if (negative_int_p(num)) {
return rb_funcall(num, rb_intern("-@"), 0);
}
return num;
};T;BTo;1;2F;3;4;;;#I"Numeric#magnitude;F;5[ ;[[@
i/;
T;;Z;0;[ ;{ ;IC;"Returns the absolute value of +num+.
12.abs #=> 12
(-34.56).abs #=> 34.56
-34.56.abs #=> 34.56
Numeric#magnitude is an alias of Numeric#abs.
;T;[o;7
;8I"
overload;F;90;;Y;:0;;I"abs;T;IC;" ;T;[o;<
;8I"return;F;9I" ;T;0;:[I"Numeric;T;@%;[ ;I"@return [Numeric];T;0;@%;F;=i ;>0;5[ ;@%o;7
;8I"
overload;F;90;;Z;:0;;I"magnitude;T;IC;" ;T;[o;<
;8I"return;F;9I" ;T;0;:[I"Numeric;T;@%;[ ;I"@return [Numeric];T;0;@%;F;=i ;>0;5[ ;@%;[ ;@!;0;@%;F;o;;T; i!;!i-;"@;;I"static VALUE;T;AI"static VALUE
num_abs(VALUE num)
{
if (negative_int_p(num)) {
return rb_funcall(num, rb_intern("-@"), 0);
}
return num;
};T;BTo;1;2F;3;4;;;#I"Numeric#to_int;F;5[ ;[[@
ik;
T;;];0;[ ;{ ;IC;"Invokes the child class's +to_i+ method to convert +num+ to an integer.
1.0.class => Float
1.0.to_int.class => Fixnum
1.0.to_i.class => Fixnum
;T;[o;7
;8I"
overload;F;90;;];:0;;I"to_int;T;IC;" ;T;[o;<
;8I"return;F;9I" ;T;0;:[I"Integer;T;@L;[ ;I"@return [Integer];T;0;@L;F;=i ;>0;5[ ;@L;[ ;I"Invokes the child class's +to_i+ method to convert +num+ to an integer.
1.0.class => Float
1.0.to_int.class => Fixnum
1.0.to_i.class => Fixnum
@overload to_int
@return [Integer];T;0;@L;F;o;;T; i`;!ih;"@;;I"static VALUE;T;AI"Vstatic VALUE
num_to_int(VALUE num)
{
return rb_funcall(num, id_to_i, 0, 0);
};T;BTo;1;2F;3;4;;;#I"Numeric#real?;F;5[ ;[[@
i;
T;:
real?;0;[ ;{ ;IC;"BReturns +true+ if +num+ is a Real number. (i.e. not Complex).
;T;[o;7
;8I"
overload;F;90;;};:0;;I"
real?;T;IC;" ;T;[o;<
;8I"return;F;9I" ;T;0;:[I"Boolean;T;@g;[ ;I"@return [Boolean];T;0;@g;F;=i ;>0;5[ ;@go;<
;8I"return;F;9@f;0;:[@h;@g;[ ;I"hReturns +true+ if +num+ is a Real number. (i.e. not Complex).
@overload real?
@return [Boolean];T;0;@g;F;o;;T; i;!i;"@;;I"static VALUE;T;AI"=static VALUE
num_real_p(VALUE num)
{
return Qtrue;
};T;BTo;1;2F;3;4;;;#I"Numeric#integer?;F;5[ ;[[@
i;
T;:
integer?;0;[ ;{ ;IC;"~Returns +true+ if +num+ is an Integer (including Fixnum and Bignum).
(1.0).integer? #=> false
(1).integer? #=> true
;T;[o;7
;8I"
overload;F;90;;~;:0;;I"
integer?;T;IC;" ;T;[o;<
;8I"return;F;9I" ;T;0;:[I"Boolean;T;@;[ ;I"@return [Boolean];T;0;@;F;=i ;>0;5[ ;@o;<
;8I"return;F;9@f;0;:[@h;@;[ ;I"Returns +true+ if +num+ is an Integer (including Fixnum and Bignum).
(1.0).integer? #=> false
(1).integer? #=> true
@overload integer?
@return [Boolean];T;0;@;F;o;;T; i;!i;"@;;I"static VALUE;T;AI"=static VALUE
num_int_p(VALUE num)
{
return Qfalse;
};T;BTo;1;2F;3;4;;;#I"Numeric#zero?;F;5[ ;[[@
i@;
T;;[;0;[ ;{ ;IC;".Returns +true+ if +num+ has a zero value.
;T;[o;7
;8I"
overload;F;90;;[;:0;;I"
zero?;T;IC;" ;T;[o;<
;8I"return;F;9I" ;T;0;:[I"Boolean;T;@;[ ;I"@return [Boolean];T;0;@;F;=i ;>0;5[ ;@o;<
;8I"return;F;9@f;0;:[@h;@;[ ;I"TReturns +true+ if +num+ has a zero value.
@overload zero?
@return [Boolean];T;0;@;F;o;;T; i9;!i=;"@;;I"static VALUE;T;AI"xstatic VALUE
num_zero_p(VALUE num)
{
if (rb_equal(num, INT2FIX(0))) {
return Qtrue;
}
return Qfalse;
};T;BTo;1;2F;3;4;;;#I"Numeric#nonzero?;F;5[ ;[[@
iW;
T;:
nonzero?;0;[ ;{ ;IC;"Returns +self+ if +num+ is not zero, +nil+ otherwise.
This behavior is useful when chaining comparisons:
a = %w( z Bb bB bb BB a aA Aa AA A )
b = a.sort {|a,b| (a.downcase <=> b.downcase).nonzero? || a <=> b }
b #=> ["A", "a", "AA", "Aa", "aA", "BB", "Bb", "bB", "bb", "z"]
;T;[o;7
;8I"
overload;F;90;;;:0;;I"
nonzero?;T;IC;" ;T;[o;<
;8I"return;F;9I" ;T;0;:[I" self;TI"nil;T;@;[ ;I"@return [self, nil];T;0;@;F;=i ;>0;5[ ;@o;<
;8I"return;F;9@f;0;:[@h;@;[ ;I"IReturns +self+ if +num+ is not zero, +nil+ otherwise.
This behavior is useful when chaining comparisons:
a = %w( z Bb bB bb BB a aA Aa AA A )
b = a.sort {|a,b| (a.downcase <=> b.downcase).nonzero? || a <=> b }
b #=> ["A", "a", "AA", "Aa", "aA", "BB", "Bb", "bB", "bb", "z"]
@overload nonzero?
@return [self, nil];T;0;@;F;o;;T; iJ;!iT;"@;;I"static VALUE;T;AI"static VALUE
num_nonzero_p(VALUE num)
{
if (RTEST(rb_funcall(num, rb_intern("zero?"), 0, 0))) {
return Qnil;
}
return num;
};T;BTo;1;2F;3;4;;;#I"Numeric#floor;F;5[ ;[[@
i;
T;;_;0;[ ;{ ;IC;"Returns the largest integer less than or equal to +num+.
Numeric implements this by converting an Integer to a Float and invoking
Float#floor.
1.floor #=> 1
(-1).floor #=> -1
;T;[o;7
;8I"
overload;F;90;;_;:0;;I"
floor;T;IC;" ;T;[o;<
;8I"return;F;9I" ;T;0;:[I"Integer;T;@;[ ;I"@return [Integer];T;0;@;F;=i ;>0;5[ ;@;[ ;I"Returns the largest integer less than or equal to +num+.
Numeric implements this by converting an Integer to a Float and invoking
Float#floor.
1.floor #=> 1
(-1).floor #=> -1
@overload floor
@return [Integer];T;0;@;F;o;;T; i;!i;"@;;I"static VALUE;T;AI"Ostatic VALUE
num_floor(VALUE num)
{
return flo_floor(rb_Float(num));
};T;BTo;1;2F;3;4;;;#I"Numeric#ceil;F;5[ ;[[@
i;
T;;`;0;[ ;{ ;IC;"Returns the smallest possible Integer that is greater than or equal to
+num+.
Numeric achieves this by converting itself to a Float then invoking
Float#ceil.
1.ceil #=> 1
1.2.ceil #=> 2
(-1.2).ceil #=> -1
(-1.0).ceil #=> -1
;T;[o;7
;8I"
overload;F;90;;`;:0;;I" ceil;T;IC;" ;T;[o;<
;8I"return;F;9I" ;T;0;:[I"Integer;T;@;[ ;I"@return [Integer];T;0;@;F;=i ;>0;5[ ;@;[ ;I""Returns the smallest possible Integer that is greater than or equal to
+num+.
Numeric achieves this by converting itself to a Float then invoking
Float#ceil.
1.ceil #=> 1
1.2.ceil #=> 2
(-1.2).ceil #=> -1
(-1.0).ceil #=> -1
@overload ceil
@return [Integer];T;0;@;F;o;;T; i;!i;"@;;I"static VALUE;T;AI"Mstatic VALUE
num_ceil(VALUE num)
{
return flo_ceil(rb_Float(num));
};T;BTo;1;2F;3;4;;;#I"Numeric#round;F;5[[@0;[[@
i;
T;;a;0;[ ;{ ;IC;"Rounds +num+ 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.
Numeric implements this by converting itself to a Float and invoking
Float#round.
;T;[o;7
;8I"
overload;F;90;;a;:0;;I"round([ndigits]);T;IC;" ;T;[o;<
;8I"return;F;9I" ;T;0;:[I"Integer;TI"
Float;T;@ ;[ ;I"@return [Integer, Float];T;0;@ ;F;=i ;>0;5[[I"[ndigits];T0;@ ;[ ;I"1Rounds +num+ 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.
Numeric implements this by converting itself to a Float and invoking
Float#round.
@overload round([ndigits])
@return [Integer, Float];T;0;@ ;F;o;;T; i;!i;"@;;I"static VALUE;T;AI"rstatic VALUE
num_round(int argc, VALUE* argv, VALUE num)
{
return flo_round(argc, argv, rb_Float(num));
};T;BTo;1;2F;3;4;;;#I"Numeric#truncate;F;5[ ;[[@
i;
T;;^;0;[ ;{ ;IC;"Returns +num+ truncated to an Integer.
Numeric implements this by converting its value to a Float and invoking
Float#truncate.
;T;[o;7
;8I"
overload;F;90;;^;:0;;I"
truncate;T;IC;" ;T;[o;<
;8I"return;F;9I" ;T;0;:[I"Integer;T;@5 ;[ ;I"@return [Integer];T;0;@5 ;F;=i ;>0;5[ ;@5 ;[ ;I"Returns +num+ truncated to an Integer.
Numeric implements this by converting its value to a Float and invoking
Float#truncate.
@overload truncate
@return [Integer];T;0;@5 ;F;o;;T; i;!i;"@;;I"static VALUE;T;AI"Ustatic VALUE
num_truncate(VALUE num)
{
return flo_truncate(rb_Float(num));
};T;BTo;1;2F;3;4;;;#I"Numeric#step;F;5[[@0;[[@
i;
T;: step;0;[ ;{ ;IC;"Invokes the given block with the sequence of numbers starting at +num+,
incremented by +step+ (defaulted to +1+) on each call.
The loop finishes when the value to be passed to the block is greater than
+limit+ (if +step+ is positive) or less than +limit+ (if +step+ is
negative), where limit is defaulted to infinity.
In the recommended keyword argument style, either or both of
+step+ and +limit+ (default infinity) can be omitted. In the
fixed position argument style, integer zero as a step
(i.e. num.step(limit, 0)) is not allowed for historical
compatibility reasons.
If all the arguments are integers, the loop operates using an integer
counter.
If any of the arguments are floating point numbers, all are converted to floats, and the loop is executed the following expression:
floor(n + n*epsilon)+ 1
Where the +n+ is the following:
n = (limit - num)/step
Otherwise, the loop starts at +num+, uses either the less-than (<) or
greater-than (>) operator to compare the counter against +limit+, and
increments itself using the +
operator.
If no block is given, an Enumerator is returned instead.
For example:
p 1.step.take(4)
p 10.step(by: -1).take(4)
3.step(to: 5) { |i| print i, " " }
1.step(10, 2) { |i| print i, " " }
Math::E.step(to: Math::PI, by: 0.2) { |f| print f, " " }
Will produce:
[1, 2, 3, 4]
[10, 9, 8, 7]
3 4 5
1 3 5 7 9
2.71828182845905 2.91828182845905 3.11828182845905
;T;[ o;7
;8I"
overload;F;90;;{;:0;;I"step(by: step, to: limit]);T;IC;" ;T;[o;<
;8I"
yield;F;9I" ;T;0;:[I"i;T;@P o;<
;8I"return;F;9I" ;T;0;:[I" self;T;@P ;[ ;I"@yield [i]
@return [self];T;0;@P ;F;=i ;>0;5[[I"by:;TI" step;T[I"to:;TI"limit];T;@P o;7
;8I"
overload;F;90;;{;:0;;I"step(by: step, to: limit]);T;IC;" ;T;[ ;[ ;I" ;T;0;@P ;F;=i ;>0;5[[I"by:;TI" step;T[I"to:;TI"limit];T;@P o;7
;8I"
overload;F;90;;{;:0;;I"step(limit=nil, step=1);T;IC;" ;T;[o;<
;8I"
yield;F;9I" ;T;0;:[I"i;T;@P o;<
;8I"return;F;9I" ;T;0;:[I" self;T;@P ;[ ;I"@yield [i]
@return [self];T;0;@P ;F;=i ;>0;5[[I"
limit;TI"nil;T[I" step;TI"1;T;@P o;7
;8I"
overload;F;90;;{;:0;;I"step(limit=nil, step=1);T;IC;" ;T;[ ;[ ;I" ;T;0;@P ;F;=i ;>0;5[[I"
limit;TI"nil;T[I" step;TI"1;T;@P ;[ ;I"zInvokes the given block with the sequence of numbers starting at +num+,
incremented by +step+ (defaulted to +1+) on each call.
The loop finishes when the value to be passed to the block is greater than
+limit+ (if +step+ is positive) or less than +limit+ (if +step+ is
negative), where limit is defaulted to infinity.
In the recommended keyword argument style, either or both of
+step+ and +limit+ (default infinity) can be omitted. In the
fixed position argument style, integer zero as a step
(i.e. num.step(limit, 0)) is not allowed for historical
compatibility reasons.
If all the arguments are integers, the loop operates using an integer
counter.
If any of the arguments are floating point numbers, all are converted to floats, and the loop is executed the following expression:
floor(n + n*epsilon)+ 1
Where the +n+ is the following:
n = (limit - num)/step
Otherwise, the loop starts at +num+, uses either the less-than (<) or
greater-than (>) operator to compare the counter against +limit+, and
increments itself using the +
operator.
If no block is given, an Enumerator is returned instead.
For example:
p 1.step.take(4)
p 10.step(by: -1).take(4)
3.step(to: 5) { |i| print i, " " }
1.step(10, 2) { |i| print i, " " }
Math::E.step(to: Math::PI, by: 0.2) { |f| print f, " " }
Will produce:
[1, 2, 3, 4]
[10, 9, 8, 7]
3 4 5
1 3 5 7 9
2.71828182845905 2.91828182845905 3.11828182845905
@overload step(by: step, to: limit])
@yield [i]
@return [self]
@overload step(by: step, to: limit])
@overload step(limit=nil, step=1)
@yield [i]
@return [self]
@overload step(limit=nil, step=1);T;0;@P ;F;o;;T; i;!i;"@;;I"static VALUE;T;AI"{static VALUE
num_step(int argc, VALUE *argv, VALUE from)
{
VALUE to, step;
int desc, inf;
RETURN_SIZED_ENUMERATOR(from, argc, argv, num_step_size);
desc = num_step_scan_args(argc, argv, &to, &step);
if (RTEST(rb_num_coerce_cmp(step, INT2FIX(0), id_eq))) {
inf = 1;
}
else if (RB_TYPE_P(to, T_FLOAT)) {
double f = RFLOAT_VALUE(to);
inf = isinf(f) && (signbit(f) ? desc : !desc);
}
else inf = 0;
if (FIXNUM_P(from) && (inf || FIXNUM_P(to)) && FIXNUM_P(step)) {
long i = FIX2LONG(from);
long diff = FIX2LONG(step);
if (inf) {
for (;; i += diff)
rb_yield(LONG2FIX(i));
}
else {
long end = FIX2LONG(to);
if (desc) {
for (; i >= end; i += diff)
rb_yield(LONG2FIX(i));
}
else {
for (; i <= end; i += diff)
rb_yield(LONG2FIX(i));
}
}
}
else if (!ruby_float_step(from, to, step, FALSE)) {
VALUE i = from;
if (inf) {
for (;; i = rb_funcall(i, '+', 1, step))
rb_yield(i);
}
else {
ID cmp = desc ? '<' : '>';
for (; !RTEST(rb_funcall(i, cmp, 1, to)); i = rb_funcall(i, '+', 1, step))
rb_yield(i);
}
}
return from;
};T;BTo;1;2F;3;4;;;#I"Numeric#to_c;F;5[ ;[[@ei;
T;: to_c;0;[ ;{ ;IC;"$Returns the value as a complex.
;T;[o;7
;8I"
overload;F;90;;|;:0;;I" to_c;T;IC;" ;T;[ ;[ ;I" ;T;0;@ ;F;=i ;>0;5[ ;@ ;[ ;I"5Returns the value as a complex.
@overload to_c;T;0;@ ;F;o;;T; i;!i;"@;;I"static VALUE;T;AI"Pstatic VALUE
numeric_to_c(VALUE self)
{
return rb_complex_new1(self);
};T;BTo;1;2F;3;4;;;#I"Numeric#real;F;5[ ;[[@eix;
T;: real;0;[ ;{ ;IC;"Returns self.
;T;[o;7
;8I"
overload;F;90;;};:0;;I" real;T;IC;" ;T;[o;<
;8I"return;F;9I" ;T;0;:[I" self;T;@ ;[ ;I"@return [self];T;0;@ ;F;=i ;>0;5[ ;@ ;[ ;I"4Returns self.
@overload real
@return [self];T;0;@ ;F;o;;T; ir;!iv;"@;;I"static VALUE;T;AI"?static VALUE
numeric_real(VALUE self)
{
return self;
};T;BTo;1;2F;3;4;;;#I"Numeric#imaginary;F;5[ ;[[@ei;
T;:imaginary;0;[ ;{ ;IC;"Returns zero.
;T;[o;7
;8I"
overload;F;90;: imag;:0;;I" imag;T;IC;" ;T;[o;<
;8I"return;F;9I" ;T;0;:[I"0;T;@ ;[ ;I"@return [ 0];T;0;@ ;F;=i ;>0;5[ ;@ o;7
;8I"
overload;F;90;;~;:0;;I"imaginary;T;IC;" ;T;[o;<
;8I"return;F;9I" ;T;0;:[I"0;T;@ ;[ ;I"@return [ 0];T;0;@ ;F;=i ;>0;5[ ;@ ;[ ;I"UReturns zero.
@overload imag
@return [ 0]
@overload imaginary
@return [ 0];T;0;@ ;F;o;;T; i~;!i;"@;;I"static VALUE;T;AI"Estatic VALUE
numeric_imag(VALUE self)
{
return INT2FIX(0);
};T;BTo;1;2F;3;4;;;#I"Numeric#imag;F;5[ ;[[@ei;
T;;;0;[ ;{ ;IC;"Returns zero.
;T;[o;7
;8I"
overload;F;90;;;:0;;I" imag;T;IC;" ;T;[o;<
;8I"return;F;9I" ;T;0;:[I"0;T;@
;[ ;I"@return [ 0];T;0;@
;F;=i ;>0;5[ ;@
o;7
;8I"
overload;F;90;;~;:0;;I"imaginary;T;IC;" ;T;[o;<
;8I"return;F;9I" ;T;0;:[I"0;T;@
;[ ;I"@return [ 0];T;0;@
;F;=i ;>0;5[ ;@
;[ ;@
;0;@
;F;o;;T; i~;!i;"@;;I"static VALUE;T;AI"Estatic VALUE
numeric_imag(VALUE self)
{
return INT2FIX(0);
};T;BTo;1;2F;3;4;;;#I"Numeric#abs2;F;5[ ;[[@ei;
T;: abs2;0;[ ;{ ;IC;"Returns square of self.
;T;[o;7
;8I"
overload;F;90;;;:0;;I" abs2;T;IC;" ;T;[ ;[ ;I" ;T;0;@+
;F;=i ;>0;5[ ;@+
;[ ;I"-Returns square of self.
@overload abs2;T;0;@+
;F;o;;T; i;!i;"@;;I"static VALUE;T;AI"Lstatic VALUE
numeric_abs2(VALUE self)
{
return f_mul(self, self);
};T;BTo;1;2F;3;4;;;#I"Numeric#arg;F;5[ ;[[@ei;
T;;e;0;[ ;{ ;IC;"6Returns 0 if the value is positive, pi otherwise.
;T;[o;7
;8I"
overload;F;90;;e;:0;;I"arg;T;IC;" ;T;[o;<
;8I"return;F;9I" ;T;0;:[I"0;TI"
Float;T;@A
;[ ;I"@return [ 0, Float];T;0;@A
;F;=i ;>0;5[ ;@A
o;7
;8I"
overload;F;90;;f;:0;;I"
angle;T;IC;" ;T;[o;<
;8I"return;F;9I" ;T;0;:[I"0;TI"
Float;T;@A
;[ ;I"@return [ 0, Float];T;0;@A
;F;=i ;>0;5[ ;@A
o;7
;8I"
overload;F;90;;g;:0;;I"
phase;T;IC;" ;T;[o;<
;8I"return;F;9I" ;T;0;:[I"0;TI"
Float;T;@A
;[ ;I"@return [ 0, Float];T;0;@A
;F;=i ;>0;5[ ;@A
;[ ;I"Returns 0 if the value is positive, pi otherwise.
@overload arg
@return [ 0, Float]
@overload angle
@return [ 0, Float]
@overload phase
@return [ 0, Float];T;0;@A
;F;o;;T; i;!i;"@;;I"static VALUE;T;AI"static VALUE
numeric_arg(VALUE self)
{
if (f_positive_p(self))
return INT2FIX(0);
return rb_const_get(rb_mMath, id_PI);
};T;BTo;1;2F;3;4;;;#I"Numeric#angle;F;5[ ;[[@ei;
T;;f;0;[ ;{ ;IC;"6Returns 0 if the value is positive, pi otherwise.
;T;[o;7
;8I"
overload;F;90;;e;:0;;I"arg;T;IC;" ;T;[o;<
;8I"return;F;9I" ;T;0;:[I"0;TI"
Float;T;@y
;[ ;I"@return [ 0, Float];T;0;@y
;F;=i ;>0;5[ ;@y
o;7
;8I"
overload;F;90;;f;:0;;I"
angle;T;IC;" ;T;[o;<
;8I"return;F;9I" ;T;0;:[I"0;TI"
Float;T;@y
;[ ;I"@return [ 0, Float];T;0;@y
;F;=i ;>0;5[ ;@y
o;7
;8I"
overload;F;90;;g;:0;;I"
phase;T;IC;" ;T;[o;<
;8I"return;F;9I" ;T;0;:[I"0;TI"
Float;T;@y
;[ ;I"@return [ 0, Float];T;0;@y
;F;=i ;>0;5[ ;@y
;[ ;@u
;0;@y
;F;o;;T; i;!i;"@;;I"static VALUE;T;AI"static VALUE
numeric_arg(VALUE self)
{
if (f_positive_p(self))
return INT2FIX(0);
return rb_const_get(rb_mMath, id_PI);
};T;BTo;1;2F;3;4;;;#I"Numeric#phase;F;5[ ;[[@ei;
T;;g;0;[ ;{ ;IC;"6Returns 0 if the value is positive, pi otherwise.
;T;[o;7
;8I"
overload;F;90;;e;:0;;I"arg;T;IC;" ;T;[o;<
;8I"return;F;9I" ;T;0;:[I"0;TI"
Float;T;@
;[ ;I"@return [ 0, Float];T;0;@
;F;=i ;>0;5[ ;@
o;7
;8I"
overload;F;90;;f;:0;;I"
angle;T;IC;" ;T;[o;<
;8I"return;F;9I" ;T;0;:[I"0;TI"
Float;T;@
;[ ;I"@return [ 0, Float];T;0;@
;F;=i ;>0;5[ ;@
o;7
;8I"
overload;F;90;;g;:0;;I"
phase;T;IC;" ;T;[o;<
;8I"return;F;9I" ;T;0;:[I"0;TI"
Float;T;@
;[ ;I"@return [ 0, Float];T;0;@
;F;=i ;>0;5[ ;@
;[ ;@u
;0;@
;F;o;;T; i;!i;"@;;I"static VALUE;T;AI"static VALUE
numeric_arg(VALUE self)
{
if (f_positive_p(self))
return INT2FIX(0);
return rb_const_get(rb_mMath, id_PI);
};T;BTo;1;2F;3;4;;;#I"Numeric#rectangular;F;5[ ;[[@ei;
T;:rectangular;0;[ ;{ ;IC;" Returns an array; [num, 0].
;T;[o;7
;8I"
overload;F;90;: rect;:0;;I" rect;T;IC;" ;T;[o;<
;8I"return;F;9I" ;T;0;:[I"
Array;T;@
;[ ;I"@return [Array];T;0;@
;F;=i ;>0;5[ ;@
o;7
;8I"
overload;F;90;;;:0;;I"rectangular;T;IC;" ;T;[o;<
;8I"return;F;9I" ;T;0;:[I"
Array;T;@
;[ ;I"@return [Array];T;0;@
;F;=i ;>0;5[ ;@
;[ ;I"kReturns an array; [num, 0].
@overload rect
@return [Array]
@overload rectangular
@return [Array];T;0;@
;F;o;;T; i;!i;"@;;I"static VALUE;T;AI"Ystatic VALUE
numeric_rect(VALUE self)
{
return rb_assoc_new(self, INT2FIX(0));
};T;BTo;1;2F;3;4;;;#I"Numeric#rect;F;5[ ;[[@ei;
T;;;0;[ ;{ ;IC;" Returns an array; [num, 0].
;T;[o;7
;8I"
overload;F;90;;;:0;;I" rect;T;IC;" ;T;[o;<
;8I"return;F;9I" ;T;0;:[I"
Array;T;@;[ ;I"@return [Array];T;0;@;F;=i ;>0;5[ ;@o;7
;8I"
overload;F;90;;;:0;;I"rectangular;T;IC;" ;T;[o;<
;8I"return;F;9I" ;T;0;:[I"
Array;T;@;[ ;I"@return [Array];T;0;@;F;=i ;>0;5[ ;@;[ ;@;0;@;F;o;;T; i;!i;"@;;I"static VALUE;T;AI"Ystatic VALUE
numeric_rect(VALUE self)
{
return rb_assoc_new(self, INT2FIX(0));
};T;BTo;1;2F;3;4;;;#I"Numeric#polar;F;5[ ;[[@ei;
T;:
polar;0;[ ;{ ;IC;"*Returns an array; [num.abs, num.arg].
;T;[o;7
;8I"
overload;F;90;;;:0;;I"
polar;T;IC;" ;T;[o;<
;8I"return;F;9I" ;T;0;:[I"
Array;T;@6;[ ;I"@return [Array];T;0;@6;F;=i ;>0;5[ ;@6;[ ;I"NReturns an array; [num.abs, num.arg].
@overload polar
@return [Array];T;0;@6;F;o;;T; i;!i;"@;;I"static VALUE;T;AI"bstatic VALUE
numeric_polar(VALUE self)
{
return rb_assoc_new(f_abs(self), f_arg(self));
};T;BTo;1;2F;3;4;;;#I"Numeric#conjugate;F;5[ ;[[@ei;
T;:conjugate;0;[ ;{ ;IC;"Returns self.
;T;[o;7
;8I"
overload;F;90;: conj;:0;;I" conj;T;IC;" ;T;[o;<
;8I"return;F;9I" ;T;0;:[I" self;T;@Q;[ ;I"@return [self];T;0;@Q;F;=i ;>0;5[ ;@Qo;7
;8I"
overload;F;90;;;:0;;I"conjugate;T;IC;" ;T;[o;<
;8I"return;F;9I" ;T;0;:[I" self;T;@Q;[ ;I"@return [self];T;0;@Q;F;=i ;>0;5[ ;@Q;[ ;I"YReturns self.
@overload conj
@return [self]
@overload conjugate
@return [self];T;0;@Q;F;o;;T; i;!i;"@;;I"static VALUE;T;AI"?static VALUE
numeric_conj(VALUE self)
{
return self;
};T;BTo;1;2F;3;4;;;#I"Numeric#conj;F;5[ ;[[@ei;
T;;;0;[ ;{ ;IC;"Returns self.
;T;[o;7
;8I"
overload;F;90;;;:0;;I" conj;T;IC;" ;T;[o;<
;8I"return;F;9I" ;T;0;:[I" self;T;@y;[ ;I"@return [self];T;0;@y;F;=i ;>0;5[ ;@yo;7
;8I"
overload;F;90;;;:0;;I"conjugate;T;IC;" ;T;[o;<
;8I"return;F;9I" ;T;0;:[I" self;T;@y;[ ;I"@return [self];T;0;@y;F;=i ;>0;5[ ;@y;[ ;@u;0;@y;F;o;;T; i;!i;"@;;I"static VALUE;T;AI"?static VALUE
numeric_conj(VALUE self)
{
return self;
};T;BTo;1;2F;3;4;;;#I"Numeric#numerator;F;5[ ;[[@i;
T;;h;0;[ ;{ ;IC;"Returns the numerator.
;T;[o;7
;8I"
overload;F;90;;h;:0;;I"numerator;T;IC;" ;T;[o;<
;8I"return;F;9I" ;T;0;:[I"Integer;T;@;[ ;I"@return [Integer];T;0;@;F;=i ;>0;5[ ;@;[ ;I"EReturns the numerator.
@overload numerator
@return [Integer];T;0;@;F;o;;T; i;!i;"@;;I"static VALUE;T;AI"Ystatic VALUE
numeric_numerator(VALUE self)
{
return f_numerator(f_to_r(self));
};T;BTo;1;2F;3;4;;;#I"Numeric#denominator;F;5[ ;[[@i
;
T;;i;0;[ ;{ ;IC;"/Returns the denominator (always positive).
;T;[o;7
;8I"
overload;F;90;;i;:0;;I"denominator;T;IC;" ;T;[o;<
;8I"return;F;9I" ;T;0;:[I"Integer;T;@;[ ;I"@return [Integer];T;0;@;F;=i ;>0;5[ ;@;[ ;I"[Returns the denominator (always positive).
@overload denominator
@return [Integer];T;0;@;F;o;;T; i;!i;"@;;I"static VALUE;T;AI"]static VALUE
numeric_denominator(VALUE self)
{
return f_denominator(f_to_r(self));
};T;BTo;1;2F;3;4;;;#I"Numeric#quo;F;5[[I"y;T0;[[@i;
T;;I;0;[ ;{ ;IC;"KReturns most exact division (rational for integers, float for floats).
;T;[o;7
;8I"
overload;F;90;;I;:0;;I"quo(int_or_rat);T;IC;" ;T;[ ;[ ;I" ;T;0;@;F;=i ;>0;5[[I"int_or_rat;T0;@o;7
;8I"
overload;F;90;;I;:0;;I"
quo(flo);T;IC;" ;T;[ ;[ ;I" ;T;0;@;F;=i ;>0;5[[I"flo;T0;@;[ ;I"zReturns most exact division (rational for integers, float for floats).
@overload quo(int_or_rat)
@overload quo(flo);T;0;@;F;o;;T; i;!i;"@;;I"static VALUE;T;AI"Dstatic VALUE
numeric_quo(VALUE x, VALUE y)
{
if (RB_TYPE_P(y, T_FLOAT)) {
return f_fdiv(x, y);
}
#ifdef CANON
if (canonicalization) {
x = rb_rational_raw1(x);
}
else
#endif
{
x = rb_convert_type(x, T_RATIONAL, "Rational", "to_r");
}
return rb_funcall(x, '/', 1, y);
};T;BT;l@;mIC;[ ;l@;nIC;[o:YARD::CodeObjects::Proxy:@orignamespace0:@origname0:
@imethod0;:Comparable;"@: @objo:$YARD::CodeObjects::ModuleObject;IC;[o;1;2F;3;4;;;#I"Comparable#==;F;5[[I"y;T0;[[I"
compar.c;Ti^;
T;;O;0;[ ;{ ;IC;"Compares two objects based on the receiver's <=>
method, returning true if it returns 0. Also returns true if
_obj_ and _other_ are the same object.
Even if _obj_ <=> _other_ raised an exception, the exception
is ignored and returns false.
;T;[o;7
;8I"
overload;F;90;;O;:0;;I"==(other);T;IC;" ;T;[o;<
;8I"return;F;9I" ;T;0;:[I"Boolean;T;@;[ ;I"@return [Boolean];T;0;@;F;=i ;>0;5[[I"
other;T0;@;[ ;I"'Compares two objects based on the receiver's <=>
method, returning true if it returns 0. Also returns true if
_obj_ and _other_ are the same object.
Even if _obj_ <=> _other_ raised an exception, the exception
is ignored and returns false.
@overload ==(other)
@return [Boolean];T;0;@;F;o;;T; iR;!i[;"@;;I"static VALUE;T;AI"static VALUE
cmp_equal(VALUE x, VALUE y)
{
VALUE a[2];
if (x == y) return Qtrue;
a[0] = x; a[1] = y;
return rb_rescue(cmp_eq, (VALUE)a, cmp_failed, 0);
};T;BTo;1;2F;3;4;;;#I"Comparable#>;F;5[[I"y;T0;[[@iq;
T;;R;0;[ ;{ ;IC;"jCompares two objects based on the receiver's <=>
method, returning true if it returns 1.
;T;[o;7
;8I"
overload;F;90;;R;:0;;I"
>(other);T;IC;" ;T;[o;<
;8I"return;F;9I" ;T;0;:[I"Boolean;T;@;[ ;I"@return [Boolean];T;0;@;F;=i ;>0;5[[I"
other;T0;@;[ ;I"Compares two objects based on the receiver's <=>
method, returning true if it returns 1.
@overload >(other)
@return [Boolean];T;0;@;F;o;;T; ii;!in;"@;;I"static VALUE;T;AI"static VALUE
cmp_gt(VALUE x, VALUE y)
{
VALUE c = rb_funcall(x, cmp, 1, y);
if (rb_cmpint(c, x, y) > 0) return Qtrue;
return Qfalse;
};T;BTo;1;2F;3;4;;;#I"Comparable#>=;F;5[[I"y;T0;[[@i};
T;;S;0;[ ;{ ;IC;"oCompares two objects based on the receiver's <=>
method, returning true if it returns 0 or 1.
;T;[o;7
;8I"
overload;F;90;;S;:0;;I">=(other);T;IC;" ;T;[o;<
;8I"return;F;9I" ;T;0;:[I"Boolean;T;@>;[ ;I"@return [Boolean];T;0;@>;F;=i ;>0;5[[I"
other;T0;@>;[ ;I"Compares two objects based on the receiver's <=>
method, returning true if it returns 0 or 1.
@overload >=(other)
@return [Boolean];T;0;@>;F;o;;T; iz;!i;"@;;I"static VALUE;T;AI"static VALUE
cmp_ge(VALUE x, VALUE y)
{
VALUE c = rb_funcall(x, cmp, 1, y);
if (rb_cmpint(c, x, y) >= 0) return Qtrue;
return Qfalse;
};T;BTo;1;2F;3;4;;;#I"Comparable#<;F;5[[I"y;T0;[[@i;
T;;T;0;[ ;{ ;IC;"kCompares two objects based on the receiver's <=>
method, returning true if it returns -1.
;T;[o;7
;8I"
overload;F;90;;T;:0;;I"
<(other);T;IC;" ;T;[o;<
;8I"return;F;9I" ;T;0;:[I"Boolean;T;@];[ ;I"@return [Boolean];T;0;@];F;=i ;>0;5[[I"
other;T0;@];[ ;I"Compares two objects based on the receiver's <=>
method, returning true if it returns -1.
@overload <(other)
@return [Boolean];T;0;@];F;o;;T; i;!i;"@;;I"static VALUE;T;AI"static VALUE
cmp_lt(VALUE x, VALUE y)
{
VALUE c = rb_funcall(x, cmp, 1, y);
if (rb_cmpint(c, x, y) < 0) return Qtrue;
return Qfalse;
};T;BTo;1;2F;3;4;;;#I"Comparable#<=;F;5[[I"y;T0;[[@i;
T;;U;0;[ ;{ ;IC;"pCompares two objects based on the receiver's <=>
method, returning true if it returns -1 or 0.
;T;[o;7
;8I"
overload;F;90;;U;:0;;I"<=(other);T;IC;" ;T;[o;<
;8I"return;F;9I" ;T;0;:[I"Boolean;T;@|;[ ;I"@return [Boolean];T;0;@|;F;=i ;>0;5[[I"
other;T0;@|;[ ;I"Compares two objects based on the receiver's <=>
method, returning true if it returns -1 or 0.
@overload <=(other)
@return [Boolean];T;0;@|;F;o;;T; i;!i;"@;;I"static VALUE;T;AI"static VALUE
cmp_le(VALUE x, VALUE y)
{
VALUE c = rb_funcall(x, cmp, 1, y);
if (rb_cmpint(c, x, y) <= 0) return Qtrue;
return Qfalse;
};T;BTo;1;2F;3;4;;;#I"Comparable#between?;F;5[[I"min;T0[I"max;T0;[[@i;
T;:
between?;0;[ ;{ ;IC;"jReturns false
if obj <=>
min is less than zero or if anObject <=>
max is greater than zero, true
otherwise.
3.between?(1, 5) #=> true
6.between?(1, 5) #=> false
'cat'.between?('ant', 'dog') #=> true
'gnu'.between?('ant', 'dog') #=> false
;T;[o;7
;8I"
overload;F;90;;;:0;;I"between?(min, max);T;IC;" ;T;[o;<
;8I"return;F;9I" ;T;0;:[I"Boolean;T;@;[ ;I"@return [Boolean];T;0;@;F;=i ;>0;5[[I"min;T0[I"max;T0;@o;<
;8I"return;F;9@f;0;:[@h;@;[ ;I"Returns false
if obj <=>
min is less than zero or if anObject <=>
max is greater than zero, true
otherwise.
3.between?(1, 5) #=> true
6.between?(1, 5) #=> false
'cat'.between?('ant', 'dog') #=> true
'gnu'.between?('ant', 'dog') #=> false
@overload between?(min, max)
@return [Boolean];T;0;@;F;o;;T; i;!i;"@;;I"static VALUE;T;AI"static VALUE
cmp_between(VALUE x, VALUE min, VALUE max)
{
if (RTEST(cmp_lt(x, min))) return Qfalse;
if (RTEST(cmp_gt(x, max))) return Qfalse;
return Qtrue;
};T;BT;l@;mIC;[ ;l@;nIC;[ ;l@;oIC;p{;qIC;p{ ;rT;4IC;p{ ;rT;rT;s{ ;t[ ;[[@i;
F;;;;@;;;[ ;{ ;IC;"The Comparable
mixin is used by classes whose objects
may be ordered. The class must define the <=>
operator,
which compares the receiver against another object, returning -1, 0,
or +1 depending on whether the receiver is less than, equal to, or
greater than the other object. If the other object is not comparable
then the <=>
operator should return nil.
Comparable
uses
<=>
to implement the conventional comparison operators
(<
, <=
, ==
, >=
,
and >
) and the method between?
.
class SizeMatters
include Comparable
attr :str
def <=>(anOther)
str.size <=> anOther.str.size
end
def initialize(str)
@str = str
end
def inspect
@str
end
end
s1 = SizeMatters.new("Z")
s2 = SizeMatters.new("YY")
s3 = SizeMatters.new("XXX")
s4 = SizeMatters.new("WWWW")
s5 = SizeMatters.new("VVVVV")
s1 < s2 #=> true
s4.between?(s1, s3) #=> false
s4.between?(s3, s5) #=> true
[ s3, s2, s5, s4, s1 ].sort #=> [Z, YY, XXX, WWWW, VVVVV]
;T;[ ;[ ;I"The Comparable
mixin is used by classes whose objects
may be ordered. The class must define the <=>
operator,
which compares the receiver against another object, returning -1, 0,
or +1 depending on whether the receiver is less than, equal to, or
greater than the other object. If the other object is not comparable
then the <=>
operator should return nil.
Comparable
uses
<=>
to implement the conventional comparison operators
(<
, <=
, ==
, >=
,
and >
) and the method between?
.
class SizeMatters
include Comparable
attr :str
def <=>(anOther)
str.size <=> anOther.str.size
end
def initialize(str)
@str = str
end
def inspect
@str
end
end
s1 = SizeMatters.new("Z")
s2 = SizeMatters.new("YY")
s3 = SizeMatters.new("XXX")
s4 = SizeMatters.new("WWWW")
s5 = SizeMatters.new("VVVVV")
s1 < s2 #=> true
s4.between?(s1, s3) #=> false
s4.between?(s3, s5) #=> true
[ s3, s2, s5, s4, s1 ].sort #=> [Z, YY, XXX, WWWW, VVVVV]
;T;0;@;F;o;;T; i;!i;"@;#I"Comparable;F:
@type0;l@;oIC;p{;qIC;p{ ;rT;4IC;p{ ;rT;rT;s{ ;t[ ;[[@
i';
F;:Numeric;;@;;;[ ;{ ;IC;" The top-level number class.;T;[ ;[ ;I"!The top-level number class.
;T;0;@;F;o;;T; i;!i;=i ;"@;#I"Numeric;F;vo;;0;0;0;:Object;"@;o; ;IC;[?o;1;2F;3;4;;;#I"Object#rb_fatal;F;5[[I"msg;T0;[[I" ext/-test-/fatal/rb_fatal.c;Ti;
T;:
rb_fatal;0;[ ;{ ;IC;" ;T;[ ;[ ;@f;0;@;"@;;I"static VALUE;T;AI"static VALUE
ruby_fatal(VALUE obj, VALUE msg)
{
const char *cmsg = NULL;
(void)obj;
cmsg = RSTRING_PTR(msg);
rb_fatal("%s", cmsg);
return 0; /* never reached */
};T;BTo;
;[[I"7ext/-test-/wait_for_single_fd/wait_for_single_fd.c;Ti;
F;:RB_WAITFD_IN;;;;;[ ;{ ;IC;" ;T;[ ;[ ;@f;0;@;"@;#I"Object::RB_WAITFD_IN;F;$I"INT2NUM(RB_WAITFD_IN);To;
;[[@i;
F;:RB_WAITFD_OUT;;;;;[ ;{ ;IC;" ;T;[ ;[ ;@f;0;@;"@;#I"Object::RB_WAITFD_OUT;F;$I"INT2NUM(RB_WAITFD_OUT);To;
;[[@i ;
F;:RB_WAITFD_PRI;;;;;[ ;{ ;IC;" ;T;[ ;[ ;@f;0;@
;"@;#I"Object::RB_WAITFD_PRI;F;$I"INT2NUM(RB_WAITFD_PRI);To;1;2F;3;4;;;#I"Object#assert_Qundef;F;5[[I"obj;T0[I"msg;T0;[[I"parse.y;Ti]-[I"parse.c;TiF[I"ext/ripper/ripper.c;Ti$G;
T;:assert_Qundef;0;[ ;{ ;IC;":nodoc:
;T;[ ;[ ;I":nodoc:;T;0;@
;F;o;;T; i#G;!i#G;"@;;I"static VALUE;T;AI"static VALUE
ripper_assert_Qundef(VALUE self, VALUE obj, VALUE msg)
{
StringValue(msg);
if (obj == Qundef) {
rb_raise(rb_eArgError, "%"PRIsVALUE, msg);
}
return Qnil;
};T;BTo;1;2F;3;4;;;#I"Object#rawVALUE;F;5[[I"obj;T0;[[@
ih-[@
iF[@
i/G;
T;:
rawVALUE;0;[ ;{ ;IC;":nodoc:
;T;[ ;[ ;I":nodoc:;T;0;@)
;F;o;;T; i.G;!i.G;"@;;I"static VALUE;T;AI"Tstatic VALUE
ripper_value(VALUE self, VALUE obj)
{
return ULONG2NUM(obj);
};T;BTo;1;2F;3;4;;;#I"Object#validate_object;F;5[[I"x;T0;[[@
i+[@
iE[@
ihE;
T;:validate_object;0;[ ;{ ;IC;":nodoc:
;T;[ ;[ ;I":nodoc:;T;0;@;
;F;o;;T; igE;!igE;"@;;I"static VALUE;T;AI"Tstatic VALUE
ripper_validate_object(VALUE self, VALUE x)
{
if (x == Qfalse) return x;
if (x == Qtrue) return x;
if (x == Qnil) return x;
if (x == Qundef)
rb_raise(rb_eArgError, "Qundef given");
if (FIXNUM_P(x)) return x;
if (SYMBOL_P(x)) return x;
if (!rb_is_pointer_to_heap(x))
rb_raise(rb_eArgError, "invalid pointer: %p", x);
switch (BUILTIN_TYPE(x)) {
case T_STRING:
case T_OBJECT:
case T_ARRAY:
case T_BIGNUM:
case T_FLOAT:
case T_COMPLEX:
case T_RATIONAL:
return x;
case T_NODE:
if (nd_type(x) != NODE_LASGN) {
rb_raise(rb_eArgError, "NODE given: %p", x);
}
return ((NODE *)x)->nd_rval;
default:
rb_raise(rb_eArgError, "wrong type of ruby object: %p (%s)",
x, rb_obj_classname(x));
}
return x;
};T;BTo;1;2F;3;4;;;#I"Object#nil?;F;5[ ;[[I"
object.c;Tic;
T;: nil?;0;[ ;{ ;IC;"Only the object nil responds true
to nil?
.
Object.new.nil? #=> false
nil.nil? #=> true
;T;[o;7
;8I"
overload;F;90;;;:0;;I" nil?;T;IC;" ;T;[o;<
;8I"return;F;9I" ;T;0;:[I"Boolean;T;@M
;[ ;I"@return [Boolean];T;0;@M
;F;=i ;>0;5[ ;@M
o;<
;8I"return;F;9@f;0;:[@h;@M
;[ ;I"Only the object nil responds true
to nil?
.
Object.new.nil? #=> false
nil.nil? #=> true
@overload nil?
@return [Boolean];T;0;@M
;F;o;;T; iX;!i_;"@;;I"static VALUE;T;AI"