Skip to content

Commit

Permalink
Introduce math_arc macro
Browse files Browse the repository at this point in the history
  • Loading branch information
S-H-GAMELINKS authored and nobu committed May 13, 2023
1 parent 5f411b9 commit 38ef5f7
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions math.c
Expand Up @@ -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
Expand All @@ -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)
}

/*
Expand All @@ -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)
}

/*
Expand Down

0 comments on commit 38ef5f7

Please sign in to comment.