From 937d921018927a0619b1af5f5eecf8ee6eb21076 Mon Sep 17 00:00:00 2001 From: Justine Tunney Date: Sat, 6 Mar 2021 12:59:35 -0800 Subject: [PATCH] Add tests for the greatest of all libm functions --- libc/tinymath/{atan2f.S => atan2.c} | 26 +-- libc/tinymath/{atan2.S => atan2f.c} | 26 ++- libc/tinymath/atan2l.S | 1 - test/libc/tinymath/atan2_test.c | 294 ++++++++++++++++++++++++++++ 4 files changed, 319 insertions(+), 28 deletions(-) rename libc/tinymath/{atan2f.S => atan2.c} (75%) rename libc/tinymath/{atan2.S => atan2f.c} (74%) create mode 100644 test/libc/tinymath/atan2_test.c diff --git a/libc/tinymath/atan2f.S b/libc/tinymath/atan2.c similarity index 75% rename from libc/tinymath/atan2f.S rename to libc/tinymath/atan2.c index 0dc8fb650..7e456fb15 100644 --- a/libc/tinymath/atan2f.S +++ b/libc/tinymath/atan2.c @@ -1,7 +1,7 @@ -/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│ -│vi: set et ft=asm ts=8 tw=8 fenc=utf-8 :vi│ +/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ +│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ ╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ +│ Copyright 2021 Justine Alexandra Roberts Tunney │ │ │ │ Permission to use, copy, modify, and/or distribute this software for │ │ any purpose with or without fee is hereby granted, provided that the │ @@ -16,14 +16,14 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/macros.internal.h" -.source __FILE__ +#include "libc/math.h" -// Returns arc tangent of 𝑦/𝑥. -// -// @param 𝑦 is float scalar in low quarter of %xmm0 -// @param 𝑥 is float scalar in low quarter of %xmm1 -// @return float scalar in low quarter of %xmm0 -atan2f: ezlea atan2l,ax - jmp _f2ld2 - .endfn atan2f,globl +/** + * Returns arc tangent of 𝑦/𝑥. + * @note the greatest of all libm functions + */ +double atan2(double y, double x) { + long double st; + asm("fpatan" : "=t"(st) : "0"((long double)x), "u"((long double)y) : "st(1)"); + return st; +} diff --git a/libc/tinymath/atan2.S b/libc/tinymath/atan2f.c similarity index 74% rename from libc/tinymath/atan2.S rename to libc/tinymath/atan2f.c index 161f75913..7ae20c3a4 100644 --- a/libc/tinymath/atan2.S +++ b/libc/tinymath/atan2f.c @@ -1,7 +1,7 @@ -/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│ -│vi: set et ft=asm ts=8 tw=8 fenc=utf-8 :vi│ +/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ +│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ ╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ +│ Copyright 2021 Justine Alexandra Roberts Tunney │ │ │ │ Permission to use, copy, modify, and/or distribute this software for │ │ any purpose with or without fee is hereby granted, provided that the │ @@ -16,15 +16,13 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/macros.internal.h" -.source __FILE__ +#include "libc/math.h" -// Returns arc tangent of 𝑦/𝑥. -// -// @param 𝑦 is double scalar in low half of %xmm0 -// @param 𝑥 is double scalar in low half of %xmm1 -// @return double scalar in low half of %xmm0 -// @note the greatest of all libm functions -atan2: ezlea atan2l,ax - jmp _d2ld2 - .endfn atan2,globl +/** + * Returns arc tangent of 𝑦/𝑥. + */ +float atan2f(float y, float x) { + long double st; + asm("fpatan" : "=t"(st) : "0"((long double)x), "u"((long double)y) : "st(1)"); + return st; +} diff --git a/libc/tinymath/atan2l.S b/libc/tinymath/atan2l.S index c49e85717..88ed9ce07 100644 --- a/libc/tinymath/atan2l.S +++ b/libc/tinymath/atan2l.S @@ -17,7 +17,6 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/macros.internal.h" -.source __FILE__ // Returns arc tangent of 𝑦/𝑥. // diff --git a/test/libc/tinymath/atan2_test.c b/test/libc/tinymath/atan2_test.c new file mode 100644 index 000000000..e91d038a1 --- /dev/null +++ b/test/libc/tinymath/atan2_test.c @@ -0,0 +1,294 @@ +/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ +│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ +╞══════════════════════════════════════════════════════════════════════════════╡ +│ Copyright 2021 Justine Alexandra Roberts Tunney │ +│ │ +│ Permission to use, copy, modify, and/or distribute this software for │ +│ any purpose with or without fee is hereby granted, provided that the │ +│ above copyright notice and this permission notice appear in all copies. │ +│ │ +│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ +│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ +│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ +│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ +│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ +│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ +│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ +│ PERFORMANCE OF THIS SOFTWARE. │ +╚─────────────────────────────────────────────────────────────────────────────*/ +#include "libc/math.h" +#include "libc/runtime/gc.h" +#include "libc/testlib/ezbench.h" +#include "libc/testlib/testlib.h" +#include "libc/x/x.h" + +TEST(atan2, yx) { + EXPECT_STREQ("-0.321750554396642", gc(xasprintf("%.15g", atan(-.5 / 1.5)))); + EXPECT_STREQ("-0.321750554396642", gc(xasprintf("%.15g", atan2(-.5, 1.5)))); +} + +TEST(atan2, test) { + EXPECT_STREQ("0", gc(xasprintf("%.15g", atan2(0., 0.)))); + EXPECT_STREQ("3.14159265358979", gc(xasprintf("%.15g", atan2(0., -0.)))); + EXPECT_STREQ("0", gc(xasprintf("%.15g", atan2(0., .5)))); + EXPECT_STREQ("3.14159265358979", gc(xasprintf("%.15g", atan2(0., -.5)))); + EXPECT_STREQ("0", gc(xasprintf("%.15g", atan2(0., 1.)))); + EXPECT_STREQ("3.14159265358979", gc(xasprintf("%.15g", atan2(0., -1.)))); + EXPECT_STREQ("0", gc(xasprintf("%.15g", atan2(0., 1.5)))); + EXPECT_STREQ("3.14159265358979", gc(xasprintf("%.15g", atan2(0., -1.5)))); + EXPECT_TRUE(isnan(atan2(0., NAN))); + EXPECT_TRUE(isnan(atan2(0., -NAN))); + EXPECT_STREQ("0", gc(xasprintf("%.15g", atan2(0., INFINITY)))); + EXPECT_STREQ("3.14159265358979", + gc(xasprintf("%.15g", atan2(0., -INFINITY)))); + EXPECT_STREQ("0", gc(xasprintf("%.15g", atan2(0., __DBL_MIN__)))); + EXPECT_STREQ("0", gc(xasprintf("%.15g", atan2(0., __DBL_MAX__)))); + EXPECT_STREQ("-0", gc(xasprintf("%.15g", atan2(-0., 0.)))); + EXPECT_STREQ("-3.14159265358979", gc(xasprintf("%.15g", atan2(-0., -0.)))); + EXPECT_STREQ("-0", gc(xasprintf("%.15g", atan2(-0., .5)))); + EXPECT_STREQ("-3.14159265358979", gc(xasprintf("%.15g", atan2(-0., -.5)))); + EXPECT_STREQ("-0", gc(xasprintf("%.15g", atan2(-0., 1.)))); + EXPECT_STREQ("-3.14159265358979", gc(xasprintf("%.15g", atan2(-0., -1.)))); + EXPECT_STREQ("-0", gc(xasprintf("%.15g", atan2(-0., 1.5)))); + EXPECT_STREQ("-3.14159265358979", gc(xasprintf("%.15g", atan2(-0., -1.5)))); + EXPECT_TRUE(isnan(atan2(-0., NAN))); + EXPECT_TRUE(isnan(atan2(-0., -NAN))); + EXPECT_STREQ("-0", gc(xasprintf("%.15g", atan2(-0., INFINITY)))); + EXPECT_STREQ("-3.14159265358979", + gc(xasprintf("%.15g", atan2(-0., -INFINITY)))); + EXPECT_STREQ("-0", gc(xasprintf("%.15g", atan2(-0., __DBL_MIN__)))); + EXPECT_STREQ("-0", gc(xasprintf("%.15g", atan2(-0., __DBL_MAX__)))); + EXPECT_STREQ("1.5707963267949", gc(xasprintf("%.15g", atan2(.5, 0.)))); + EXPECT_STREQ("1.5707963267949", gc(xasprintf("%.15g", atan2(.5, -0.)))); + EXPECT_STREQ("0.785398163397448", gc(xasprintf("%.15g", atan2(.5, .5)))); + EXPECT_STREQ("2.35619449019234", gc(xasprintf("%.15g", atan2(.5, -.5)))); + EXPECT_STREQ("0.463647609000806", gc(xasprintf("%.15g", atan2(.5, 1.)))); + EXPECT_STREQ("2.67794504458899", gc(xasprintf("%.15g", atan2(.5, -1.)))); + EXPECT_STREQ("0.321750554396642", gc(xasprintf("%.15g", atan2(.5, 1.5)))); + EXPECT_STREQ("2.81984209919315", gc(xasprintf("%.15g", atan2(.5, -1.5)))); + EXPECT_TRUE(isnan(atan2(.5, NAN))); + EXPECT_TRUE(isnan(atan2(.5, -NAN))); + EXPECT_STREQ("0", gc(xasprintf("%.15g", atan2(.5, INFINITY)))); + EXPECT_STREQ("3.14159265358979", + gc(xasprintf("%.15g", atan2(.5, -INFINITY)))); + EXPECT_STREQ("1.5707963267949", + gc(xasprintf("%.15g", atan2(.5, __DBL_MIN__)))); + EXPECT_STREQ("2.781342323134e-309", + gc(xasprintf("%.15g", atan2(.5, __DBL_MAX__)))); + EXPECT_STREQ("-1.5707963267949", gc(xasprintf("%.15g", atan2(-.5, 0.)))); + EXPECT_STREQ("-1.5707963267949", gc(xasprintf("%.15g", atan2(-.5, -0.)))); + EXPECT_STREQ("-0.785398163397448", gc(xasprintf("%.15g", atan2(-.5, .5)))); + EXPECT_STREQ("-2.35619449019234", gc(xasprintf("%.15g", atan2(-.5, -.5)))); + EXPECT_STREQ("-0.463647609000806", gc(xasprintf("%.15g", atan2(-.5, 1.)))); + EXPECT_STREQ("-2.67794504458899", gc(xasprintf("%.15g", atan2(-.5, -1.)))); + EXPECT_STREQ("-0.321750554396642", gc(xasprintf("%.15g", atan2(-.5, 1.5)))); + EXPECT_STREQ("-2.81984209919315", gc(xasprintf("%.15g", atan2(-.5, -1.5)))); + EXPECT_TRUE(isnan(atan2(-.5, NAN))); + EXPECT_TRUE(isnan(atan2(-.5, -NAN))); + EXPECT_STREQ("-0", gc(xasprintf("%.15g", atan2(-.5, INFINITY)))); + EXPECT_STREQ("-3.14159265358979", + gc(xasprintf("%.15g", atan2(-.5, -INFINITY)))); + EXPECT_STREQ("-1.5707963267949", + gc(xasprintf("%.15g", atan2(-.5, __DBL_MIN__)))); + EXPECT_STREQ("-2.781342323134e-309", + gc(xasprintf("%.15g", atan2(-.5, __DBL_MAX__)))); + EXPECT_STREQ("1.5707963267949", gc(xasprintf("%.15g", atan2(1., 0.)))); + EXPECT_STREQ("1.5707963267949", gc(xasprintf("%.15g", atan2(1., -0.)))); + EXPECT_STREQ("1.10714871779409", gc(xasprintf("%.15g", atan2(1., .5)))); + EXPECT_STREQ("2.0344439357957", gc(xasprintf("%.15g", atan2(1., -.5)))); + EXPECT_STREQ("0.785398163397448", gc(xasprintf("%.15g", atan2(1., 1.)))); + EXPECT_STREQ("2.35619449019234", gc(xasprintf("%.15g", atan2(1., -1.)))); + EXPECT_STREQ("0.588002603547568", gc(xasprintf("%.15g", atan2(1., 1.5)))); + EXPECT_STREQ("2.55359005004223", gc(xasprintf("%.15g", atan2(1., -1.5)))); + EXPECT_TRUE(isnan(atan2(1., NAN))); + EXPECT_TRUE(isnan(atan2(1., -NAN))); + EXPECT_STREQ("0", gc(xasprintf("%.15g", atan2(1., INFINITY)))); + EXPECT_STREQ("3.14159265358979", + gc(xasprintf("%.15g", atan2(1., -INFINITY)))); + EXPECT_STREQ("1.5707963267949", + gc(xasprintf("%.15g", atan2(1., __DBL_MIN__)))); + EXPECT_STREQ("5.562684646268e-309", + gc(xasprintf("%.15g", atan2(1., __DBL_MAX__)))); + EXPECT_STREQ("-1.5707963267949", gc(xasprintf("%.15g", atan2(-1., 0.)))); + EXPECT_STREQ("-1.5707963267949", gc(xasprintf("%.15g", atan2(-1., -0.)))); + EXPECT_STREQ("-1.10714871779409", gc(xasprintf("%.15g", atan2(-1., .5)))); + EXPECT_STREQ("-2.0344439357957", gc(xasprintf("%.15g", atan2(-1., -.5)))); + EXPECT_STREQ("-0.785398163397448", gc(xasprintf("%.15g", atan2(-1., 1.)))); + EXPECT_STREQ("-2.35619449019234", gc(xasprintf("%.15g", atan2(-1., -1.)))); + EXPECT_STREQ("-0.588002603547568", gc(xasprintf("%.15g", atan2(-1., 1.5)))); + EXPECT_STREQ("-2.55359005004223", gc(xasprintf("%.15g", atan2(-1., -1.5)))); + EXPECT_TRUE(isnan(atan2(-1., NAN))); + EXPECT_TRUE(isnan(atan2(-1., -NAN))); + EXPECT_STREQ("-0", gc(xasprintf("%.15g", atan2(-1., INFINITY)))); + EXPECT_STREQ("-3.14159265358979", + gc(xasprintf("%.15g", atan2(-1., -INFINITY)))); + EXPECT_STREQ("-1.5707963267949", + gc(xasprintf("%.15g", atan2(-1., __DBL_MIN__)))); + EXPECT_STREQ("-5.562684646268e-309", + gc(xasprintf("%.15g", atan2(-1., __DBL_MAX__)))); + EXPECT_STREQ("1.5707963267949", gc(xasprintf("%.15g", atan2(1.5, 0.)))); + EXPECT_STREQ("1.5707963267949", gc(xasprintf("%.15g", atan2(1.5, -0.)))); + EXPECT_STREQ("1.24904577239825", gc(xasprintf("%.15g", atan2(1.5, .5)))); + EXPECT_STREQ("1.89254688119154", gc(xasprintf("%.15g", atan2(1.5, -.5)))); + EXPECT_STREQ("0.982793723247329", gc(xasprintf("%.15g", atan2(1.5, 1.)))); + EXPECT_STREQ("2.15879893034246", gc(xasprintf("%.15g", atan2(1.5, -1.)))); + EXPECT_STREQ("0.785398163397448", gc(xasprintf("%.15g", atan2(1.5, 1.5)))); + EXPECT_STREQ("2.35619449019234", gc(xasprintf("%.15g", atan2(1.5, -1.5)))); + EXPECT_TRUE(isnan(atan2(1.5, NAN))); + EXPECT_TRUE(isnan(atan2(1.5, -NAN))); + EXPECT_STREQ("0", gc(xasprintf("%.15g", atan2(1.5, INFINITY)))); + EXPECT_STREQ("3.14159265358979", + gc(xasprintf("%.15g", atan2(1.5, -INFINITY)))); + EXPECT_STREQ("1.5707963267949", + gc(xasprintf("%.15g", atan2(1.5, __DBL_MIN__)))); + EXPECT_STREQ("8.34402696940201e-309", + gc(xasprintf("%.15g", atan2(1.5, __DBL_MAX__)))); + EXPECT_STREQ("-1.5707963267949", gc(xasprintf("%.15g", atan2(-1.5, 0.)))); + EXPECT_STREQ("-1.5707963267949", gc(xasprintf("%.15g", atan2(-1.5, -0.)))); + EXPECT_STREQ("-1.24904577239825", gc(xasprintf("%.15g", atan2(-1.5, .5)))); + EXPECT_STREQ("-1.89254688119154", gc(xasprintf("%.15g", atan2(-1.5, -.5)))); + EXPECT_STREQ("-0.982793723247329", gc(xasprintf("%.15g", atan2(-1.5, 1.)))); + EXPECT_STREQ("-2.15879893034246", gc(xasprintf("%.15g", atan2(-1.5, -1.)))); + EXPECT_STREQ("-0.785398163397448", gc(xasprintf("%.15g", atan2(-1.5, 1.5)))); + EXPECT_STREQ("-2.35619449019234", gc(xasprintf("%.15g", atan2(-1.5, -1.5)))); + EXPECT_TRUE(isnan(atan2(-1.5, NAN))); + EXPECT_TRUE(isnan(atan2(-1.5, -NAN))); + EXPECT_STREQ("-0", gc(xasprintf("%.15g", atan2(-1.5, INFINITY)))); + EXPECT_STREQ("-3.14159265358979", + gc(xasprintf("%.15g", atan2(-1.5, -INFINITY)))); + EXPECT_STREQ("-1.5707963267949", + gc(xasprintf("%.15g", atan2(-1.5, __DBL_MIN__)))); + EXPECT_STREQ("-8.34402696940201e-309", + gc(xasprintf("%.15g", atan2(-1.5, __DBL_MAX__)))); + EXPECT_TRUE(isnan(atan2(NAN, 0.))); + EXPECT_TRUE(isnan(atan2(NAN, -0.))); + EXPECT_TRUE(isnan(atan2(NAN, .5))); + EXPECT_TRUE(isnan(atan2(NAN, -.5))); + EXPECT_TRUE(isnan(atan2(NAN, 1.))); + EXPECT_TRUE(isnan(atan2(NAN, -1.))); + EXPECT_TRUE(isnan(atan2(NAN, 1.5))); + EXPECT_TRUE(isnan(atan2(NAN, -1.5))); + EXPECT_TRUE(isnan(atan2(NAN, NAN))); + EXPECT_TRUE(isnan(atan2(NAN, -NAN))); + EXPECT_TRUE(isnan(atan2(NAN, INFINITY))); + EXPECT_TRUE(isnan(atan2(NAN, -INFINITY))); + EXPECT_TRUE(isnan(atan2(NAN, __DBL_MIN__))); + EXPECT_TRUE(isnan(atan2(NAN, __DBL_MAX__))); + EXPECT_TRUE(isnan(atan2(-NAN, 0.))); + EXPECT_TRUE(isnan(atan2(-NAN, -0.))); + EXPECT_TRUE(isnan(atan2(-NAN, .5))); + EXPECT_TRUE(isnan(atan2(-NAN, -.5))); + EXPECT_TRUE(isnan(atan2(-NAN, 1.))); + EXPECT_TRUE(isnan(atan2(-NAN, -1.))); + EXPECT_TRUE(isnan(atan2(-NAN, 1.5))); + EXPECT_TRUE(isnan(atan2(-NAN, -1.5))); + EXPECT_TRUE(isnan(atan2(-NAN, NAN))); + EXPECT_TRUE(isnan(atan2(-NAN, -NAN))); + EXPECT_TRUE(isnan(atan2(-NAN, INFINITY))); + EXPECT_TRUE(isnan(atan2(-NAN, -INFINITY))); + EXPECT_TRUE(isnan(atan2(-NAN, __DBL_MIN__))); + EXPECT_TRUE(isnan(atan2(-NAN, __DBL_MAX__))); + EXPECT_STREQ("1.5707963267949", gc(xasprintf("%.15g", atan2(INFINITY, 0.)))); + EXPECT_STREQ("1.5707963267949", gc(xasprintf("%.15g", atan2(INFINITY, -0.)))); + EXPECT_STREQ("1.5707963267949", gc(xasprintf("%.15g", atan2(INFINITY, .5)))); + EXPECT_STREQ("1.5707963267949", gc(xasprintf("%.15g", atan2(INFINITY, -.5)))); + EXPECT_STREQ("1.5707963267949", gc(xasprintf("%.15g", atan2(INFINITY, 1.)))); + EXPECT_STREQ("1.5707963267949", gc(xasprintf("%.15g", atan2(INFINITY, -1.)))); + EXPECT_STREQ("1.5707963267949", gc(xasprintf("%.15g", atan2(INFINITY, 1.5)))); + EXPECT_STREQ("1.5707963267949", + gc(xasprintf("%.15g", atan2(INFINITY, -1.5)))); + EXPECT_TRUE(isnan(atan2(INFINITY, NAN))); + EXPECT_TRUE(isnan(atan2(INFINITY, -NAN))); + EXPECT_STREQ("0.785398163397448", + gc(xasprintf("%.15g", atan2(INFINITY, INFINITY)))); + EXPECT_STREQ("2.35619449019234", + gc(xasprintf("%.15g", atan2(INFINITY, -INFINITY)))); + EXPECT_STREQ("1.5707963267949", + gc(xasprintf("%.15g", atan2(INFINITY, __DBL_MIN__)))); + EXPECT_STREQ("1.5707963267949", + gc(xasprintf("%.15g", atan2(INFINITY, __DBL_MAX__)))); + EXPECT_STREQ("-1.5707963267949", + gc(xasprintf("%.15g", atan2(-INFINITY, 0.)))); + EXPECT_STREQ("-1.5707963267949", + gc(xasprintf("%.15g", atan2(-INFINITY, -0.)))); + EXPECT_STREQ("-1.5707963267949", + gc(xasprintf("%.15g", atan2(-INFINITY, .5)))); + EXPECT_STREQ("-1.5707963267949", + gc(xasprintf("%.15g", atan2(-INFINITY, -.5)))); + EXPECT_STREQ("-1.5707963267949", + gc(xasprintf("%.15g", atan2(-INFINITY, 1.)))); + EXPECT_STREQ("-1.5707963267949", + gc(xasprintf("%.15g", atan2(-INFINITY, -1.)))); + EXPECT_STREQ("-1.5707963267949", + gc(xasprintf("%.15g", atan2(-INFINITY, 1.5)))); + EXPECT_STREQ("-1.5707963267949", + gc(xasprintf("%.15g", atan2(-INFINITY, -1.5)))); + EXPECT_TRUE(isnan(atan2(-INFINITY, NAN))); + EXPECT_TRUE(isnan(atan2(-INFINITY, -NAN))); + EXPECT_STREQ("-0.785398163397448", + gc(xasprintf("%.15g", atan2(-INFINITY, INFINITY)))); + EXPECT_STREQ("-2.35619449019234", + gc(xasprintf("%.15g", atan2(-INFINITY, -INFINITY)))); + EXPECT_STREQ("-1.5707963267949", + gc(xasprintf("%.15g", atan2(-INFINITY, __DBL_MIN__)))); + EXPECT_STREQ("-1.5707963267949", + gc(xasprintf("%.15g", atan2(-INFINITY, __DBL_MAX__)))); + EXPECT_STREQ("1.5707963267949", + gc(xasprintf("%.15g", atan2(__DBL_MIN__, 0.)))); + EXPECT_STREQ("1.5707963267949", + gc(xasprintf("%.15g", atan2(__DBL_MIN__, -0.)))); + EXPECT_STREQ("4.4501477170144e-308", + gc(xasprintf("%.15g", atan2(__DBL_MIN__, .5)))); + EXPECT_STREQ("3.14159265358979", + gc(xasprintf("%.15g", atan2(__DBL_MIN__, -.5)))); + EXPECT_STREQ("2.2250738585072e-308", + gc(xasprintf("%.15g", atan2(__DBL_MIN__, 1.)))); + EXPECT_STREQ("3.14159265358979", + gc(xasprintf("%.15g", atan2(__DBL_MIN__, -1.)))); + EXPECT_STREQ("1.48338257233813e-308", + gc(xasprintf("%.15g", atan2(__DBL_MIN__, 1.5)))); + EXPECT_STREQ("3.14159265358979", + gc(xasprintf("%.15g", atan2(__DBL_MIN__, -1.5)))); + EXPECT_TRUE(isnan(atan2(__DBL_MIN__, NAN))); + EXPECT_TRUE(isnan(atan2(__DBL_MIN__, -NAN))); + EXPECT_STREQ("0", gc(xasprintf("%.15g", atan2(__DBL_MIN__, INFINITY)))); + EXPECT_STREQ("3.14159265358979", + gc(xasprintf("%.15g", atan2(__DBL_MIN__, -INFINITY)))); + EXPECT_STREQ("0.785398163397448", + gc(xasprintf("%.15g", atan2(__DBL_MIN__, __DBL_MIN__)))); + EXPECT_STREQ("0", gc(xasprintf("%.15g", atan2(__DBL_MIN__, __DBL_MAX__)))); + EXPECT_STREQ("1.5707963267949", + gc(xasprintf("%.15g", atan2(__DBL_MAX__, 0.)))); + EXPECT_STREQ("1.5707963267949", + gc(xasprintf("%.15g", atan2(__DBL_MAX__, -0.)))); + EXPECT_STREQ("1.5707963267949", + gc(xasprintf("%.15g", atan2(__DBL_MAX__, .5)))); + EXPECT_STREQ("1.5707963267949", + gc(xasprintf("%.15g", atan2(__DBL_MAX__, -.5)))); + EXPECT_STREQ("1.5707963267949", + gc(xasprintf("%.15g", atan2(__DBL_MAX__, 1.)))); + EXPECT_STREQ("1.5707963267949", + gc(xasprintf("%.15g", atan2(__DBL_MAX__, -1.)))); + EXPECT_STREQ("1.5707963267949", + gc(xasprintf("%.15g", atan2(__DBL_MAX__, 1.5)))); + EXPECT_STREQ("1.5707963267949", + gc(xasprintf("%.15g", atan2(__DBL_MAX__, -1.5)))); + EXPECT_TRUE(isnan(atan2(__DBL_MAX__, NAN))); + EXPECT_TRUE(isnan(atan2(__DBL_MAX__, -NAN))); + EXPECT_STREQ("0", gc(xasprintf("%.15g", atan2(__DBL_MAX__, INFINITY)))); + EXPECT_STREQ("3.14159265358979", + gc(xasprintf("%.15g", atan2(__DBL_MAX__, -INFINITY)))); + EXPECT_STREQ("1.5707963267949", + gc(xasprintf("%.15g", atan2(__DBL_MAX__, __DBL_MIN__)))); + EXPECT_STREQ("0.785398163397448", + gc(xasprintf("%.15g", atan2(__DBL_MAX__, __DBL_MAX__)))); +} + +BENCH(atan2, bench) { + volatile float f = 3; + volatile double d = 3; + volatile long double l = 3; + EZBENCH2("atan2", donothing, atan2(d, d)); // ~31ns + EZBENCH2("atan2f", donothing, atan2f(f, f)); // ~31ns + EZBENCH2("atan2l", donothing, atan2l(l, l)); // ~31ns +}