mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
This commit is contained in:
parent
97cf290063
commit
fad7908a5d
Notes:
git
2021-02-09 13:30:07 +09:00
Merged-By: k0kubun <takashikkbn@gmail.com>
3 changed files with 30 additions and 30 deletions
8
benchmark/float_neg_posi.yml
Normal file
8
benchmark/float_neg_posi.yml
Normal file
|
@ -0,0 +1,8 @@
|
|||
prelude: |
|
||||
flo = 4.2
|
||||
benchmark:
|
||||
negative?: |
|
||||
flo.negative?
|
||||
positive?: |
|
||||
flo.positive?
|
||||
loop_count: 20000000
|
30
numeric.c
30
numeric.c
|
@ -2384,34 +2384,6 @@ flo_truncate(int argc, VALUE *argv, VALUE num)
|
|||
return flo_floor(argc, argv, num);
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* float.positive? -> true or false
|
||||
*
|
||||
* Returns +true+ if +float+ is greater than 0.
|
||||
*/
|
||||
|
||||
static VALUE
|
||||
flo_positive_p(VALUE num)
|
||||
{
|
||||
double f = RFLOAT_VALUE(num);
|
||||
return f > 0.0 ? Qtrue : Qfalse;
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* float.negative? -> true or false
|
||||
*
|
||||
* Returns +true+ if +float+ is less than 0.
|
||||
*/
|
||||
|
||||
static VALUE
|
||||
flo_negative_p(VALUE num)
|
||||
{
|
||||
double f = RFLOAT_VALUE(num);
|
||||
return f < 0.0 ? Qtrue : Qfalse;
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* num.floor([ndigits]) -> integer or float
|
||||
|
@ -5654,8 +5626,6 @@ Init_Numeric(void)
|
|||
rb_define_method(rb_cFloat, "finite?", rb_flo_is_finite_p, 0);
|
||||
rb_define_method(rb_cFloat, "next_float", flo_next_float, 0);
|
||||
rb_define_method(rb_cFloat, "prev_float", flo_prev_float, 0);
|
||||
rb_define_method(rb_cFloat, "positive?", flo_positive_p, 0);
|
||||
rb_define_method(rb_cFloat, "negative?", flo_negative_p, 0);
|
||||
}
|
||||
|
||||
#undef rb_float_value
|
||||
|
|
22
numeric.rb
22
numeric.rb
|
@ -204,4 +204,26 @@ class Float
|
|||
Primitive.attr! 'inline'
|
||||
Primitive.cexpr! 'FLOAT_ZERO_P(self) ? Qtrue : Qfalse'
|
||||
end
|
||||
|
||||
#
|
||||
# call-seq:
|
||||
# float.positive? -> true or false
|
||||
#
|
||||
# Returns +true+ if +float+ is greater than 0.
|
||||
#
|
||||
def positive?
|
||||
Primitive.attr! 'inline'
|
||||
Primitive.cexpr! 'RFLOAT_VALUE(self) > 0.0 ? Qtrue : Qfalse'
|
||||
end
|
||||
|
||||
#
|
||||
# call-seq:
|
||||
# float.negative? -> true or false
|
||||
#
|
||||
# Returns +true+ if +float+ is less than 0.
|
||||
#
|
||||
def negative?
|
||||
Primitive.attr! 'inline'
|
||||
Primitive.cexpr! 'RFLOAT_VALUE(self) < 0.0 ? Qtrue : Qfalse'
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue