numeric.c: prefer rb_check_arity
* numeric.c (flo_round, int_to_s, int_round): use rb_check_arity instead of rb_scan_args for a simple optional argument. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54474 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
9731a745ba
commit
9a686593c7
22
numeric.c
22
numeric.c
@ -1842,14 +1842,13 @@ flo_truncate(VALUE num);
|
|||||||
static VALUE
|
static VALUE
|
||||||
flo_round(int argc, VALUE *argv, VALUE num)
|
flo_round(int argc, VALUE *argv, VALUE num)
|
||||||
{
|
{
|
||||||
VALUE nd;
|
|
||||||
double number, f;
|
double number, f;
|
||||||
int ndigits = 0;
|
int ndigits = 0;
|
||||||
int binexp;
|
int binexp;
|
||||||
enum {float_dig = DBL_DIG+2};
|
enum {float_dig = DBL_DIG+2};
|
||||||
|
|
||||||
if (argc > 0 && rb_scan_args(argc, argv, "01", &nd) == 1) {
|
if (rb_check_arity(argc, 0, 1)) {
|
||||||
ndigits = NUM2INT(nd);
|
ndigits = NUM2INT(argv[0]);
|
||||||
}
|
}
|
||||||
if (ndigits < 0) {
|
if (ndigits < 0) {
|
||||||
return rb_int_round(flo_truncate(num), ndigits);
|
return rb_int_round(flo_truncate(num), ndigits);
|
||||||
@ -3015,13 +3014,10 @@ int_to_s(int argc, VALUE *argv, VALUE x)
|
|||||||
{
|
{
|
||||||
int base;
|
int base;
|
||||||
|
|
||||||
if (argc == 0) base = 10;
|
if (rb_check_arity(argc, 0, 1))
|
||||||
else {
|
base = NUM2INT(argv[0]);
|
||||||
VALUE b;
|
else
|
||||||
|
base = 10;
|
||||||
rb_scan_args(argc, argv, "01", &b);
|
|
||||||
base = NUM2INT(b);
|
|
||||||
}
|
|
||||||
return rb_int2str(x, base);
|
return rb_int2str(x, base);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4142,12 +4138,10 @@ int_dotimes(VALUE num)
|
|||||||
static VALUE
|
static VALUE
|
||||||
int_round(int argc, VALUE* argv, VALUE num)
|
int_round(int argc, VALUE* argv, VALUE num)
|
||||||
{
|
{
|
||||||
VALUE n;
|
|
||||||
int ndigits;
|
int ndigits;
|
||||||
|
|
||||||
if (argc == 0) return num;
|
if (!rb_check_arity(argc, 0, 1)) return num;
|
||||||
rb_scan_args(argc, argv, "1", &n);
|
ndigits = NUM2INT(argv[0]);
|
||||||
ndigits = NUM2INT(n);
|
|
||||||
if (ndigits > 0) {
|
if (ndigits > 0) {
|
||||||
return rb_Float(num);
|
return rb_Float(num);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user