summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorS-H-GAMELINKS <gamelinks007@gmail.com>2023-05-12 12:03:19 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2023-05-13 14:54:18 +0900
commit38ef5f7b35cab5064c4ed48c24bbd7a5eeb6e918 (patch)
treebe7c627ae9984f3ce231220babbc58723eb0e164
parent5f411b9b3e45a40df788f85156d4337206686deb (diff)
downloadruby-38ef5f7b35cab5064c4ed48c24bbd7a5eeb6e918.tar.gz
Introduce math_arc macro
-rw-r--r--math.c18
1 files changed, 8 insertions, 10 deletions
diff --git a/math.c b/math.c
index 67bf8b7b63..51a9eac8b4 100644
--- a/math.c
+++ b/math.c
@@ -170,6 +170,12 @@ math_tan(VALUE unused_obj, VALUE x)
return DBL2NUM(tan(Get_Double(x)));
}
+#define math_arc(num, func) \
+ double d; \
+ d = Get_Double((num)); \
+ domain_check_range(d, -1.0, 1.0, #func); \
+ return DBL2NUM(func(d));
+
/*
* call-seq:
* Math.acos(x) -> float
@@ -190,11 +196,7 @@ math_tan(VALUE unused_obj, VALUE x)
static VALUE
math_acos(VALUE unused_obj, VALUE x)
{
- double d;
-
- d = Get_Double(x);
- domain_check_range(d, -1.0, 1.0, "acos");
- return DBL2NUM(acos(d));
+ math_arc(x, acos)
}
/*
@@ -217,11 +219,7 @@ math_acos(VALUE unused_obj, VALUE x)
static VALUE
math_asin(VALUE unused_obj, VALUE x)
{
- double d;
-
- d = Get_Double(x);
- domain_check_range(d, -1.0, 1.0, "asin");
- return DBL2NUM(asin(d));
+ math_arc(x, asin)
}
/*