summaryrefslogtreecommitdiff
path: root/complex.c
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2019-07-14 18:01:24 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2019-07-14 20:42:08 +0900
commit1464f7a149264b02637fdd444f8a431f1692981a (patch)
tree950b9e8b1f161f85813d1b4efa6c25a0cd706fde /complex.c
parent0df4a813ca8f9cb4d081c45ad91be3dd17bb06f1 (diff)
Expand f_abs to use particular functions directly
Diffstat (limited to 'complex.c')
-rw-r--r--complex.c19
1 files changed, 18 insertions, 1 deletions
diff --git a/complex.c b/complex.c
index 44fd65756c..c3e2fcc56d 100644
--- a/complex.c
+++ b/complex.c
@@ -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)