mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Adding trigonometric and hyperbolic trigonometric tests (#1699)
* math_tests: rewrote test_atan() Rewrote the atan test so that analagous checks are symmetrically performed for all possible inputs: int, float, and double. The total number of tests has increased while reducing the total amount of code. * math_tests: inverse trig and inverse hyperbolic trig Tests were written for acos, acosh, asin, asinh, and atanh. * math: cos macro missing values::promote_int The cosine macro can't take an integer input without this fix. You can see that some of the other macros, like the sine macro, have this. * math_tests: trig and exponential Wrote tests for the trigonometric macros as well as the exponential macro. The hyperbolic trig macros use the exponential macro rather than any LLVM instrinsics (for now at least, LLVM 19 has the proper compiler intrinsics). * math: float comparison In the math module two macros were defined to assist in comparing floating-point numbers for a given tolerance. The trig, hyperbolic trig, and exponential tests in the math_tests module were updated to use these macros instead of direct comparison.
This commit is contained in:
@@ -131,6 +131,28 @@ macro deg_to_rad(x) {
|
||||
*>
|
||||
macro abs(x) => $$abs(x);
|
||||
|
||||
<*
|
||||
@require values::@is_int(x) || values::@is_float(x) "Expected an integer or floating point value"
|
||||
@require values::@is_int(y) || values::@is_float(y) "Expected an integer or floating point value"
|
||||
*>
|
||||
macro is_approx(x, y, eps)
|
||||
{
|
||||
if (x == y) return true;
|
||||
if (is_nan(x) || is_nan(y)) return false;
|
||||
return abs(x-y) <= eps;
|
||||
}
|
||||
|
||||
<*
|
||||
@require values::@is_int(x) || values::@is_float(x) "Expected an integer or floating point value"
|
||||
@require values::@is_int(y) || values::@is_float(y) "Expected an integer or floating point value"
|
||||
*>
|
||||
macro is_approx_rel(x, y, eps)
|
||||
{
|
||||
if (x == y) return true;
|
||||
if (is_nan(x) || is_nan(y)) return false;
|
||||
return abs(x-y) <= eps * max(abs(x), abs(y));
|
||||
}
|
||||
|
||||
<*
|
||||
@require values::@is_int(x) `The input must be an integer`
|
||||
*>
|
||||
@@ -290,7 +312,7 @@ macro copysign(mag, sgn) => $$copysign(values::promote_int_same(mag, sgn), ($typ
|
||||
<*
|
||||
@require values::@is_promotable_to_floatlike(x) `The input must be a number value or float vector`
|
||||
*>
|
||||
macro cos(x) => $$cos(x);
|
||||
macro cos(x) => $$cos(values::promote_int(x));
|
||||
|
||||
<*
|
||||
@require values::@is_promotable_to_floatlike(x) `The input must be a number value or float vector`
|
||||
|
||||
Reference in New Issue
Block a user