diff options
author | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2019-07-14 18:01:24 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2019-07-14 20:42:08 +0900 |
commit | 1464f7a149264b02637fdd444f8a431f1692981a (patch) | |
tree | 950b9e8b1f161f85813d1b4efa6c25a0cd706fde /complex.c | |
parent | 0df4a813ca8f9cb4d081c45ad91be3dd17bb06f1 (diff) |
Expand f_abs to use particular functions directly
Diffstat (limited to 'complex.c')
-rw-r--r-- | complex.c | 19 |
1 files changed, 18 insertions, 1 deletions
@@ -152,7 +152,24 @@ f_sub(VALUE x, VALUE y) return rb_funcall(x, '-', 1, y); } -fun1(abs) +inline static VALUE +f_abs(VALUE x) +{ + if (RB_INTEGER_TYPE_P(x)) { + return rb_int_abs(x); + } + else if (RB_FLOAT_TYPE_P(x)) { + return rb_float_abs(x); + } + else if (RB_TYPE_P(x, T_RATIONAL)) { + return rb_rational_abs(x); + } + else if (RB_TYPE_P(x, T_COMPLEX)) { + return rb_complex_abs(x); + } + return rb_funcall(x, id_abs, 0); +} + fun1(arg) fun1(denominator) |