2021-02-28 09:06:00 +00:00
|
|
|
/*-*- 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"
|
2022-09-13 06:10:38 +00:00
|
|
|
#include "libc/mem/gc.h"
|
2021-08-16 22:26:31 +00:00
|
|
|
#include "libc/testlib/ezbench.h"
|
2021-02-28 09:06:00 +00:00
|
|
|
#include "libc/testlib/testlib.h"
|
|
|
|
#include "libc/x/x.h"
|
2022-09-13 06:10:38 +00:00
|
|
|
#include "libc/x/xasprintf.h"
|
2021-02-28 09:06:00 +00:00
|
|
|
|
2023-05-12 02:56:33 +00:00
|
|
|
double _atanh(double) asm("atanh");
|
|
|
|
float _atanhf(float) asm("atanhf");
|
|
|
|
long double _atanhl(long double) asm("atanhl");
|
2021-02-28 09:06:00 +00:00
|
|
|
|
|
|
|
TEST(atanh, test) {
|
2023-05-12 02:56:33 +00:00
|
|
|
EXPECT_STREQ("0", _gc(xdtoa(_atanh(0))));
|
|
|
|
EXPECT_STREQ("-0", _gc(xdtoa(_atanh(-0.))));
|
|
|
|
EXPECT_STREQ(".549306144334055", _gc(xdtoa(_atanh(.5))));
|
|
|
|
EXPECT_STREQ("-.549306144334055", _gc(xdtoa(_atanh(-.5))));
|
|
|
|
EXPECT_STREQ("INFINITY", _gc(xdtoa(_atanh(+1))));
|
|
|
|
EXPECT_STREQ("-INFINITY", _gc(xdtoa(_atanh(-1))));
|
|
|
|
EXPECT_TRUE(isnan(_atanh(+1.1)));
|
|
|
|
EXPECT_TRUE(isnan(_atanh(-1.1)));
|
2021-08-16 22:26:31 +00:00
|
|
|
EXPECT_STREQ("-2.1073424255447e-08",
|
2023-05-12 02:56:33 +00:00
|
|
|
_gc(xasprintf("%.15g", _atanh(-2.1073424255447e-08))));
|
2021-02-28 09:06:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(atanhl, test) {
|
2023-05-12 02:56:33 +00:00
|
|
|
EXPECT_STREQ("0", _gc(xdtoal(_atanhl(0))));
|
|
|
|
EXPECT_STREQ("-0", _gc(xdtoal(_atanhl(-0.))));
|
|
|
|
EXPECT_STREQ(".5493061443340548", _gc(xdtoal(_atanhl(.5))));
|
|
|
|
EXPECT_STREQ("-.5493061443340548", _gc(xdtoal(_atanhl(-.5))));
|
|
|
|
EXPECT_STREQ("INFINITY", _gc(xdtoal(_atanhl(+1))));
|
|
|
|
EXPECT_STREQ("-INFINITY", _gc(xdtoal(_atanhl(-1))));
|
|
|
|
EXPECT_TRUE(isnan(_atanhl(+1.1)));
|
|
|
|
EXPECT_TRUE(isnan(_atanhl(-1.1)));
|
2021-02-28 09:06:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(atanhf, test) {
|
2023-05-12 02:56:33 +00:00
|
|
|
EXPECT_STREQ("0", _gc(xdtoaf(_atanhf(0))));
|
|
|
|
EXPECT_STREQ("-0", _gc(xdtoaf(_atanhf(-0.))));
|
|
|
|
EXPECT_STREQ(".549306", _gc(xdtoaf(_atanhf(.5))));
|
|
|
|
EXPECT_STREQ("-.549306", _gc(xdtoaf(_atanhf(-.5))));
|
|
|
|
EXPECT_STREQ("INFINITY", _gc(xdtoaf(_atanhf(+1))));
|
|
|
|
EXPECT_STREQ("-INFINITY", _gc(xdtoaf(_atanhf(-1))));
|
|
|
|
EXPECT_TRUE(isnan(_atanhf(+1.1)));
|
|
|
|
EXPECT_TRUE(isnan(_atanhf(-1.1)));
|
2021-02-28 09:06:00 +00:00
|
|
|
}
|
2021-08-16 22:26:31 +00:00
|
|
|
|
2023-05-12 02:56:33 +00:00
|
|
|
BENCH(_atanh, bench) {
|
2021-08-16 22:26:31 +00:00
|
|
|
volatile double a = .5;
|
2023-05-12 02:56:33 +00:00
|
|
|
EZBENCH2("atanhf", donothing, EXPROPRIATE(_atanhf(a)));
|
|
|
|
EZBENCH2("atanh", donothing, EXPROPRIATE(_atanh(a)));
|
|
|
|
EZBENCH2("atanhl", donothing, EXPROPRIATE(_atanhl(a)));
|
2021-08-16 22:26:31 +00:00
|
|
|
}
|