mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Expanded f_ceil
This commit is contained in:
parent
ffe4a6ebf9
commit
f9a0492b76
3 changed files with 19 additions and 9 deletions
|
@ -1772,6 +1772,7 @@ VALUE rb_int_odd_p(VALUE num);
|
|||
int rb_int_positive_p(VALUE num);
|
||||
int rb_int_negative_p(VALUE num);
|
||||
VALUE rb_num_pow(VALUE x, VALUE y);
|
||||
VALUE rb_float_ceil(VALUE num, int ndigits);
|
||||
|
||||
static inline VALUE
|
||||
rb_num_compare_with_zero(VALUE num, ID mid)
|
||||
|
|
|
@ -2002,12 +2002,19 @@ flo_floor(int argc, VALUE *argv, VALUE num)
|
|||
static VALUE
|
||||
flo_ceil(int argc, VALUE *argv, VALUE num)
|
||||
{
|
||||
double number, f;
|
||||
int ndigits = 0;
|
||||
|
||||
if (rb_check_arity(argc, 0, 1)) {
|
||||
ndigits = NUM2INT(argv[0]);
|
||||
}
|
||||
return rb_float_ceil(num, ndigits);
|
||||
}
|
||||
|
||||
VALUE
|
||||
rb_float_ceil(VALUE num, int ndigits)
|
||||
{
|
||||
double number, f;
|
||||
|
||||
number = RFLOAT_VALUE(num);
|
||||
if (number == 0.0) {
|
||||
return ndigits > 0 ? DBL2NUM(number) : INT2FIX(0);
|
||||
|
|
18
rational.c
18
rational.c
|
@ -43,13 +43,6 @@ static ID id_abs, id_idiv, id_integer_p,
|
|||
|
||||
static VALUE nurat_to_f(VALUE self);
|
||||
|
||||
#define fun1(n) \
|
||||
inline static VALUE \
|
||||
f_##n(VALUE x)\
|
||||
{\
|
||||
return rb_funcall(x, id_##n, 0);\
|
||||
}
|
||||
|
||||
inline static VALUE
|
||||
f_add(VALUE x, VALUE y)
|
||||
{
|
||||
|
@ -1597,7 +1590,16 @@ nurat_to_r(VALUE self)
|
|||
}
|
||||
|
||||
#define id_ceil rb_intern("ceil")
|
||||
#define f_ceil(x) rb_funcall((x), id_ceil, 0)
|
||||
static VALUE
|
||||
f_ceil(VALUE x)
|
||||
{
|
||||
if (RB_INTEGER_TYPE_P(x))
|
||||
return x;
|
||||
if (RB_FLOAT_TYPE_P(x))
|
||||
return rb_float_ceil(x, 0);
|
||||
|
||||
return rb_funcall(x, id_ceil, 0);
|
||||
}
|
||||
|
||||
#define id_quo rb_intern("quo")
|
||||
#define f_quo(x,y) rb_funcall((x), id_quo, 1, (y))
|
||||
|
|
Loading…
Add table
Reference in a new issue