Get more Python tests passing (#141)

This commit is contained in:
Justine Tunney 2021-08-16 15:26:31 -07:00
parent 916f19eea1
commit 59e1c245d1
141 changed files with 3536 additions and 1203 deletions

View file

@ -30,10 +30,11 @@ TEST(acos, test) {
EXPECT_STREQ("3.14159265358979", gc(xasprintf("%.15g", acos(-1.))));
EXPECT_TRUE(isnan(acos(1.5)));
EXPECT_TRUE(isnan(acos(-1.5)));
EXPECT_TRUE(isnan(acos(2.)));
EXPECT_TRUE(isnan(acos(NAN)));
EXPECT_TRUE(isnan(acos(-NAN)));
EXPECT_TRUE(isnan(acos(INFINITY)));
EXPECT_TRUE(isnan(acos(-INFINITY)));
EXPECT_STREQ("1.5707963267949", gc(xasprintf("%.15g", acos(__DBL_MIN__))));
EXPECT_TRUE(isnan(acos(__LDBL_MAX__)));
EXPECT_TRUE(isnan(acos(__DBL_MAX__)));
}

View file

@ -31,6 +31,8 @@ TEST(asinh, test) {
EXPECT_STREQ("0", gc(xdtoa(asinh(0))));
EXPECT_STREQ("NAN", gc(xdtoa(asinh(NAN))));
EXPECT_STREQ("INFINITY", gc(xdtoa(asinh(INFINITY))));
EXPECT_STREQ("-2.1073424255447e-08",
gc(xasprintf("%.15g", asinh(-2.1073424255447e-08))));
}
TEST(asinhf, test) {

View file

@ -287,6 +287,8 @@ TEST(atan2, test) {
EXPECT_STREQ("-0", gc(xasprintf("%.15g", atan2(-1, INFINITY))));
EXPECT_STREQ(
"-0", gc(xasprintf("%.15g", atan2(-1.7976931348623157e308, INFINITY))));
EXPECT_STREQ("1.5707963267949",
gc(xasprintf("%.15g", atan2(1.4142135623731, 0))));
}
BENCH(atan2, bench) {

View file

@ -18,6 +18,7 @@
*/
#include "libc/math.h"
#include "libc/runtime/gc.internal.h"
#include "libc/testlib/ezbench.h"
#include "libc/testlib/testlib.h"
#include "libc/x/x.h"
@ -34,6 +35,8 @@ TEST(atanh, test) {
EXPECT_STREQ("-INFINITY", gc(xdtoa(atanh(-1))));
EXPECT_TRUE(isnan(atanh(+1.1)));
EXPECT_TRUE(isnan(atanh(-1.1)));
EXPECT_STREQ("-2.1073424255447e-08",
gc(xasprintf("%.15g", atanh(-2.1073424255447e-08))));
}
TEST(atanhl, test) {
@ -57,3 +60,10 @@ TEST(atanhf, test) {
EXPECT_TRUE(isnan(atanhf(+1.1)));
EXPECT_TRUE(isnan(atanhf(-1.1)));
}
BENCH(atanh, bench) {
volatile double a = .5;
EZBENCH2("atanhf", donothing, EXPROPRIATE(atanhf(a)));
EZBENCH2("atanh", donothing, EXPROPRIATE(atanh(a)));
EZBENCH2("atanhl", donothing, EXPROPRIATE(atanhl(a)));
}

View 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.internal.h"
#include "libc/testlib/testlib.h"
#include "libc/x/x.h"
TEST(cos, test) {
EXPECT_STREQ("1", gc(xasprintf("%.15g", cos(0.))));
EXPECT_STREQ("1", gc(xasprintf("%.15g", cos(-0.))));
EXPECT_STREQ("0.995004165278026", gc(xasprintf("%.15g", cos(.1))));
EXPECT_STREQ("0.995004165278026", gc(xasprintf("%.15g", cos(-.1))));
EXPECT_STREQ("0.877582561890373", gc(xasprintf("%.15g", cos(.5))));
EXPECT_STREQ("0.877582561890373", gc(xasprintf("%.15g", cos(-.5))));
EXPECT_STREQ("0.54030230586814", gc(xasprintf("%.15g", cos(1.))));
EXPECT_STREQ("0.54030230586814", gc(xasprintf("%.15g", cos(-1.))));
EXPECT_STREQ("0.0707372016677029", gc(xasprintf("%.15g", cos(1.5))));
EXPECT_STREQ("0.0707372016677029", gc(xasprintf("%.15g", cos(-1.5))));
EXPECT_STREQ("-0.416146836547142", gc(xasprintf("%.15g", cos(2.))));
EXPECT_TRUE(isnan(cos(NAN)));
EXPECT_TRUE(isnan(cos(-NAN)));
EXPECT_TRUE(isnan(cos(INFINITY)));
EXPECT_TRUE(isnan(cos(-INFINITY)));
EXPECT_STREQ("1", gc(xasprintf("%.15g", cos(__DBL_MIN__))));
EXPECT_STREQ("-0.99998768942656", gc(xasprintf("%.15g", cos(__DBL_MAX__))));
EXPECT_STREQ("0.54030230586814",
gc(xasprintf("%.15g", cos(-1.0000000000000002))));
EXPECT_STREQ("1", gc(xasprintf("%.15g", cos(-2.1073424255447e-08))));
}

View file

@ -110,6 +110,13 @@ TEST(hypotll, test) {
EXPECT_STREQ("INFINITY", gc(xdtoal(hypotl(INFINITY, INFINITY))));
}
/*
hypot (musl) l: 53𝑐 17𝑛𝑠 m: 85𝑐 27𝑛𝑠
hypot l: 39𝑐 13𝑛𝑠 m: 66𝑐 21𝑛𝑠
hypotf l: 25𝑐 8𝑛𝑠 m: 55𝑐 18𝑛𝑠
hypotl l: 43𝑐 14𝑛𝑠 m: 74𝑐 24𝑛𝑠
*/
BENCH(hypot, bench) {
volatile double a = 2;
volatile double b = 3;

View file

@ -34,18 +34,32 @@ TEST(sinl, test) {
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)))); */
/* EXPECT_STREQ("1", gc(xdtoal(sinl(5.319372648326541e+255L)))); */
}
TEST(sin, test) {
EXPECT_STREQ("0", gc(xasprintf("%.15g", sin(0.))));
EXPECT_STREQ("-0", gc(xasprintf("%.15g", sin(-0.))));
EXPECT_STREQ("0.0998334166468282", gc(xasprintf("%.15g", sin(.1))));
EXPECT_STREQ("-0.0998334166468282", gc(xasprintf("%.15g", sin(-.1))));
EXPECT_STREQ("0.479425538604203", gc(xasprintf("%.15g", sin(.5))));
EXPECT_STREQ("-0.479425538604203", gc(xasprintf("%.15g", sin(-.5))));
EXPECT_STREQ("0.841470984807897", gc(xasprintf("%.15g", sin(1.))));
EXPECT_STREQ("-0.841470984807897", gc(xasprintf("%.15g", sin(-1.))));
EXPECT_STREQ("0.997494986604054", gc(xasprintf("%.15g", sin(1.5))));
EXPECT_STREQ("-0.997494986604054", gc(xasprintf("%.15g", sin(-1.5))));
EXPECT_STREQ("0.909297426825682", gc(xasprintf("%.15g", sin(2.))));
EXPECT_TRUE(isnan(sin(NAN)));
EXPECT_TRUE(isnan(sin(+INFINITY)));
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))));
EXPECT_STREQ("2.2250738585072e-308",
gc(xasprintf("%.15g", sin(__DBL_MIN__))));
EXPECT_STREQ("0.00496195478918406", gc(xasprintf("%.15g", sin(__DBL_MAX__))));
EXPECT_STREQ("-0.841470984807897",
gc(xasprintf("%.15g", sin(-1.0000000000000002))));
EXPECT_STREQ("-2.1073424255447e-08",
gc(xasprintf("%.15g", sin(-2.1073424255447e-08))));
}
TEST(sinf, test) {

View file

@ -0,0 +1,37 @@
/*-*- 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.internal.h"
#include "libc/testlib/ezbench.h"
#include "libc/testlib/testlib.h"
#include "libc/x/x.h"
TEST(sincos, test) {
double sine, cosine;
sincos(.1, &sine, &cosine);
EXPECT_STREQ("0.0998334166468282", gc(xasprintf("%.15g", sine)));
EXPECT_STREQ("0.995004165278026", gc(xasprintf("%.15g", cosine)));
}
BENCH(sincos, bench) {
volatile double x = 31337;
volatile double sine, cosine;
EZBENCH2("sin+cos", donothing, (sin(x), cos(x)));
EZBENCH2("sincos", donothing, sincos(x, &sine, &cosine));
}

View file

@ -36,6 +36,5 @@ TEST(tan, test) {
EXPECT_STREQ("-nan", gc(xasprintf("%.15g", tan(-INFINITY))));
EXPECT_STREQ("2.2250738585072e-308",
gc(xasprintf("%.15g", tan(__DBL_MIN__))));
/* EXPECT_STREQ("-0.0049620158744449", */
/* gc(xasprintf("%.15g", tan(__DBL_MAX__)))); */
EXPECT_STREQ("-0.0049620158744449", gc(xasprintf("%.15g", tan(__DBL_MAX__))));
}

View file

@ -36,13 +36,28 @@ TEST(tanhl, test) {
}
TEST(tanh, test) {
EXPECT_STREQ(".0996679946249559", gc(xdtoa(tanh(+.1))));
EXPECT_STREQ("-.0996679946249559", gc(xdtoa(tanh(-.1))));
EXPECT_STREQ("0", gc(xdtoa(tanh(0))));
EXPECT_STREQ("-0", gc(xdtoa(tanh(-0.))));
EXPECT_STREQ("0", gc(xasprintf("%.15g", tanh(0.))));
EXPECT_STREQ("-0", gc(xasprintf("%.15g", tanh(-0.))));
EXPECT_STREQ("0.0996679946249558", gc(xasprintf("%.15g", tanh(.1))));
EXPECT_STREQ("-0.0996679946249558", gc(xasprintf("%.15g", tanh(-.1))));
EXPECT_STREQ("0.46211715726001", gc(xasprintf("%.15g", tanh(.5))));
EXPECT_STREQ("-0.46211715726001", gc(xasprintf("%.15g", tanh(-.5))));
EXPECT_STREQ("0.761594155955765", gc(xasprintf("%.15g", tanh(1.))));
EXPECT_STREQ("-0.761594155955765", gc(xasprintf("%.15g", tanh(-1.))));
EXPECT_STREQ("0.905148253644866", gc(xasprintf("%.15g", tanh(1.5))));
EXPECT_STREQ("-0.905148253644866", gc(xasprintf("%.15g", tanh(-1.5))));
EXPECT_STREQ("0.964027580075817", gc(xasprintf("%.15g", tanh(2.))));
EXPECT_TRUE(isnan(tanh(NAN)));
EXPECT_STREQ("1", gc(xdtoa(tanh(INFINITY))));
EXPECT_STREQ("-1", gc(xdtoa(tanh(-INFINITY))));
EXPECT_TRUE(isnan(tanh(-NAN)));
EXPECT_STREQ("1", gc(xasprintf("%.15g", tanh(INFINITY))));
EXPECT_STREQ("-1", gc(xasprintf("%.15g", tanh(-INFINITY))));
EXPECT_STREQ("2.2250738585072e-308",
gc(xasprintf("%.15g", tanh(__DBL_MIN__))));
EXPECT_STREQ("1", gc(xasprintf("%.15g", tanh(__DBL_MAX__))));
EXPECT_STREQ("-0.761594155955765",
gc(xasprintf("%.15g", tanh(-1.0000000000000002))));
EXPECT_STREQ("-2.1073424255447e-08",
gc(xasprintf("%.15g", tanh(-2.1073424255447e-08))));
}
TEST(tanhf, test) {