From 38ef5f7b35cab5064c4ed48c24bbd7a5eeb6e918 Mon Sep 17 00:00:00 2001 From: S-H-GAMELINKS Date: Fri, 12 May 2023 12:03:19 +0900 Subject: Introduce math_arc macro --- math.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) (limited to 'math.c') 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) } /* -- cgit v1.2.1