From b88e5a8079776e07a312ff8fecde60344ce95c17 Mon Sep 17 00:00:00 2001 From: Christoffer Lerno Date: Sat, 17 Dec 2022 21:29:45 +0100 Subject: [PATCH] Add atan and atan2 --- lib/std/math.c3 | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/lib/std/math.c3 b/lib/std/math.c3 index 856f8b2f9..3b5803636 100644 --- a/lib/std/math.c3 +++ b/lib/std/math.c3 @@ -95,6 +95,32 @@ macro sign(x) return ($typeof(x))(x < 0 ? -1 : 1); } +$if (env::COMPILER_LIBC_AVAILABLE): + +extern fn double _atan(double x) @extname("atan"); +extern fn float _atanf(float x) @extname("atanf"); +extern fn double _atan2(double x) @extname("atan2"); +extern fn float _atanf2(float x) @extname("atanf2"); + +macro atan(x) +{ + $if ($typeof(x).typeid == float.typeid): + return _atanf(x); + $else: + return _atan(x); + $endif; +} + +macro atan2(x, y) +{ + $if ($typeof(x).typeid == float.typeid && $typeof(y).typeid == float.typeid): + return _atan2f(x); + $else: + return _atan2(x); + $endif; +} + +$endif; /** * @require values::@is_floatlike(x) `The input must be a floating point value or float vector` **/