mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-06-28 07:18:30 +00:00
Import more Musl math
This commit is contained in:
parent
6d52664aa7
commit
3027d67037
48 changed files with 1749 additions and 180 deletions
|
@ -44,10 +44,11 @@ TEST(acos, test) {
|
|||
EXPECT_TRUE(isnan(acos(__DBL_MAX__)));
|
||||
}
|
||||
|
||||
BENCH(acos, bench) {
|
||||
EZBENCH2("acos(+0)", donothing, acos(0));
|
||||
EZBENCH2("acos(-0)", donothing, acos(-0.));
|
||||
EZBENCH2("acos(NAN)", donothing, acos(NAN));
|
||||
EZBENCH2("acos(INFINITY)", donothing, acos(INFINITY));
|
||||
EZBENCH_C("acos", _real1(vigna()), acos(_real1(vigna())));
|
||||
BENCH(acosl, bench) {
|
||||
double _acos(double) asm("acos");
|
||||
float _acosf(float) asm("acosf");
|
||||
long double _acosl(long double) asm("acosl");
|
||||
EZBENCH2("-acos", donothing, _acos(.7)); /* ~17ns */
|
||||
EZBENCH2("-acosf", donothing, _acosf(.7)); /* ~11ns */
|
||||
EZBENCH2("-acosl", donothing, _acosl(.7)); /* ~40ns */
|
||||
}
|
||||
|
|
|
@ -44,10 +44,11 @@ TEST(asin, test) {
|
|||
EXPECT_TRUE(isnan(asin(__DBL_MAX__)));
|
||||
}
|
||||
|
||||
BENCH(asin, bench) {
|
||||
EZBENCH2("asin(+0)", donothing, asin(0));
|
||||
EZBENCH2("asin(-0)", donothing, asin(-0.));
|
||||
EZBENCH2("asin(NAN)", donothing, asin(NAN));
|
||||
EZBENCH2("asin(INFINITY)", donothing, asin(INFINITY));
|
||||
EZBENCH_C("asin", _real1(lemur64()), asin(_real1(lemur64())));
|
||||
BENCH(asinl, bench) {
|
||||
double _asin(double) asm("asin");
|
||||
float _asinf(float) asm("asinf");
|
||||
long double _asinl(long double) asm("asinl");
|
||||
EZBENCH2("-asin", donothing, _asin(.7)); /* ~16ns */
|
||||
EZBENCH2("-asinf", donothing, _asinf(.7)); /* ~12ns */
|
||||
EZBENCH2("-asinl", donothing, _asinl(.7)); /* ~39ns */
|
||||
}
|
||||
|
|
|
@ -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"
|
||||
|
||||
|
@ -38,3 +39,12 @@ TEST(atan, test) {
|
|||
gc(xasprintf("%.15g", atan(__DBL_MIN__))));
|
||||
EXPECT_STREQ("1.5707963267949", gc(xasprintf("%.15g", atan(__DBL_MAX__))));
|
||||
}
|
||||
|
||||
BENCH(atanl, bench) {
|
||||
double _atan(double) asm("atan");
|
||||
float _atanf(float) asm("atanf");
|
||||
long double _atanl(long double) asm("atanl");
|
||||
EZBENCH2("-atan", donothing, _atan(.7)); /* ~18ns */
|
||||
EZBENCH2("-atanf", donothing, _atanf(.7)); /* ~12ns */
|
||||
EZBENCH2("-atanl", donothing, _atanl(.7)); /* ~34ns */
|
||||
}
|
||||
|
|
|
@ -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"
|
||||
|
||||
|
@ -43,3 +44,12 @@ TEST(cos, test) {
|
|||
gc(xasprintf("%.15g", cos(-1.0000000000000002))));
|
||||
EXPECT_STREQ("1", gc(xasprintf("%.15g", cos(-2.1073424255447e-08))));
|
||||
}
|
||||
|
||||
BENCH(cos, bench) {
|
||||
double _cos(double) asm("cos");
|
||||
float _cosf(float) asm("cosf");
|
||||
long double _cosl(long double) asm("cosl");
|
||||
EZBENCH2("cos", donothing, _cos(.7)); /* ~6ns */
|
||||
EZBENCH2("cosf", donothing, _cosf(.7)); /* ~5ns */
|
||||
EZBENCH2("cosl", donothing, _cosl(.7)); /* ~28ns */
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#include "libc/rand/rand.h"
|
||||
#include "libc/runtime/gc.internal.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
#include "libc/testlib/ezbench.h"
|
||||
#include "libc/testlib/testlib.h"
|
||||
#include "libc/x/x.h"
|
||||
|
||||
|
@ -110,7 +111,11 @@ TEST(ldexp, stuff) {
|
|||
ASSERT_STREQ("100.48", gc(xasprintf("%.2Lf", scalblnl(pi, twopow))));
|
||||
}
|
||||
|
||||
TEST(exp10, test) {
|
||||
ASSERT_EQ(100, (int)exp10(2));
|
||||
ASSERT_STREQ("100.000000", gc(xasprintf("%Lf", exp10l(2))));
|
||||
BENCH(ldexpl, bench) {
|
||||
double _ldexp(double, int) asm("ldexp");
|
||||
float _ldexpf(float, int) asm("ldexpf");
|
||||
long double _ldexpl(long double, int) asm("ldexpl");
|
||||
EZBENCH2("ldexp", donothing, _ldexp(.7, 3)); /* ~1ns */
|
||||
EZBENCH2("ldexpf", donothing, _ldexpf(.7, 3)); /* ~1ns */
|
||||
EZBENCH2("ldexpl", donothing, _ldexpl(.7, 3)); /* ~7ns */
|
||||
}
|
||||
|
|
|
@ -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"
|
||||
|
||||
|
@ -45,3 +46,12 @@ TEST(log1pf, test) {
|
|||
EXPECT_STREQ("-INFINITY", gc(xdtoaf(log1pf(-1))));
|
||||
EXPECT_STREQ("-NAN", gc(xdtoaf(log1pf(-2))));
|
||||
}
|
||||
|
||||
BENCH(log1p, bench) {
|
||||
double _log1p(double) asm("log1p");
|
||||
float _log1pf(float) asm("log1pf");
|
||||
long double _log1pl(long double) asm("log1pl");
|
||||
EZBENCH2("log1p", donothing, _log1p(.7)); /* ~17ns */
|
||||
EZBENCH2("log1pf", donothing, _log1pf(.7)); /* ~17ns */
|
||||
EZBENCH2("log1pl", donothing, _log1pl(.7)); /* ~28ns */
|
||||
}
|
||||
|
|
|
@ -563,6 +563,6 @@ BENCH(powl, bench) {
|
|||
float _powf(float, float) asm("powf");
|
||||
long double _powl(long double, long double) asm("powl");
|
||||
EZBENCH2("pow", donothing, _pow(.7, .2)); /* ~18ns */
|
||||
EZBENCH2("powf", donothing, _powf(.7, .2)); /* ~56ns */
|
||||
EZBENCH2("powf", donothing, _powf(.7, .2)); /* ~16ns */
|
||||
EZBENCH2("powl", donothing, _powl(.7, .2)); /* ~56ns */
|
||||
}
|
||||
|
|
|
@ -72,8 +72,11 @@ TEST(sinf, test) {
|
|||
EXPECT_STARTSWITH(".873283", gc(xdtoaf(sinf(555))));
|
||||
}
|
||||
|
||||
BENCH(sinl, bench) {
|
||||
EZBENCH(donothing, sinl(0.7)); /* ~30ns */
|
||||
EZBENCH(donothing, sin(0.7)); /* ~35ns */
|
||||
EZBENCH(donothing, sinf(0.7f)); /* ~35ns */
|
||||
BENCH(sin, bench) {
|
||||
double _sin(double) asm("sin");
|
||||
float _sinf(float) asm("sinf");
|
||||
long double _sinl(long double) asm("sinl");
|
||||
EZBENCH2("sin", donothing, _sin(.7)); /* ~5ns */
|
||||
EZBENCH2("sinf", donothing, _sinf(.7)); /* ~5ns */
|
||||
EZBENCH2("sinl", donothing, _sinl(.7)); /* ~28ns */
|
||||
}
|
||||
|
|
|
@ -29,9 +29,39 @@ TEST(sincos, test) {
|
|||
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));
|
||||
TEST(sincosf, test) {
|
||||
float sine, cosine;
|
||||
sincosf(.1, &sine, &cosine);
|
||||
EXPECT_STREQ("0.0998334", gc(xasprintf("%.6g", sine)));
|
||||
EXPECT_STREQ("0.995004", gc(xasprintf("%.6g", cosine)));
|
||||
}
|
||||
|
||||
TEST(sincosl, test) {
|
||||
long double sine, cosine;
|
||||
sincosl(.1, &sine, &cosine);
|
||||
EXPECT_STREQ("0.0998334166468282", gc(xasprintf("%.15Lg", sine)));
|
||||
EXPECT_STREQ("0.995004165278026", gc(xasprintf("%.15Lg", cosine)));
|
||||
}
|
||||
|
||||
#define NUM .123
|
||||
|
||||
BENCH(sincos, bench) {
|
||||
double _sin(double) asm("sin");
|
||||
float _sinf(float) asm("sinf");
|
||||
long double _sinl(long double) asm("sinl");
|
||||
double _cos(double) asm("cos");
|
||||
float _cosf(float) asm("cosf");
|
||||
long double _cosl(long double) asm("cosl");
|
||||
double _sincos(double, double*, double*) asm("sincos");
|
||||
float _sincosf(float, float*, float*) asm("sincosf");
|
||||
long double _sincosl(long double, long double*, long double*) asm("sincosl");
|
||||
volatile float sinef, cosinef;
|
||||
volatile double sine, cosine;
|
||||
volatile long double sinel, cosinel;
|
||||
EZBENCH2("sin+cos", donothing, (_sin(NUM), _cos(NUM)));
|
||||
EZBENCH2("sincos", donothing, _sincos(NUM, &sine, &cosine));
|
||||
EZBENCH2("sinf+cosf", donothing, (_sinf(NUM), _cosf(NUM)));
|
||||
EZBENCH2("sincosf", donothing, _sincosf(NUM, &sinef, &cosinef));
|
||||
EZBENCH2("sinl+cosl", donothing, (_sinl(NUM), _cosl(NUM)));
|
||||
EZBENCH2("sincosl", donothing, _sincosl(NUM, &sinel, &cosinel));
|
||||
}
|
||||
|
|
|
@ -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"
|
||||
|
||||
|
@ -38,3 +39,12 @@ TEST(tan, test) {
|
|||
gc(xasprintf("%.15g", tan(__DBL_MIN__))));
|
||||
EXPECT_STREQ("-0.0049620158744449", gc(xasprintf("%.15g", tan(__DBL_MAX__))));
|
||||
}
|
||||
|
||||
BENCH(tan, bench) {
|
||||
double _tan(double) asm("tan");
|
||||
float _tanf(float) asm("tanf");
|
||||
long double _tanl(long double) asm("tanl");
|
||||
EZBENCH2("tan", donothing, _tan(.7)); /* ~19ns */
|
||||
EZBENCH2("tanf", donothing, _tanf(.7)); /* ~32ns */
|
||||
EZBENCH2("tanl", donothing, _tanl(.7)); /* ~28ns */
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue