mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-22 21:32:31 +00:00
Improve signal handling and math
- Polyfill ucontext_t on FreeBSD/OpenBSD/NetBSD - Add tests confirming signals can edit CPU state - Work towards supporting ZIP filesystem on bare metal - Add more tinymath unit tests for POSIX conformance - Add X87 and SSE status flags to crash report - Fix some bugs in blinkenlights - Fix llvm build breakage
This commit is contained in:
parent
cdc54ea1fd
commit
40291c9db3
109 changed files with 2316 additions and 520 deletions
|
@ -28,3 +28,28 @@ TEST(atan2l, test) {
|
|||
EXPECT_STREQ("-2.95", gc(xasprintf("%.2f", atan2(b, a))));
|
||||
EXPECT_STREQ("-2.95", gc(xasprintf("%.2Lf", atan2l(b, a))));
|
||||
}
|
||||
|
||||
TEST(atan2, testSpecialCases) {
|
||||
ASSERT_STREQ("NAN", gc(xdtoa(atan2(NAN, 0))));
|
||||
ASSERT_STREQ("NAN", gc(xdtoa(atan2(0, NAN))));
|
||||
ASSERT_STREQ("0", gc(xdtoa(atan2(+0., +0.))));
|
||||
ASSERT_STREQ("0", gc(xdtoa(atan2(+0., +1.))));
|
||||
ASSERT_STREQ("0", gc(xdtoa(atan2(+0., +2.))));
|
||||
ASSERT_STREQ("0", gc(xdtoa(atan2(1, INFINITY))));
|
||||
ASSERT_STREQ("3.141592653589793", gc(xdtoal(atan2(+0., -0.))));
|
||||
ASSERT_STREQ("3.141592653589793", gc(xdtoal(atan2(+0., -1.))));
|
||||
ASSERT_STREQ("3.141592653589793", gc(xdtoal(atan2(+0., -2.))));
|
||||
ASSERT_STREQ("-1.570796326794897", gc(xdtoal(atan2(-1., -0.))));
|
||||
ASSERT_STREQ("-1.570796326794897", gc(xdtoal(atan2(-1., +0.))));
|
||||
ASSERT_STREQ("-1.570796326794897", gc(xdtoal(atan2(-2., -0.))));
|
||||
ASSERT_STREQ("-1.570796326794897", gc(xdtoal(atan2(-2., +0.))));
|
||||
ASSERT_STREQ("1.570796326794897", gc(xdtoal(atan2(+1., -0.))));
|
||||
ASSERT_STREQ("1.570796326794897", gc(xdtoal(atan2(+1., +0.))));
|
||||
ASSERT_STREQ("1.570796326794897", gc(xdtoal(atan2(+2., -0.))));
|
||||
ASSERT_STREQ("1.570796326794897", gc(xdtoal(atan2(+2., +0.))));
|
||||
ASSERT_STREQ("1.570796326794897", gc(xdtoal(atan2(INFINITY, 1))));
|
||||
ASSERT_STREQ("1.570796326794897", gc(xdtoal(atan2(INFINITY, -1))));
|
||||
ASSERT_STREQ("3.141592653589793", gc(xdtoal(atan2(1, -INFINITY))));
|
||||
ASSERT_STREQ("2.356194490192345", gc(xdtoal(atan2(INFINITY, -INFINITY))));
|
||||
ASSERT_STREQ(".7853981633974483", gc(xdtoal(atan2(INFINITY, INFINITY))));
|
||||
}
|
||||
|
|
45
test/libc/tinymath/atanl_test.c
Normal file
45
test/libc/tinymath/atanl_test.c
Normal file
|
@ -0,0 +1,45 @@
|
|||
/*-*- 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/testlib.h"
|
||||
#include "libc/x/x.h"
|
||||
|
||||
void SetUp(void) {
|
||||
/* 8087 FPU Control Word
|
||||
IM: Invalid Operation ───────────────┐
|
||||
DM: Denormal Operand ───────────────┐│
|
||||
ZM: Zero Divide ───────────────────┐││
|
||||
OM: Overflow ─────────────────────┐│││
|
||||
UM: Underflow ───────────────────┐││││
|
||||
PM: Precision ──────────────────┐│││││
|
||||
PC: Precision Control ────────┐ ││││││
|
||||
{float,∅,double,long double} │ ││││││
|
||||
RC: Rounding Control ───────┐ │ ││││││
|
||||
{even, →-∞, →+∞, →0} │┌┤ ││││││
|
||||
┌┤││ ││││││
|
||||
d││││rr││││││*/
|
||||
int x87cw = 0b0000000000000000001101100001;
|
||||
asm volatile("fldcw\t%0" : /* no outputs */ : "m"(x87cw));
|
||||
}
|
||||
|
||||
TEST(atanl, testLongDouble) {
|
||||
EXPECT_STREQ("NAN", gc(xdtoal(atanl(NAN))));
|
||||
EXPECT_STREQ(".7853981583974483", gc(xdtoal(atanl(.99999999))));
|
||||
}
|
73
test/libc/tinymath/copysign_test.c
Normal file
73
test/libc/tinymath/copysign_test.c
Normal file
|
@ -0,0 +1,73 @@
|
|||
/*-*- 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/testlib.h"
|
||||
#include "libc/x/x.h"
|
||||
|
||||
TEST(copysign, test) {
|
||||
EXPECT_STREQ("0", gc(xdtoa(copysign(0, +0))));
|
||||
EXPECT_STREQ("-0", gc(xdtoa(copysign(0, -0.))));
|
||||
EXPECT_STREQ("0", gc(xdtoa(copysign(0, +1))));
|
||||
EXPECT_STREQ("-0", gc(xdtoa(copysign(-0., -1))));
|
||||
EXPECT_STREQ("2", gc(xdtoa(copysign(2, +1))));
|
||||
EXPECT_STREQ("-2", gc(xdtoa(copysign(-2, -1))));
|
||||
EXPECT_STREQ("NAN", gc(xdtoa(copysign(NAN, +1))));
|
||||
EXPECT_STREQ("-NAN", gc(xdtoa(copysign(NAN, -1))));
|
||||
EXPECT_STREQ("INFINITY", gc(xdtoa(copysign(INFINITY, +1))));
|
||||
EXPECT_STREQ("-INFINITY", gc(xdtoa(copysign(INFINITY, -1))));
|
||||
EXPECT_STREQ("NAN", gc(xdtoa(copysign(-NAN, +1))));
|
||||
EXPECT_STREQ("-NAN", gc(xdtoa(copysign(-NAN, -1))));
|
||||
EXPECT_STREQ("INFINITY", gc(xdtoa(copysign(-INFINITY, +1))));
|
||||
EXPECT_STREQ("-INFINITY", gc(xdtoa(copysign(-INFINITY, -1))));
|
||||
}
|
||||
|
||||
TEST(copysignl, test) {
|
||||
EXPECT_STREQ("0", gc(xdtoal(copysignl(0, +0))));
|
||||
EXPECT_STREQ("-0", gc(xdtoal(copysignl(0, -0.))));
|
||||
EXPECT_STREQ("0", gc(xdtoal(copysignl(0, +1))));
|
||||
EXPECT_STREQ("-0", gc(xdtoal(copysignl(-0., -1))));
|
||||
EXPECT_STREQ("2", gc(xdtoal(copysignl(2, +1))));
|
||||
EXPECT_STREQ("-2", gc(xdtoal(copysignl(-2, -1))));
|
||||
EXPECT_STREQ("NAN", gc(xdtoal(copysignl(NAN, +1))));
|
||||
EXPECT_STREQ("-NAN", gc(xdtoal(copysignl(NAN, -1))));
|
||||
EXPECT_STREQ("INFINITY", gc(xdtoal(copysignl(INFINITY, +1))));
|
||||
EXPECT_STREQ("-INFINITY", gc(xdtoal(copysignl(INFINITY, -1))));
|
||||
EXPECT_STREQ("NAN", gc(xdtoal(copysignl(-NAN, +1))));
|
||||
EXPECT_STREQ("-NAN", gc(xdtoal(copysignl(-NAN, -1))));
|
||||
EXPECT_STREQ("INFINITY", gc(xdtoal(copysignl(-INFINITY, +1))));
|
||||
EXPECT_STREQ("-INFINITY", gc(xdtoal(copysignl(-INFINITY, -1))));
|
||||
}
|
||||
|
||||
TEST(copysignf, test) {
|
||||
EXPECT_STREQ("0", gc(xdtoaf(copysignf(0, +0))));
|
||||
EXPECT_STREQ("-0", gc(xdtoaf(copysignf(0, -0.))));
|
||||
EXPECT_STREQ("0", gc(xdtoaf(copysignf(0, +1))));
|
||||
EXPECT_STREQ("-0", gc(xdtoaf(copysignf(-0., -1))));
|
||||
EXPECT_STREQ("2", gc(xdtoaf(copysignf(2, +1))));
|
||||
EXPECT_STREQ("-2", gc(xdtoaf(copysignf(-2, -1))));
|
||||
EXPECT_STREQ("NAN", gc(xdtoaf(copysignf(NAN, +1))));
|
||||
EXPECT_STREQ("-NAN", gc(xdtoaf(copysignf(NAN, -1))));
|
||||
EXPECT_STREQ("INFINITY", gc(xdtoaf(copysignf(INFINITY, +1))));
|
||||
EXPECT_STREQ("-INFINITY", gc(xdtoaf(copysignf(INFINITY, -1))));
|
||||
EXPECT_STREQ("NAN", gc(xdtoaf(copysignf(-NAN, +1))));
|
||||
EXPECT_STREQ("-NAN", gc(xdtoaf(copysignf(-NAN, -1))));
|
||||
EXPECT_STREQ("INFINITY", gc(xdtoaf(copysignf(-INFINITY, +1))));
|
||||
EXPECT_STREQ("-INFINITY", gc(xdtoaf(copysignf(-INFINITY, -1))));
|
||||
}
|
56
test/libc/tinymath/exp10_test.c
Normal file
56
test/libc/tinymath/exp10_test.c
Normal file
|
@ -0,0 +1,56 @@
|
|||
/*-*- 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/testlib.h"
|
||||
#include "libc/x/x.h"
|
||||
|
||||
#define exp10l(x) exp10l(VEIL("t", (long double)(x)))
|
||||
#define exp10(x) exp10(VEIL("x", (double)(x)))
|
||||
#define exp10f(x) exp10f(VEIL("x", (float)(x)))
|
||||
|
||||
TEST(exp10l, test) {
|
||||
EXPECT_STREQ("1", gc(xdtoal(exp10l(0))));
|
||||
EXPECT_STREQ("1", gc(xdtoal(exp10l(-0.))));
|
||||
EXPECT_STREQ("INFINITY", gc(xdtoal(exp10l(INFINITY))));
|
||||
EXPECT_STREQ("0", gc(xdtoal(exp10l(-INFINITY))));
|
||||
EXPECT_STREQ("NAN", gc(xdtoal(exp10l(NAN))));
|
||||
EXPECT_STREQ("0", gc(xdtoal(exp10l(-132098844872390))));
|
||||
EXPECT_STREQ("INFINITY", gc(xdtoal(exp10l(132098844872390))));
|
||||
}
|
||||
|
||||
TEST(exp10, test) {
|
||||
EXPECT_STREQ("1", gc(xdtoa(exp10(0))));
|
||||
EXPECT_STREQ("1", gc(xdtoa(exp10(-0.))));
|
||||
EXPECT_STREQ("INFINITY", gc(xdtoa(exp10(INFINITY))));
|
||||
EXPECT_STREQ("0", gc(xdtoa(exp10(-INFINITY))));
|
||||
EXPECT_STREQ("NAN", gc(xdtoa(exp10(NAN))));
|
||||
EXPECT_STREQ("0", gc(xdtoa(exp10(-132098844872390))));
|
||||
EXPECT_STREQ("INFINITY", gc(xdtoa(exp10(132098844872390))));
|
||||
}
|
||||
|
||||
TEST(exp10f, test) {
|
||||
EXPECT_STREQ("1", gc(xdtoaf(exp10f(0))));
|
||||
EXPECT_STREQ("1", gc(xdtoaf(exp10f(-0.))));
|
||||
EXPECT_STREQ("INFINITY", gc(xdtoaf(exp10f(INFINITY))));
|
||||
EXPECT_STREQ("0", gc(xdtoaf(exp10f(-INFINITY))));
|
||||
EXPECT_STREQ("NAN", gc(xdtoaf(exp10f(NAN))));
|
||||
EXPECT_STREQ("0", gc(xdtoaf(exp10f(-132098844872390))));
|
||||
EXPECT_STREQ("INFINITY", gc(xdtoaf(exp10f(132098844872390))));
|
||||
}
|
56
test/libc/tinymath/exp2_test.c
Normal file
56
test/libc/tinymath/exp2_test.c
Normal file
|
@ -0,0 +1,56 @@
|
|||
/*-*- 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/testlib.h"
|
||||
#include "libc/x/x.h"
|
||||
|
||||
#define exp2l(x) exp2l(VEIL("t", (long double)(x)))
|
||||
#define exp2(x) exp2(VEIL("x", (double)(x)))
|
||||
#define exp2f(x) exp2f(VEIL("x", (float)(x)))
|
||||
|
||||
TEST(exp2l, test) {
|
||||
EXPECT_STREQ("1", gc(xdtoal(exp2l(0))));
|
||||
EXPECT_STREQ("1", gc(xdtoal(exp2l(-0.))));
|
||||
EXPECT_STREQ("INFINITY", gc(xdtoal(exp2l(INFINITY))));
|
||||
EXPECT_STREQ("0", gc(xdtoal(exp2l(-INFINITY))));
|
||||
EXPECT_STREQ("NAN", gc(xdtoal(exp2l(NAN))));
|
||||
EXPECT_STREQ("0", gc(xdtoal(exp2l(-132098844872390))));
|
||||
EXPECT_STREQ("INFINITY", gc(xdtoal(exp2l(132098844872390))));
|
||||
}
|
||||
|
||||
TEST(exp2, test) {
|
||||
EXPECT_STREQ("1", gc(xdtoa(exp2(0))));
|
||||
EXPECT_STREQ("1", gc(xdtoa(exp2(-0.))));
|
||||
EXPECT_STREQ("INFINITY", gc(xdtoa(exp2(INFINITY))));
|
||||
EXPECT_STREQ("0", gc(xdtoa(exp2(-INFINITY))));
|
||||
EXPECT_STREQ("NAN", gc(xdtoa(exp2(NAN))));
|
||||
EXPECT_STREQ("0", gc(xdtoa(exp2(-132098844872390))));
|
||||
EXPECT_STREQ("INFINITY", gc(xdtoa(exp2(132098844872390))));
|
||||
}
|
||||
|
||||
TEST(exp2f, test) {
|
||||
EXPECT_STREQ("1", gc(xdtoaf(exp2f(0))));
|
||||
EXPECT_STREQ("1", gc(xdtoaf(exp2f(-0.))));
|
||||
EXPECT_STREQ("INFINITY", gc(xdtoaf(exp2f(INFINITY))));
|
||||
EXPECT_STREQ("0", gc(xdtoaf(exp2f(-INFINITY))));
|
||||
EXPECT_STREQ("NAN", gc(xdtoaf(exp2f(NAN))));
|
||||
EXPECT_STREQ("0", gc(xdtoaf(exp2f(-132098844872390))));
|
||||
EXPECT_STREQ("INFINITY", gc(xdtoaf(exp2f(132098844872390))));
|
||||
}
|
|
@ -22,7 +22,41 @@
|
|||
#include "libc/testlib/testlib.h"
|
||||
#include "libc/x/x.h"
|
||||
|
||||
#define expl(x) expl(VEIL("t", (long double)(x)))
|
||||
#define exp(x) exp(VEIL("x", (double)(x)))
|
||||
#define expf(x) expf(VEIL("x", (float)(x)))
|
||||
|
||||
TEST(expl, test) {
|
||||
EXPECT_STREQ("1", gc(xdtoal(expl(0))));
|
||||
EXPECT_STREQ("1", gc(xdtoal(expl(-0.))));
|
||||
EXPECT_STREQ("INFINITY", gc(xdtoal(expl(INFINITY))));
|
||||
EXPECT_STREQ("0", gc(xdtoal(expl(-INFINITY))));
|
||||
EXPECT_STREQ("NAN", gc(xdtoal(expl(NAN))));
|
||||
EXPECT_STREQ("0", gc(xdtoal(expl(-132098844872390))));
|
||||
EXPECT_STREQ("INFINITY", gc(xdtoal(expl(132098844872390))));
|
||||
}
|
||||
|
||||
TEST(exp, test) {
|
||||
EXPECT_STREQ("1", gc(xdtoa(exp(0))));
|
||||
EXPECT_STREQ("1", gc(xdtoa(exp(-0.))));
|
||||
EXPECT_STREQ("INFINITY", gc(xdtoa(exp(INFINITY))));
|
||||
EXPECT_STREQ("0", gc(xdtoa(exp(-INFINITY))));
|
||||
EXPECT_STREQ("NAN", gc(xdtoa(exp(NAN))));
|
||||
EXPECT_STREQ("0", gc(xdtoa(exp(-132098844872390))));
|
||||
EXPECT_STREQ("INFINITY", gc(xdtoa(exp(132098844872390))));
|
||||
}
|
||||
|
||||
TEST(expf, test) {
|
||||
EXPECT_STREQ("1", gc(xdtoaf(expf(0))));
|
||||
EXPECT_STREQ("1", gc(xdtoaf(expf(-0.))));
|
||||
EXPECT_STREQ("INFINITY", gc(xdtoaf(expf(INFINITY))));
|
||||
EXPECT_STREQ("0", gc(xdtoaf(expf(-INFINITY))));
|
||||
EXPECT_STREQ("NAN", gc(xdtoaf(expf(NAN))));
|
||||
EXPECT_STREQ("0", gc(xdtoaf(expf(-132098844872390))));
|
||||
EXPECT_STREQ("INFINITY", gc(xdtoaf(expf(132098844872390))));
|
||||
}
|
||||
|
||||
TEST(exp, fun) {
|
||||
ASSERT_STREQ("7.389056", gc(xasprintf("%f", exp(2.0))));
|
||||
ASSERT_STREQ("6.389056", gc(xasprintf("%f", expm1(2.0))));
|
||||
ASSERT_STREQ("6.389056", gc(xasprintf("%f", exp(2.0) - 1.0)));
|
||||
|
|
58
test/libc/tinymath/expm1_test.c
Normal file
58
test/libc/tinymath/expm1_test.c
Normal file
|
@ -0,0 +1,58 @@
|
|||
/*-*- 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/testlib.h"
|
||||
#include "libc/x/x.h"
|
||||
|
||||
#define expm1l(x) expm1l(VEIL("t", (long double)(x)))
|
||||
#define expm1(x) expm1(VEIL("x", (double)(x)))
|
||||
#define expm1f(x) expm1f(VEIL("x", (float)(x)))
|
||||
|
||||
TEST(expm1l, test) {
|
||||
EXPECT_STREQ("1.718281828459045", gc(xdtoal(expm1l(1))));
|
||||
EXPECT_STREQ("1.718281828459045", gc(xdtoal(expl(1) - 1)));
|
||||
EXPECT_STREQ("0", gc(xdtoal(expm1l(0))));
|
||||
EXPECT_STREQ("0", gc(xdtoal(expm1l(-0.))));
|
||||
EXPECT_STREQ("NAN", gc(xdtoal(expm1l(NAN))));
|
||||
EXPECT_STREQ("-1", gc(xdtoal(expm1l(-INFINITY))));
|
||||
EXPECT_STREQ("INFINITY", gc(xdtoal(expm1l(INFINITY))));
|
||||
/* EXPECT_STREQ("-INFINITY", gc(xdtoal(expm1l(-132098844872390)))); */
|
||||
/* EXPECT_STREQ("INFINITY", gc(xdtoal(expm1l(132098844872390)))); */
|
||||
}
|
||||
|
||||
TEST(expm1, test) {
|
||||
EXPECT_STREQ("0", gc(xdtoa(expm1(0))));
|
||||
EXPECT_STREQ("0", gc(xdtoa(expm1(-0.))));
|
||||
EXPECT_STREQ("NAN", gc(xdtoa(expm1(NAN))));
|
||||
EXPECT_STREQ("-1", gc(xdtoa(expm1(-INFINITY))));
|
||||
EXPECT_STREQ("INFINITY", gc(xdtoa(expm1(INFINITY))));
|
||||
/* EXPECT_STREQ("-INFINITY", gc(xdtoa(expm1(-132098844872390)))); */
|
||||
/* EXPECT_STREQ("INFINITY", gc(xdtoa(expm1(132098844872390)))); */
|
||||
}
|
||||
|
||||
TEST(expm1f, test) {
|
||||
EXPECT_STREQ("0", gc(xdtoaf(expm1f(0))));
|
||||
EXPECT_STREQ("0", gc(xdtoaf(expm1f(-0.))));
|
||||
EXPECT_STREQ("NAN", gc(xdtoaf(expm1f(NAN))));
|
||||
EXPECT_STREQ("-1", gc(xdtoaf(expm1f(-INFINITY))));
|
||||
EXPECT_STREQ("INFINITY", gc(xdtoaf(expm1f(INFINITY))));
|
||||
/* EXPECT_STREQ("-INFINITY", gc(xdtoaf(expm1f(-132098844872390)))); */
|
||||
/* EXPECT_STREQ("INFINITY", gc(xdtoaf(expm1f(132098844872390)))); */
|
||||
}
|
|
@ -17,9 +17,39 @@
|
|||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/math.h"
|
||||
#include "libc/runtime/gc.h"
|
||||
#include "libc/testlib/testlib.h"
|
||||
#include "libc/x/x.h"
|
||||
|
||||
#define fabsl(x) fabsl(VEIL("t", (long double)(x)))
|
||||
#define fabs(x) fabs(VEIL("x", (double)(x)))
|
||||
#define fabsf(x) fabsf(VEIL("x", (float)(x)))
|
||||
|
||||
TEST(fabsl, test) {
|
||||
EXPECT_STREQ("0", gc(xdtoal(fabsl(-0.))));
|
||||
EXPECT_STREQ("0", gc(xdtoal(fabsl(-0.))));
|
||||
EXPECT_STREQ("NAN", gc(xdtoal(fabsl(NAN))));
|
||||
EXPECT_STREQ("INFINITY", gc(xdtoal(fabsl(INFINITY))));
|
||||
EXPECT_STREQ("INFINITY", gc(xdtoal(fabsl(-INFINITY))));
|
||||
}
|
||||
|
||||
TEST(fabs, test) {
|
||||
EXPECT_STREQ("0", gc(xdtoa(fabs(-0.))));
|
||||
EXPECT_STREQ("0", gc(xdtoa(fabs(-0.))));
|
||||
EXPECT_STREQ("NAN", gc(xdtoa(fabs(NAN))));
|
||||
EXPECT_STREQ("INFINITY", gc(xdtoa(fabs(INFINITY))));
|
||||
EXPECT_STREQ("INFINITY", gc(xdtoa(fabs(-INFINITY))));
|
||||
}
|
||||
|
||||
TEST(fabsf, test) {
|
||||
EXPECT_STREQ("0", gc(xdtoaf(fabsf(-0.))));
|
||||
EXPECT_STREQ("0", gc(xdtoaf(fabsf(-0.))));
|
||||
EXPECT_STREQ("NAN", gc(xdtoaf(fabsf(NAN))));
|
||||
EXPECT_STREQ("INFINITY", gc(xdtoaf(fabsf(INFINITY))));
|
||||
EXPECT_STREQ("INFINITY", gc(xdtoaf(fabsf(-INFINITY))));
|
||||
}
|
||||
|
||||
TEST(fabs, stuff) {
|
||||
EXPECT_LDBL_EQ(3.14, fabs(3.14));
|
||||
EXPECT_LDBL_EQ(3.14, fabs(-3.14));
|
||||
EXPECT_EQ(1, !!isnan(fabs(NAN)));
|
||||
|
|
73
test/libc/tinymath/fmod_test.c
Normal file
73
test/libc/tinymath/fmod_test.c
Normal file
|
@ -0,0 +1,73 @@
|
|||
/*-*- 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/rand/rand.h"
|
||||
#include "libc/runtime/gc.h"
|
||||
#include "libc/testlib/ezbench.h"
|
||||
#include "libc/testlib/testlib.h"
|
||||
#include "libc/x/x.h"
|
||||
|
||||
int rando;
|
||||
|
||||
void SetUp(void) {
|
||||
rando = rand() & 0xffff;
|
||||
}
|
||||
|
||||
TEST(fmodl, test) {
|
||||
EXPECT_STREQ("0", gc(xdtoal(fmodl(0, rando))));
|
||||
EXPECT_STREQ("NAN", gc(xdtoal(fmodl(1, NAN))));
|
||||
EXPECT_STREQ("NAN", gc(xdtoal(fmodl(NAN, 1))));
|
||||
EXPECT_STREQ("-NAN", gc(xdtoal(fmodl(INFINITY, 1))));
|
||||
EXPECT_STREQ("-NAN", gc(xdtoal(fmodl(1, 0))));
|
||||
EXPECT_STREQ("8", gc(xdtoal(fmodl(8, 32))));
|
||||
EXPECT_STREQ("8e+100", gc(xdtoal(fmodl(8e100, 32e100))));
|
||||
EXPECT_STREQ("5.319372648326541e+255",
|
||||
gc(xdtoal(ldexpl(6381956970095103, 797))));
|
||||
EXPECT_STREQ(".09287409360354737",
|
||||
gc(xdtoal(fmodl(ldexpl(6381956970095103, 797), M_2_PI))));
|
||||
}
|
||||
|
||||
TEST(fmod, test) {
|
||||
EXPECT_STREQ("0", gc(xdtoa(fmod(0, rando))));
|
||||
EXPECT_STREQ("NAN", gc(xdtoa(fmod(1, NAN))));
|
||||
EXPECT_STREQ("NAN", gc(xdtoa(fmod(NAN, 1))));
|
||||
EXPECT_STREQ("-NAN", gc(xdtoa(fmod(INFINITY, 1))));
|
||||
EXPECT_STREQ("-NAN", gc(xdtoa(fmod(1, 0))));
|
||||
EXPECT_STREQ("8", gc(xdtoa(fmod(8, 32))));
|
||||
EXPECT_STREQ("8e+100", gc(xdtoa(fmod(8e100, 32e100))));
|
||||
EXPECT_STREQ("5.31937264832654e+255",
|
||||
gc(xdtoa(ldexp(6381956970095103, 797))));
|
||||
EXPECT_STREQ(".0928740936035474",
|
||||
gc(xdtoa(fmod(ldexp(6381956970095103, 797), M_2_PI))));
|
||||
}
|
||||
|
||||
TEST(fmodf, test) {
|
||||
EXPECT_STREQ("0", gc(xdtoaf(fmodf(0, rando))));
|
||||
EXPECT_STREQ("NAN", gc(xdtoaf(fmodf(1, NAN))));
|
||||
EXPECT_STREQ("NAN", gc(xdtoaf(fmodf(NAN, 1))));
|
||||
EXPECT_STREQ("-NAN", gc(xdtoaf(fmodf(INFINITY, 1))));
|
||||
EXPECT_STREQ("-NAN", gc(xdtoaf(fmodf(1, 0))));
|
||||
EXPECT_STREQ("8", gc(xdtoaf(fmodf(8, 32))));
|
||||
EXPECT_STREQ("8e+20", gc(xdtoaf(fmodf(8e20, 32e20))));
|
||||
}
|
||||
|
||||
BENCH(fmod, bench) {
|
||||
EZBENCH2("fmod eze", donothing, fmodl(8, 32));
|
||||
EZBENCH2("fmod big", donothing, fmodl(5.319372648326541e+255, M_2_PI));
|
||||
}
|
|
@ -21,6 +21,11 @@
|
|||
#include "libc/testlib/testlib.h"
|
||||
#include "libc/x/x.h"
|
||||
|
||||
#define hypotl(x, y) \
|
||||
hypotl(VEIL("t", (long double)(x)), VEIL("t", (long double)(y)))
|
||||
#define hypot(x, y) hypot(VEIL("x", (double)(x)), VEIL("x", (double)(y)))
|
||||
#define hypotf(x, y) hypotf(VEIL("x", (float)(x)), VEIL("x", (float)(y)))
|
||||
|
||||
TEST(hypot, test) {
|
||||
EXPECT_STREQ("0", gc(xdtoa(hypot(0, 0))));
|
||||
EXPECT_STREQ("3", gc(xdtoa(hypot(3, 0))));
|
||||
|
@ -33,12 +38,12 @@ TEST(hypot, test) {
|
|||
EXPECT_STREQ("5", gc(xdtoa(hypot(4, -3))));
|
||||
EXPECT_STREQ("5", gc(xdtoa(hypot(-3, -4))));
|
||||
EXPECT_STREQ("5", gc(xdtoa(hypot(-4, -3))));
|
||||
EXPECT_STREQ("1.414213562373095", gc(xdtoa(hypot(1, 1))));
|
||||
EXPECT_STREQ("1.414213562373095", gc(xdtoa(hypot(1, -1))));
|
||||
EXPECT_STREQ("1.414213562373095", gc(xdtoa(hypot(-1, 1))));
|
||||
EXPECT_STREQ("1.414213626012708", gc(xdtoa(hypot(1.0000001, .99999999))));
|
||||
EXPECT_STREQ("1.414213626012708", gc(xdtoa(hypot(.99999999, 1.0000001))));
|
||||
EXPECT_STREQ("1.414213562373095e+154", gc(xdtoa(hypot(1e154, 1e154))));
|
||||
EXPECT_STREQ("1.4142135623731", gc(xdtoa(hypot(1, 1))));
|
||||
EXPECT_STREQ("1.4142135623731", gc(xdtoa(hypot(1, -1))));
|
||||
EXPECT_STREQ("1.4142135623731", gc(xdtoa(hypot(-1, 1))));
|
||||
EXPECT_STREQ("1.41421362601271", gc(xdtoa(hypot(1.0000001, .99999999))));
|
||||
EXPECT_STREQ("1.41421362601271", gc(xdtoa(hypot(.99999999, 1.0000001))));
|
||||
EXPECT_STREQ("1.4142135623731e+154", gc(xdtoa(hypot(1e154, 1e154))));
|
||||
EXPECT_STREQ("NAN", gc(xdtoa(hypot(0, NAN))));
|
||||
EXPECT_STREQ("NAN", gc(xdtoa(hypot(NAN, 0))));
|
||||
EXPECT_STREQ("NAN", gc(xdtoa(hypot(NAN, NAN))));
|
||||
|
@ -61,12 +66,12 @@ TEST(hypotf, test) {
|
|||
EXPECT_STREQ("5", gc(xdtoa(hypotf(4, -3))));
|
||||
EXPECT_STREQ("5", gc(xdtoa(hypotf(-3, -4))));
|
||||
EXPECT_STREQ("5", gc(xdtoa(hypotf(-4, -3))));
|
||||
EXPECT_STREQ("1.414214", gc(xdtoaf(hypotf(1, 1))));
|
||||
EXPECT_STREQ("1.414214", gc(xdtoaf(hypotf(1, -1))));
|
||||
EXPECT_STREQ("1.414214", gc(xdtoaf(hypotf(-1, 1))));
|
||||
EXPECT_STREQ("1.414214", gc(xdtoaf(hypotf(1.000001, 0.999999))));
|
||||
EXPECT_STREQ("1.414214", gc(xdtoaf(hypotf(0.999999, 1.000001))));
|
||||
EXPECT_STREQ("1.414214e+38", gc(xdtoaf(hypotf(1e38, 1e38))));
|
||||
EXPECT_STREQ("1.41421", gc(xdtoaf(hypotf(1, 1))));
|
||||
EXPECT_STREQ("1.41421", gc(xdtoaf(hypotf(1, -1))));
|
||||
EXPECT_STREQ("1.41421", gc(xdtoaf(hypotf(-1, 1))));
|
||||
EXPECT_STREQ("1.41421", gc(xdtoaf(hypotf(1.000001, 0.999999))));
|
||||
EXPECT_STREQ("1.41421", gc(xdtoaf(hypotf(0.999999, 1.000001))));
|
||||
EXPECT_STREQ("1.41421e+38", gc(xdtoaf(hypotf(1e38, 1e38))));
|
||||
EXPECT_STREQ("NAN", gc(xdtoaf(hypotf(0, NAN))));
|
||||
EXPECT_STREQ("NAN", gc(xdtoaf(hypotf(NAN, 0))));
|
||||
EXPECT_STREQ("NAN", gc(xdtoaf(hypotf(NAN, NAN))));
|
||||
|
@ -78,31 +83,31 @@ TEST(hypotf, test) {
|
|||
}
|
||||
|
||||
TEST(hypotll, test) {
|
||||
EXPECT_STREQ("0", gc(xdtoa(hypotl(0, 0))));
|
||||
EXPECT_STREQ("3", gc(xdtoa(hypotl(3, 0))));
|
||||
EXPECT_STREQ("3", gc(xdtoa(hypotl(0, 3))));
|
||||
EXPECT_STREQ("5", gc(xdtoa(hypotl(3, 4))));
|
||||
EXPECT_STREQ("5", gc(xdtoa(hypotl(4, 3))));
|
||||
EXPECT_STREQ("5", gc(xdtoa(hypotl(3, -4))));
|
||||
EXPECT_STREQ("5", gc(xdtoa(hypotl(-4, 3))));
|
||||
EXPECT_STREQ("5", gc(xdtoa(hypotl(-3, 4))));
|
||||
EXPECT_STREQ("5", gc(xdtoa(hypotl(4, -3))));
|
||||
EXPECT_STREQ("5", gc(xdtoa(hypotl(-3, -4))));
|
||||
EXPECT_STREQ("5", gc(xdtoa(hypotl(-4, -3))));
|
||||
EXPECT_STREQ("1.414213562373095", gc(xdtoa(hypotl(1, 1))));
|
||||
EXPECT_STREQ("1.414213562373095", gc(xdtoa(hypotl(1, -1))));
|
||||
EXPECT_STREQ("1.414213562373095", gc(xdtoa(hypotl(-1, 1))));
|
||||
EXPECT_STREQ("1.414213626012708", gc(xdtoa(hypotl(1.0000001, .99999999))));
|
||||
EXPECT_STREQ("1.414213626012708", gc(xdtoa(hypotl(.99999999, 1.0000001))));
|
||||
EXPECT_STREQ("1.414213562373095e+4931", gc(xdtoa(hypotl(1e4931L, 1e4931L))));
|
||||
EXPECT_STREQ("NAN", gc(xdtoa(hypotl(0, NAN))));
|
||||
EXPECT_STREQ("NAN", gc(xdtoa(hypotl(NAN, 0))));
|
||||
EXPECT_STREQ("NAN", gc(xdtoa(hypotl(NAN, NAN))));
|
||||
EXPECT_STREQ("INFINITY", gc(xdtoa(hypotl(INFINITY, 0))));
|
||||
EXPECT_STREQ("INFINITY", gc(xdtoa(hypotl(0, INFINITY))));
|
||||
EXPECT_STREQ("INFINITY", gc(xdtoa(hypotl(INFINITY, NAN))));
|
||||
EXPECT_STREQ("INFINITY", gc(xdtoa(hypotl(NAN, INFINITY))));
|
||||
EXPECT_STREQ("INFINITY", gc(xdtoa(hypotl(INFINITY, INFINITY))));
|
||||
EXPECT_STREQ("0", gc(xdtoal(hypotl(0, 0))));
|
||||
EXPECT_STREQ("3", gc(xdtoal(hypotl(3, 0))));
|
||||
EXPECT_STREQ("3", gc(xdtoal(hypotl(0, 3))));
|
||||
EXPECT_STREQ("5", gc(xdtoal(hypotl(3, 4))));
|
||||
EXPECT_STREQ("5", gc(xdtoal(hypotl(4, 3))));
|
||||
EXPECT_STREQ("5", gc(xdtoal(hypotl(3, -4))));
|
||||
EXPECT_STREQ("5", gc(xdtoal(hypotl(-4, 3))));
|
||||
EXPECT_STREQ("5", gc(xdtoal(hypotl(-3, 4))));
|
||||
EXPECT_STREQ("5", gc(xdtoal(hypotl(4, -3))));
|
||||
EXPECT_STREQ("5", gc(xdtoal(hypotl(-3, -4))));
|
||||
EXPECT_STREQ("5", gc(xdtoal(hypotl(-4, -3))));
|
||||
EXPECT_STREQ("1.414213562373095", gc(xdtoal(hypotl(1, 1))));
|
||||
EXPECT_STREQ("1.414213562373095", gc(xdtoal(hypotl(1, -1))));
|
||||
EXPECT_STREQ("1.414213562373095", gc(xdtoal(hypotl(-1, 1))));
|
||||
EXPECT_STREQ("1.414213626012708", gc(xdtoal(hypotl(1.0000001, .99999999))));
|
||||
EXPECT_STREQ("1.414213626012708", gc(xdtoal(hypotl(.99999999, 1.0000001))));
|
||||
EXPECT_STREQ("1.414213562373095e+4931", gc(xdtoal(hypotl(1e4931L, 1e4931L))));
|
||||
EXPECT_STREQ("NAN", gc(xdtoal(hypotl(0, NAN))));
|
||||
EXPECT_STREQ("NAN", gc(xdtoal(hypotl(NAN, 0))));
|
||||
EXPECT_STREQ("NAN", gc(xdtoal(hypotl(NAN, NAN))));
|
||||
EXPECT_STREQ("INFINITY", gc(xdtoal(hypotl(INFINITY, 0))));
|
||||
EXPECT_STREQ("INFINITY", gc(xdtoal(hypotl(0, INFINITY))));
|
||||
EXPECT_STREQ("INFINITY", gc(xdtoal(hypotl(INFINITY, NAN))));
|
||||
EXPECT_STREQ("INFINITY", gc(xdtoal(hypotl(NAN, INFINITY))));
|
||||
EXPECT_STREQ("INFINITY", gc(xdtoal(hypotl(INFINITY, INFINITY))));
|
||||
}
|
||||
|
||||
BENCH(hypot, bench) {
|
||||
|
|
|
@ -17,12 +17,83 @@
|
|||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/math.h"
|
||||
#include "libc/rand/rand.h"
|
||||
#include "libc/runtime/gc.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
#include "libc/testlib/testlib.h"
|
||||
#include "libc/x/x.h"
|
||||
|
||||
int rando;
|
||||
|
||||
void SetUp(void) {
|
||||
rando = rand() & 0xffff;
|
||||
}
|
||||
|
||||
TEST(ldexpl, test) {
|
||||
EXPECT_EQ(rando, ldexpl(rando, 0));
|
||||
EXPECT_STREQ("NAN", gc(xdtoal(ldexpl(NAN, 0))));
|
||||
EXPECT_STREQ("-NAN", gc(xdtoal(ldexpl(-NAN, 0))));
|
||||
EXPECT_STREQ("INFINITY", gc(xdtoal(ldexpl(INFINITY, 0))));
|
||||
EXPECT_STREQ("-INFINITY", gc(xdtoal(ldexpl(-INFINITY, 0))));
|
||||
EXPECT_STREQ("NAN", gc(xdtoal(ldexpl(NAN, 1))));
|
||||
EXPECT_STREQ("-NAN", gc(xdtoal(ldexpl(-NAN, 1))));
|
||||
EXPECT_STREQ("INFINITY", gc(xdtoal(ldexpl(INFINITY, 1))));
|
||||
EXPECT_STREQ("-INFINITY", gc(xdtoal(ldexpl(-INFINITY, 1))));
|
||||
EXPECT_STREQ("16384", gc(xdtoal(log2l(LDBL_MAX))));
|
||||
EXPECT_STREQ(".00390625", gc(xdtoal(ldexpl(1, -8))));
|
||||
EXPECT_STREQ("0", gc(xdtoal(ldexpl(0, -8))));
|
||||
EXPECT_STREQ("0", gc(xdtoal(ldexpl(0, 8))));
|
||||
EXPECT_STREQ("256", gc(xdtoal(ldexpl(1, 8))));
|
||||
EXPECT_STREQ("512", gc(xdtoal(ldexpl(2, 8))));
|
||||
EXPECT_STREQ("768", gc(xdtoal(ldexpl(3, 8))));
|
||||
EXPECT_STREQ("6.997616471358197e+3461", gc(xdtoal(ldexpl(1, 11500))));
|
||||
EXPECT_STREQ("INFINITY", gc(xdtoal(ldexpl(1, 999999))));
|
||||
EXPECT_STREQ("0", gc(xdtoal(ldexpl(1, -999999))));
|
||||
}
|
||||
|
||||
TEST(ldexp, test) {
|
||||
EXPECT_EQ(rando, ldexp(rando, 0));
|
||||
EXPECT_STREQ("NAN", gc(xdtoa(ldexp(NAN, 0))));
|
||||
EXPECT_STREQ("-NAN", gc(xdtoa(ldexp(-NAN, 0))));
|
||||
EXPECT_STREQ("INFINITY", gc(xdtoa(ldexp(INFINITY, 0))));
|
||||
EXPECT_STREQ("-INFINITY", gc(xdtoa(ldexp(-INFINITY, 0))));
|
||||
EXPECT_STREQ("NAN", gc(xdtoa(ldexp(NAN, 1))));
|
||||
EXPECT_STREQ("-NAN", gc(xdtoa(ldexp(-NAN, 1))));
|
||||
EXPECT_STREQ("INFINITY", gc(xdtoa(ldexp(INFINITY, 1))));
|
||||
EXPECT_STREQ("-INFINITY", gc(xdtoa(ldexp(-INFINITY, 1))));
|
||||
EXPECT_STREQ("16384", gc(xdtoa(log2l(LDBL_MAX))));
|
||||
EXPECT_STREQ(".00390625", gc(xdtoa(ldexp(1, -8))));
|
||||
EXPECT_STREQ("0", gc(xdtoa(ldexp(0, -8))));
|
||||
EXPECT_STREQ("0", gc(xdtoa(ldexp(0, 8))));
|
||||
EXPECT_STREQ("256", gc(xdtoa(ldexp(1, 8))));
|
||||
EXPECT_STREQ("512", gc(xdtoa(ldexp(2, 8))));
|
||||
EXPECT_STREQ("768", gc(xdtoa(ldexp(3, 8))));
|
||||
EXPECT_STREQ("INFINITY", gc(xdtoa(ldexp(1, 999999))));
|
||||
EXPECT_STREQ("0", gc(xdtoa(ldexp(1, -999999))));
|
||||
}
|
||||
|
||||
TEST(ldexpf, test) {
|
||||
EXPECT_EQ(rando, ldexpf(rando, 0));
|
||||
EXPECT_STREQ("NAN", gc(xdtoaf(ldexpf(NAN, 0))));
|
||||
EXPECT_STREQ("-NAN", gc(xdtoaf(ldexpf(-NAN, 0))));
|
||||
EXPECT_STREQ("INFINITY", gc(xdtoaf(ldexpf(INFINITY, 0))));
|
||||
EXPECT_STREQ("-INFINITY", gc(xdtoaf(ldexpf(-INFINITY, 0))));
|
||||
EXPECT_STREQ("NAN", gc(xdtoaf(ldexpf(NAN, 1))));
|
||||
EXPECT_STREQ("-NAN", gc(xdtoaf(ldexpf(-NAN, 1))));
|
||||
EXPECT_STREQ("INFINITY", gc(xdtoaf(ldexpf(INFINITY, 1))));
|
||||
EXPECT_STREQ("-INFINITY", gc(xdtoaf(ldexpf(-INFINITY, 1))));
|
||||
EXPECT_STREQ("16384", gc(xdtoaf(log2l(LDBL_MAX))));
|
||||
EXPECT_STREQ(".00390625", gc(xdtoaf(ldexpf(1, -8))));
|
||||
EXPECT_STREQ("0", gc(xdtoaf(ldexpf(0, -8))));
|
||||
EXPECT_STREQ("0", gc(xdtoaf(ldexpf(0, 8))));
|
||||
EXPECT_STREQ("256", gc(xdtoaf(ldexpf(1, 8))));
|
||||
EXPECT_STREQ("512", gc(xdtoaf(ldexpf(2, 8))));
|
||||
EXPECT_STREQ("768", gc(xdtoaf(ldexpf(3, 8))));
|
||||
EXPECT_STREQ("INFINITY", gc(xdtoaf(ldexpf(1, 999999))));
|
||||
EXPECT_STREQ("0", gc(xdtoaf(ldexpf(1, -999999))));
|
||||
}
|
||||
|
||||
TEST(ldexp, stuff) {
|
||||
volatile int twopow = 5;
|
||||
volatile double pi = 3.14;
|
||||
ASSERT_STREQ("100.48", gc(xasprintf("%.2f", ldexp(pi, twopow))));
|
||||
|
|
47
test/libc/tinymath/log1p_test.c
Normal file
47
test/libc/tinymath/log1p_test.c
Normal file
|
@ -0,0 +1,47 @@
|
|||
/*-*- 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/testlib.h"
|
||||
#include "libc/x/x.h"
|
||||
|
||||
TEST(log1pl, test) {
|
||||
EXPECT_STREQ("1", gc(xdtoal(log1pl(1.71828182845904523536L))));
|
||||
EXPECT_STREQ("NAN", gc(xdtoal(log1pl(NAN))));
|
||||
EXPECT_STREQ("INFINITY", gc(xdtoal(log1pl(INFINITY))));
|
||||
EXPECT_STREQ("-INFINITY", gc(xdtoal(log1pl(-1))));
|
||||
EXPECT_STREQ("-NAN", gc(xdtoal(log1pl(-2))));
|
||||
}
|
||||
|
||||
TEST(log1p, test) {
|
||||
EXPECT_STREQ("1", gc(xdtoa(log1p(M_E - 1))));
|
||||
EXPECT_STREQ("2", gc(xdtoa(log1p(M_E * M_E - 1))));
|
||||
EXPECT_STREQ("NAN", gc(xdtoa(log1p(NAN))));
|
||||
EXPECT_STREQ("INFINITY", gc(xdtoa(log1p(INFINITY))));
|
||||
EXPECT_STREQ("-INFINITY", gc(xdtoa(log1p(-1))));
|
||||
EXPECT_STREQ("-NAN", gc(xdtoa(log1p(-2))));
|
||||
}
|
||||
|
||||
TEST(log1pf, test) {
|
||||
EXPECT_STREQ("1", gc(xdtoaf(log1pf(M_E - 1))));
|
||||
EXPECT_STREQ("NAN", gc(xdtoaf(log1pf(NAN))));
|
||||
EXPECT_STREQ("INFINITY", gc(xdtoaf(log1pf(INFINITY))));
|
||||
EXPECT_STREQ("-INFINITY", gc(xdtoaf(log1pf(-1))));
|
||||
EXPECT_STREQ("-NAN", gc(xdtoaf(log1pf(-2))));
|
||||
}
|
56
test/libc/tinymath/log2_test.c
Normal file
56
test/libc/tinymath/log2_test.c
Normal file
|
@ -0,0 +1,56 @@
|
|||
/*-*- 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/testlib.h"
|
||||
#include "libc/x/x.h"
|
||||
|
||||
TEST(log2l, test) {
|
||||
EXPECT_STREQ("1", gc(xdtoal(log2l(2))));
|
||||
EXPECT_STREQ("NAN", gc(xdtoal(log2l(NAN))));
|
||||
EXPECT_STREQ("0", gc(xdtoal(log2l(1))));
|
||||
EXPECT_STREQ("INFINITY", gc(xdtoal(log2l(INFINITY))));
|
||||
EXPECT_STREQ("-INFINITY", gc(xdtoal(log2l(0))));
|
||||
EXPECT_STREQ("-INFINITY", gc(xdtoal(log2l(-0.))));
|
||||
EXPECT_STREQ("-NAN", gc(xdtoal(log2l(-1))));
|
||||
EXPECT_STREQ("-NAN", gc(xdtoal(log2l(-2))));
|
||||
}
|
||||
|
||||
TEST(log2, test) {
|
||||
EXPECT_STREQ("1", gc(xdtoa(log2(2))));
|
||||
EXPECT_STREQ("2", gc(xdtoa(log2(2 * 2))));
|
||||
EXPECT_STREQ("NAN", gc(xdtoa(log2(NAN))));
|
||||
EXPECT_STREQ("0", gc(xdtoa(log2(1))));
|
||||
EXPECT_STREQ("INFINITY", gc(xdtoa(log2(INFINITY))));
|
||||
EXPECT_STREQ("-INFINITY", gc(xdtoa(log2(0))));
|
||||
EXPECT_STREQ("-INFINITY", gc(xdtoa(log2(-0.))));
|
||||
EXPECT_STREQ("-NAN", gc(xdtoa(log2(-1))));
|
||||
EXPECT_STREQ("-NAN", gc(xdtoa(log2(-2))));
|
||||
}
|
||||
|
||||
TEST(log2f, test) {
|
||||
EXPECT_STREQ("1", gc(xdtoaf(log2f(2))));
|
||||
EXPECT_STREQ("NAN", gc(xdtoaf(log2f(NAN))));
|
||||
EXPECT_STREQ("0", gc(xdtoaf(log2f(1))));
|
||||
EXPECT_STREQ("INFINITY", gc(xdtoaf(log2f(INFINITY))));
|
||||
EXPECT_STREQ("-INFINITY", gc(xdtoaf(log2f(0))));
|
||||
EXPECT_STREQ("-INFINITY", gc(xdtoaf(log2f(-0.))));
|
||||
EXPECT_STREQ("-NAN", gc(xdtoaf(log2f(-1))));
|
||||
EXPECT_STREQ("-NAN", gc(xdtoaf(log2f(-2))));
|
||||
}
|
56
test/libc/tinymath/log_test.c
Normal file
56
test/libc/tinymath/log_test.c
Normal file
|
@ -0,0 +1,56 @@
|
|||
/*-*- 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/testlib.h"
|
||||
#include "libc/x/x.h"
|
||||
|
||||
TEST(logl, test) {
|
||||
EXPECT_STREQ("1", gc(xdtoal(logl(2.71828182845904523536L))));
|
||||
EXPECT_STREQ("NAN", gc(xdtoal(logl(NAN))));
|
||||
EXPECT_STREQ("0", gc(xdtoal(logl(1))));
|
||||
EXPECT_STREQ("INFINITY", gc(xdtoal(logl(INFINITY))));
|
||||
EXPECT_STREQ("-INFINITY", gc(xdtoal(logl(0))));
|
||||
EXPECT_STREQ("-INFINITY", gc(xdtoal(logl(-0.))));
|
||||
EXPECT_STREQ("-NAN", gc(xdtoal(logl(-1))));
|
||||
EXPECT_STREQ("-NAN", gc(xdtoal(logl(-2))));
|
||||
}
|
||||
|
||||
TEST(log, test) {
|
||||
EXPECT_STREQ("1", gc(xdtoa(log(M_E))));
|
||||
EXPECT_STREQ("2", gc(xdtoa(log(M_E * M_E))));
|
||||
EXPECT_STREQ("NAN", gc(xdtoa(log(NAN))));
|
||||
EXPECT_STREQ("0", gc(xdtoa(log(1))));
|
||||
EXPECT_STREQ("INFINITY", gc(xdtoa(log(INFINITY))));
|
||||
EXPECT_STREQ("-INFINITY", gc(xdtoa(log(0))));
|
||||
EXPECT_STREQ("-INFINITY", gc(xdtoa(log(-0.))));
|
||||
EXPECT_STREQ("-NAN", gc(xdtoa(log(-1))));
|
||||
EXPECT_STREQ("-NAN", gc(xdtoa(log(-2))));
|
||||
}
|
||||
|
||||
TEST(logf, test) {
|
||||
EXPECT_STREQ("1", gc(xdtoaf(logf(M_E))));
|
||||
EXPECT_STREQ("NAN", gc(xdtoaf(logf(NAN))));
|
||||
EXPECT_STREQ("0", gc(xdtoaf(logf(1))));
|
||||
EXPECT_STREQ("INFINITY", gc(xdtoaf(logf(INFINITY))));
|
||||
EXPECT_STREQ("-INFINITY", gc(xdtoaf(logf(0))));
|
||||
EXPECT_STREQ("-INFINITY", gc(xdtoaf(logf(-0.))));
|
||||
EXPECT_STREQ("-NAN", gc(xdtoaf(logf(-1))));
|
||||
EXPECT_STREQ("-NAN", gc(xdtoaf(logf(-2))));
|
||||
}
|
|
@ -16,39 +16,47 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/struct/sigaction.h"
|
||||
#include "libc/calls/struct/siginfo.h"
|
||||
#include "libc/calls/ucontext.h"
|
||||
#include "libc/math.h"
|
||||
#include "libc/runtime/gc.h"
|
||||
#include "libc/runtime/pc.internal.h"
|
||||
#include "libc/sysv/consts/sa.h"
|
||||
#include "libc/sysv/consts/sig.h"
|
||||
#include "libc/testlib/ezbench.h"
|
||||
#include "libc/testlib/testlib.h"
|
||||
#include "libc/x/x.h"
|
||||
|
||||
double powa(double x, double y) {
|
||||
return exp2(fmod(y * log2(x), 1)) * exp2(y);
|
||||
}
|
||||
|
||||
TEST(powl, testLongDouble) {
|
||||
EXPECT_TRUE(isnan(powl(-1, 1.1)));
|
||||
EXPECT_STREQ("1e+4932", gc(xdtoal(powl(10, 4932))));
|
||||
EXPECT_STREQ("INFINITY", gc(xdtoal(powl(10, 4933))));
|
||||
EXPECT_STREQ("0", gc(xdtoal(powl(10, -5000))));
|
||||
EXPECT_STREQ("1.063382396627933e+37", gc(xdtoal(powl(2, 123))));
|
||||
/* .4248496805467504836322459796959084815827285786480897 */
|
||||
EXPECT_STARTSWITH(".4248496805467504", gc(xdtoa(powl(0.7, 2.4))));
|
||||
EXPECT_STARTSWITH(".4248496805467504", gc(xdtoal(powl(0.7, 2.4))));
|
||||
}
|
||||
|
||||
TEST(powl, testDouble) {
|
||||
EXPECT_STARTSWITH(".4248496805467504", gc(xdtoa(pow(0.7, 2.4))));
|
||||
EXPECT_STREQ("1e+308", gc(xdtoa(pow(10, 308))));
|
||||
EXPECT_STREQ("INFINITY", gc(xdtoa(pow(10, 309))));
|
||||
EXPECT_STARTSWITH(".42484968054675", gc(xdtoa(pow(0.7, 2.4))));
|
||||
}
|
||||
|
||||
TEST(powl, testFloat) {
|
||||
EXPECT_STARTSWITH(".4248496", gc(xdtoa(powf(0.7f, 2.4f))));
|
||||
}
|
||||
|
||||
static long double do_powl(void) {
|
||||
return CONCEAL("t", powl(CONCEAL("t", 0.7), CONCEAL("t", 0.2)));
|
||||
}
|
||||
|
||||
static double do_pow(void) {
|
||||
return CONCEAL("x", pow(CONCEAL("x", 0.7), CONCEAL("x", 0.2)));
|
||||
}
|
||||
|
||||
static float do_powf(void) {
|
||||
return CONCEAL("x", powf(CONCEAL("x", 0.7f), CONCEAL("x", 0.2f)));
|
||||
}
|
||||
|
||||
BENCH(powl, bench) {
|
||||
EZBENCH2("powl", donothing, do_powl()); /* ~61ns */
|
||||
EZBENCH2("pow", donothing, do_pow()); /* ~64ns */
|
||||
EZBENCH2("powf", donothing, do_powf()); /* ~64ns */
|
||||
double _pow(double, double) asm("pow");
|
||||
float _powf(float, float) asm("powf");
|
||||
long double _powl(long double, long double) asm("powl");
|
||||
EZBENCH2("pow", donothing, _pow(.7, .2)); /* ~51ns */
|
||||
EZBENCH2("powf", donothing, _powf(.7, .2)); /* ~52ns */
|
||||
EZBENCH2("powl", donothing, _powl(.7, .2)); /* ~53ns */
|
||||
}
|
||||
|
|
|
@ -23,6 +23,10 @@
|
|||
#include "libc/testlib/testlib.h"
|
||||
#include "libc/x/x.h"
|
||||
|
||||
#define roundl(x) roundl(VEIL("t", (long double)(x)))
|
||||
#define round(x) round(VEIL("x", (double)(x)))
|
||||
#define roundf(x) roundf(VEIL("x", (float)(x)))
|
||||
|
||||
FIXTURE(intrin, disableHardwareExtensions) {
|
||||
memset((/*unconst*/ void *)kCpuids, 0, sizeof(kCpuids));
|
||||
}
|
||||
|
|
|
@ -22,21 +22,58 @@
|
|||
#include "libc/testlib/testlib.h"
|
||||
#include "libc/x/x.h"
|
||||
|
||||
char buf[32];
|
||||
#define sinl(x) sinl(VEIL("t", (long double)(x)))
|
||||
#define sin(x) sin(VEIL("x", (double)(x)))
|
||||
#define sinf(x) sinf(VEIL("x", (float)(x)))
|
||||
|
||||
TEST(sinl, testLongDouble) {
|
||||
EXPECT_STREQ(".479425538604203", gc(xdtoa(sinl(.5))));
|
||||
EXPECT_STREQ("-.479425538604203", gc(xdtoa(sinl(-.5))));
|
||||
void SetUp(void) {
|
||||
/* 8087 FPU Control Word
|
||||
IM: Invalid Operation ───────────────┐
|
||||
DM: Denormal Operand ───────────────┐│
|
||||
ZM: Zero Divide ───────────────────┐││
|
||||
OM: Overflow ─────────────────────┐│││
|
||||
UM: Underflow ───────────────────┐││││
|
||||
PM: Precision ──────────────────┐│││││
|
||||
PC: Precision Control ────────┐ ││││││
|
||||
{float,∅,double,long double} │ ││││││
|
||||
RC: Rounding Control ───────┐ │ ││││││
|
||||
{even, →-∞, →+∞, →0} │┌┤ ││││││
|
||||
┌┤││ ││││││
|
||||
d││││rr││││││*/
|
||||
int x87cw = 0b0000000000000000001101100001;
|
||||
asm volatile("fldcw\t%0" : /* no outputs */ : "m"(x87cw));
|
||||
}
|
||||
|
||||
TEST(sinl, testDouble) {
|
||||
TEST(sinl, test) {
|
||||
EXPECT_STREQ("NAN", gc(xdtoal(sinl(NAN))));
|
||||
EXPECT_STREQ("-NAN", gc(xdtoal(sinl(+INFINITY))));
|
||||
EXPECT_STREQ("-NAN", gc(xdtoal(sinl(-INFINITY))));
|
||||
EXPECT_STREQ(".479425538604203", gc(xdtoal(sinl(.5))));
|
||||
EXPECT_STREQ("-.479425538604203", gc(xdtoal(sinl(-.5))));
|
||||
EXPECT_STREQ(".8414709794048734", gc(xdtoal(sinl(.99999999))));
|
||||
/* EXPECT_STREQ("-.998836772397", gc(xdtoal(sinl(555555555555)))); */
|
||||
/* EXPECT_STREQ("1", gc(xdtoal(SINL(5.319372648326541e+255L)))); */
|
||||
}
|
||||
|
||||
TEST(sin, test) {
|
||||
EXPECT_TRUE(isnan(sin(NAN)));
|
||||
EXPECT_TRUE(isnan(sin(+INFINITY)));
|
||||
EXPECT_TRUE(isnan(sin(-INFINITY)));
|
||||
EXPECT_STREQ("NAN", gc(xdtoa(sin(NAN))));
|
||||
EXPECT_STREQ(".479425538604203", gc(xdtoa(sin(.5))));
|
||||
EXPECT_STREQ("-.479425538604203", gc(xdtoa(sin(-.5))));
|
||||
EXPECT_STREQ(".479425538604203", gc(xdtoa(sin(.5))));
|
||||
EXPECT_STREQ("-.479425538604203", gc(xdtoa(sin(-.5))));
|
||||
}
|
||||
|
||||
TEST(sinl, testFloat) {
|
||||
EXPECT_STARTSWITH(".4794255", gc(xdtoa(sinf(.5f))));
|
||||
EXPECT_STARTSWITH("-.4794255", gc(xdtoa(sinf(-.5f))));
|
||||
TEST(sinf, test) {
|
||||
EXPECT_TRUE(isnan(sinf(NAN)));
|
||||
EXPECT_TRUE(isnan(sinf(+INFINITY)));
|
||||
EXPECT_TRUE(isnan(sinf(-INFINITY)));
|
||||
EXPECT_STREQ("NAN", gc(xdtoaf(sinf(NAN))));
|
||||
EXPECT_STARTSWITH(".479426", gc(xdtoaf(sinf(.5f))));
|
||||
EXPECT_STARTSWITH("-.479426", gc(xdtoaf(sinf(-.5f))));
|
||||
EXPECT_STARTSWITH(".873283", gc(xdtoaf(sinf(555))));
|
||||
}
|
||||
|
||||
BENCH(sinl, bench) {
|
||||
|
|
50
test/libc/tinymath/sqrt_test.c
Normal file
50
test/libc/tinymath/sqrt_test.c
Normal file
|
@ -0,0 +1,50 @@
|
|||
/*-*- 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/testlib.h"
|
||||
#include "libc/x/x.h"
|
||||
|
||||
#define sqrtl(x) sqrtl(VEIL("t", (long double)(x)))
|
||||
#define sqrt(x) sqrt(VEIL("x", (double)(x)))
|
||||
#define sqrtf(x) sqrtf(VEIL("x", (float)(x)))
|
||||
|
||||
TEST(sqrtl, test) {
|
||||
EXPECT_STREQ("7", gc(xdtoal(sqrtl(7 * 7))));
|
||||
EXPECT_STREQ("NAN", gc(xdtoal(sqrtl(NAN))));
|
||||
EXPECT_STREQ("0", gc(xdtoal(sqrtl(0))));
|
||||
EXPECT_STREQ("INFINITY", gc(xdtoal(sqrtl(INFINITY))));
|
||||
EXPECT_STREQ("-NAN", gc(xdtoal(sqrtl(-1))));
|
||||
}
|
||||
|
||||
TEST(sqrt, test) {
|
||||
EXPECT_STREQ("7", gc(xdtoa(sqrt(7 * 7))));
|
||||
EXPECT_STREQ("NAN", gc(xdtoa(sqrt(NAN))));
|
||||
EXPECT_STREQ("0", gc(xdtoa(sqrt(0))));
|
||||
EXPECT_STREQ("INFINITY", gc(xdtoa(sqrt(INFINITY))));
|
||||
EXPECT_STREQ("-NAN", gc(xdtoa(sqrt(-1))));
|
||||
}
|
||||
|
||||
TEST(sqrtf, test) {
|
||||
EXPECT_STREQ("7", gc(xdtoaf(sqrtf(7 * 7))));
|
||||
EXPECT_STREQ("NAN", gc(xdtoaf(sqrtf(NAN))));
|
||||
EXPECT_STREQ("0", gc(xdtoaf(sqrtf(0))));
|
||||
EXPECT_STREQ("INFINITY", gc(xdtoaf(sqrtf(INFINITY))));
|
||||
EXPECT_STREQ("-NAN", gc(xdtoaf(sqrtf(-1))));
|
||||
}
|
|
@ -23,13 +23,16 @@ TEST_LIBC_TINYMATH_CHECKS = \
|
|||
$(TEST_LIBC_TINYMATH_SRCS_TEST:%.c=o/$(MODE)/%.com.runs)
|
||||
|
||||
TEST_LIBC_TINYMATH_DIRECTDEPS = \
|
||||
LIBC_CALLS \
|
||||
LIBC_FMT \
|
||||
LIBC_INTRIN \
|
||||
LIBC_MEM \
|
||||
LIBC_NEXGEN32E \
|
||||
LIBC_RAND \
|
||||
LIBC_RUNTIME \
|
||||
LIBC_STR \
|
||||
LIBC_STUBS \
|
||||
LIBC_SYSV \
|
||||
LIBC_TESTLIB \
|
||||
LIBC_TINYMATH \
|
||||
LIBC_UNICODE \
|
||||
|
@ -52,7 +55,7 @@ o/$(MODE)/test/libc/tinymath/%.com.dbg: \
|
|||
@$(APELINK)
|
||||
|
||||
$(TEST_LIBC_TINYMATH_OBJS): \
|
||||
DEFAULT_CCFLAGS += \
|
||||
OVERRIDE_CFLAGS += \
|
||||
-fno-builtin
|
||||
|
||||
.PHONY: o/$(MODE)/test/libc/tinymath
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue