mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-22 21:32:31 +00:00
parent
32e289b1d8
commit
9367253b4d
15 changed files with 390 additions and 124 deletions
55
test/libc/tinymath/ceil_test.c
Normal file
55
test/libc/tinymath/ceil_test.c
Normal file
|
@ -0,0 +1,55 @@
|
|||
/*-*- 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(ceil, test) {
|
||||
EXPECT_STREQ("3", gc(xdtoa(ceil(3))));
|
||||
EXPECT_STREQ("4", gc(xdtoa(ceil(3.14))));
|
||||
EXPECT_STREQ("-3", gc(xdtoa(ceil(-3.14))));
|
||||
EXPECT_STREQ("-0", gc(xdtoa(ceil(-0.))));
|
||||
EXPECT_STREQ("NAN", gc(xdtoa(ceil(NAN))));
|
||||
EXPECT_STREQ("-NAN", gc(xdtoa(ceil(-NAN))));
|
||||
EXPECT_STREQ("INFINITY", gc(xdtoa(ceil(INFINITY))));
|
||||
EXPECT_STREQ("-INFINITY", gc(xdtoa(ceil(-INFINITY))));
|
||||
}
|
||||
|
||||
TEST(ceilf, test) {
|
||||
EXPECT_STREQ("3", gc(xdtoaf(ceilf(3))));
|
||||
EXPECT_STREQ("4", gc(xdtoaf(ceilf(3.14))));
|
||||
EXPECT_STREQ("-3", gc(xdtoaf(ceilf(-3.14))));
|
||||
EXPECT_STREQ("-0", gc(xdtoaf(ceilf(-0.))));
|
||||
EXPECT_STREQ("NAN", gc(xdtoaf(ceilf(NAN))));
|
||||
EXPECT_STREQ("-NAN", gc(xdtoaf(ceilf(-NAN))));
|
||||
EXPECT_STREQ("INFINITY", gc(xdtoaf(ceilf(INFINITY))));
|
||||
EXPECT_STREQ("-INFINITY", gc(xdtoaf(ceilf(-INFINITY))));
|
||||
}
|
||||
|
||||
TEST(ceill, test) {
|
||||
EXPECT_STREQ("3", gc(xdtoal(ceill(3))));
|
||||
EXPECT_STREQ("4", gc(xdtoal(ceill(3.14))));
|
||||
EXPECT_STREQ("-3", gc(xdtoal(ceill(-3.14))));
|
||||
EXPECT_STREQ("-0", gc(xdtoal(ceill(-0.))));
|
||||
EXPECT_STREQ("NAN", gc(xdtoal(ceill(NAN))));
|
||||
EXPECT_STREQ("-NAN", gc(xdtoal(ceill(-NAN))));
|
||||
EXPECT_STREQ("INFINITY", gc(xdtoal(ceill(INFINITY))));
|
||||
EXPECT_STREQ("-INFINITY", gc(xdtoal(ceill(-INFINITY))));
|
||||
}
|
28
test/libc/tinymath/exp2l_test.c
Normal file
28
test/libc/tinymath/exp2l_test.c
Normal file
|
@ -0,0 +1,28 @@
|
|||
/*-*- 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(exp2l, test) {
|
||||
EXPECT_STREQ("16", gc(xdtoal(exp2l(4))));
|
||||
EXPECT_STREQ("16", gc(xdtoa(exp2(4))));
|
||||
EXPECT_STREQ("16", gc(xdtoaf(exp2f(4))));
|
||||
}
|
55
test/libc/tinymath/floor_test.c
Normal file
55
test/libc/tinymath/floor_test.c
Normal file
|
@ -0,0 +1,55 @@
|
|||
/*-*- 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(floor, test) {
|
||||
EXPECT_STREQ("3", gc(xdtoa(floor(3))));
|
||||
EXPECT_STREQ("3", gc(xdtoa(floor(3.14))));
|
||||
EXPECT_STREQ("-4", gc(xdtoa(floor(-3.14))));
|
||||
EXPECT_STREQ("-0", gc(xdtoa(floor(-0.))));
|
||||
EXPECT_STREQ("NAN", gc(xdtoa(floor(NAN))));
|
||||
EXPECT_STREQ("-NAN", gc(xdtoa(floor(-NAN))));
|
||||
EXPECT_STREQ("INFINITY", gc(xdtoa(floor(INFINITY))));
|
||||
EXPECT_STREQ("-INFINITY", gc(xdtoa(floor(-INFINITY))));
|
||||
}
|
||||
|
||||
TEST(floorf, test) {
|
||||
EXPECT_STREQ("3", gc(xdtoaf(floorf(3))));
|
||||
EXPECT_STREQ("3", gc(xdtoaf(floorf(3.14))));
|
||||
EXPECT_STREQ("-4", gc(xdtoaf(floorf(-3.14))));
|
||||
EXPECT_STREQ("-0", gc(xdtoaf(floorf(-0.))));
|
||||
EXPECT_STREQ("NAN", gc(xdtoaf(floorf(NAN))));
|
||||
EXPECT_STREQ("-NAN", gc(xdtoaf(floorf(-NAN))));
|
||||
EXPECT_STREQ("INFINITY", gc(xdtoaf(floorf(INFINITY))));
|
||||
EXPECT_STREQ("-INFINITY", gc(xdtoaf(floorf(-INFINITY))));
|
||||
}
|
||||
|
||||
TEST(floorl, test) {
|
||||
EXPECT_STREQ("3", gc(xdtoal(floorl(3))));
|
||||
EXPECT_STREQ("3", gc(xdtoal(floorl(3.14))));
|
||||
EXPECT_STREQ("-4", gc(xdtoal(floorl(-3.14))));
|
||||
EXPECT_STREQ("-0", gc(xdtoal(floorl(-0.))));
|
||||
EXPECT_STREQ("NAN", gc(xdtoal(floorl(NAN))));
|
||||
EXPECT_STREQ("-NAN", gc(xdtoal(floorl(-NAN))));
|
||||
EXPECT_STREQ("INFINITY", gc(xdtoal(floorl(INFINITY))));
|
||||
EXPECT_STREQ("-INFINITY", gc(xdtoal(floorl(-INFINITY))));
|
||||
}
|
|
@ -22,33 +22,35 @@
|
|||
#include "libc/math.h"
|
||||
#include "libc/runtime/gc.h"
|
||||
#include "libc/runtime/pc.internal.h"
|
||||
#include "libc/stdio/stdio.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("27", gc(xdtoal(powl(3, 3))));
|
||||
EXPECT_STREQ("-27", gc(xdtoal(powl(-3, 3))));
|
||||
EXPECT_STREQ("-1", gc(xdtoal(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(xdtoal(powl(0.7, 2.4))));
|
||||
}
|
||||
|
||||
TEST(powl, testDouble) {
|
||||
EXPECT_STREQ("27", gc(xdtoa(pow(3, 3))));
|
||||
EXPECT_STREQ("-27", gc(xdtoa(pow(-3, 3))));
|
||||
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_STREQ("27", gc(xdtoaf(powf(3, 3))));
|
||||
EXPECT_STREQ("-27", gc(xdtoaf(powf(-3, 3))));
|
||||
EXPECT_STARTSWITH(".4248496", gc(xdtoa(powf(0.7f, 2.4f))));
|
||||
}
|
||||
|
||||
|
|
55
test/libc/tinymath/trunc_test.c
Normal file
55
test/libc/tinymath/trunc_test.c
Normal file
|
@ -0,0 +1,55 @@
|
|||
/*-*- 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(trunc, test) {
|
||||
EXPECT_STREQ("3", gc(xdtoa(trunc(3))));
|
||||
EXPECT_STREQ("3", gc(xdtoa(trunc(3.14))));
|
||||
EXPECT_STREQ("-3", gc(xdtoa(trunc(-3.14))));
|
||||
EXPECT_STREQ("-0", gc(xdtoa(trunc(-0.))));
|
||||
EXPECT_STREQ("NAN", gc(xdtoa(trunc(NAN))));
|
||||
EXPECT_STREQ("-NAN", gc(xdtoa(trunc(-NAN))));
|
||||
EXPECT_STREQ("INFINITY", gc(xdtoa(trunc(INFINITY))));
|
||||
EXPECT_STREQ("-INFINITY", gc(xdtoa(trunc(-INFINITY))));
|
||||
}
|
||||
|
||||
TEST(truncf, test) {
|
||||
EXPECT_STREQ("3", gc(xdtoaf(truncf(3))));
|
||||
EXPECT_STREQ("3", gc(xdtoaf(truncf(3.14))));
|
||||
EXPECT_STREQ("-3", gc(xdtoaf(truncf(-3.14))));
|
||||
EXPECT_STREQ("-0", gc(xdtoaf(truncf(-0.))));
|
||||
EXPECT_STREQ("NAN", gc(xdtoaf(truncf(NAN))));
|
||||
EXPECT_STREQ("-NAN", gc(xdtoaf(truncf(-NAN))));
|
||||
EXPECT_STREQ("INFINITY", gc(xdtoaf(truncf(INFINITY))));
|
||||
EXPECT_STREQ("-INFINITY", gc(xdtoaf(truncf(-INFINITY))));
|
||||
}
|
||||
|
||||
TEST(truncl, test) {
|
||||
EXPECT_STREQ("3", gc(xdtoal(truncl(3))));
|
||||
EXPECT_STREQ("3", gc(xdtoal(truncl(3.14))));
|
||||
EXPECT_STREQ("-3", gc(xdtoal(truncl(-3.14))));
|
||||
EXPECT_STREQ("-0", gc(xdtoal(truncl(-0.))));
|
||||
EXPECT_STREQ("NAN", gc(xdtoal(truncl(NAN))));
|
||||
EXPECT_STREQ("-NAN", gc(xdtoal(truncl(-NAN))));
|
||||
EXPECT_STREQ("INFINITY", gc(xdtoal(truncl(INFINITY))));
|
||||
EXPECT_STREQ("-INFINITY", gc(xdtoal(truncl(-INFINITY))));
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue