mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-04-15 04:08:47 +00:00
Add more math fixes
This commit is contained in:
parent
11ec99931b
commit
bfef17eb6d
27 changed files with 236 additions and 61 deletions
4
Makefile
4
Makefile
|
@ -234,7 +234,6 @@ COSMOPOLITAN_OBJECTS = \
|
||||||
LIBC_NT_MSWSOCK \
|
LIBC_NT_MSWSOCK \
|
||||||
LIBC_OHMYPLUS \
|
LIBC_OHMYPLUS \
|
||||||
LIBC_X \
|
LIBC_X \
|
||||||
THIRD_PARTY_GDTOA \
|
|
||||||
THIRD_PARTY_GETOPT \
|
THIRD_PARTY_GETOPT \
|
||||||
LIBC_LOG \
|
LIBC_LOG \
|
||||||
LIBC_UNICODE \
|
LIBC_UNICODE \
|
||||||
|
@ -243,6 +242,7 @@ COSMOPOLITAN_OBJECTS = \
|
||||||
THIRD_PARTY_ZLIB \
|
THIRD_PARTY_ZLIB \
|
||||||
THIRD_PARTY_MUSL \
|
THIRD_PARTY_MUSL \
|
||||||
LIBC_STDIO \
|
LIBC_STDIO \
|
||||||
|
THIRD_PARTY_GDTOA \
|
||||||
THIRD_PARTY_REGEX \
|
THIRD_PARTY_REGEX \
|
||||||
LIBC_ALG \
|
LIBC_ALG \
|
||||||
LIBC_MEM \
|
LIBC_MEM \
|
||||||
|
@ -265,8 +265,8 @@ COSMOPOLITAN_OBJECTS = \
|
||||||
LIBC_FMT \
|
LIBC_FMT \
|
||||||
THIRD_PARTY_COMPILER_RT \
|
THIRD_PARTY_COMPILER_RT \
|
||||||
LIBC_TINYMATH \
|
LIBC_TINYMATH \
|
||||||
LIBC_SYSV \
|
|
||||||
LIBC_STR \
|
LIBC_STR \
|
||||||
|
LIBC_SYSV \
|
||||||
LIBC_INTRIN \
|
LIBC_INTRIN \
|
||||||
LIBC_NT_KERNEL32 \
|
LIBC_NT_KERNEL32 \
|
||||||
LIBC_NEXGEN32E
|
LIBC_NEXGEN32E
|
||||||
|
|
|
@ -17,7 +17,6 @@
|
||||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/macros.internal.h"
|
#include "libc/macros.internal.h"
|
||||||
.source __FILE__
|
|
||||||
|
|
||||||
// Returns arc cosine of 𝑥.
|
// Returns arc cosine of 𝑥.
|
||||||
//
|
//
|
||||||
|
|
|
@ -17,38 +17,27 @@
|
||||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/macros.internal.h"
|
#include "libc/macros.internal.h"
|
||||||
.source __FILE__
|
|
||||||
|
|
||||||
// Returns arc cosine of 𝑥.
|
// Returns arc cosine of 𝑥.
|
||||||
//
|
//
|
||||||
// @param 𝑥 is an 80-bit long double passed on stack in 16-bytes
|
// @param 𝑥 is an 80-bit long double passed on stack in 16-bytes
|
||||||
// @return result of computation on FPU stack in %st
|
// @return result of computation on FPU stack in %st
|
||||||
// @define atan2(abs(sqrt((1-𝑥)*(1+𝑥))),𝑥)
|
// @define atan2(fabs(sqrt((1-𝑥)*(1+𝑥))),𝑥)
|
||||||
// @domain -1 ≤ 𝑥 ≤ 1
|
// @domain -1 ≤ 𝑥 ≤ 1
|
||||||
// @mode long,legacy
|
acosl: pushq %rbp
|
||||||
acosl: push %rbp
|
|
||||||
mov %rsp,%rbp
|
mov %rsp,%rbp
|
||||||
.profilable
|
.profilable
|
||||||
fldl 16(%rbp)
|
fldt 16(%rbp)
|
||||||
fld %st
|
|
||||||
#ifdef __FAST_MATH__
|
|
||||||
fmul %st(1),%st
|
|
||||||
fsubrs .Lone(%rip)
|
|
||||||
fsqrt
|
|
||||||
#else
|
|
||||||
fld1
|
fld1
|
||||||
fsubp
|
fld %st
|
||||||
fld1
|
fsub %st(2)
|
||||||
fadd %st(2)
|
fxch
|
||||||
|
fadd %st(2)
|
||||||
fmulp
|
fmulp
|
||||||
fsqrt
|
fsqrt
|
||||||
fabs # needed in downward rounding mode
|
fabs
|
||||||
#endif
|
|
||||||
fxch
|
fxch
|
||||||
fpatan
|
fpatan
|
||||||
pop %rbp
|
leave
|
||||||
ret
|
ret
|
||||||
.endfn acosl,globl
|
.endfn acosl,globl
|
||||||
|
|
||||||
.rodata.cst4
|
|
||||||
.Lone: .float 1.0
|
|
||||||
|
|
|
@ -17,7 +17,6 @@
|
||||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/macros.internal.h"
|
#include "libc/macros.internal.h"
|
||||||
.source __FILE__
|
|
||||||
|
|
||||||
// Returns arc sine of 𝑥.
|
// Returns arc sine of 𝑥.
|
||||||
//
|
//
|
||||||
|
|
|
@ -17,7 +17,6 @@
|
||||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/macros.internal.h"
|
#include "libc/macros.internal.h"
|
||||||
.source __FILE__
|
|
||||||
|
|
||||||
// Returns arc sine of 𝑥.
|
// Returns arc sine of 𝑥.
|
||||||
//
|
//
|
||||||
|
|
|
@ -17,7 +17,6 @@
|
||||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/macros.internal.h"
|
#include "libc/macros.internal.h"
|
||||||
.source __FILE__
|
|
||||||
|
|
||||||
// Returns arc sine of 𝑥.
|
// Returns arc sine of 𝑥.
|
||||||
//
|
//
|
||||||
|
@ -25,27 +24,18 @@
|
||||||
// @return result of computation on FPU stack in %st
|
// @return result of computation on FPU stack in %st
|
||||||
// @define atan2(𝑥,sqrt((1-𝑥)*(1+𝑥)))
|
// @define atan2(𝑥,sqrt((1-𝑥)*(1+𝑥)))
|
||||||
// @domain -1 ≤ 𝑥 ≤ 1
|
// @domain -1 ≤ 𝑥 ≤ 1
|
||||||
// @mode long,legacy
|
asinl: pushq %rbp
|
||||||
asinl: push %rbp
|
|
||||||
mov %rsp,%rbp
|
mov %rsp,%rbp
|
||||||
.profilable
|
.profilable
|
||||||
fldl 16(%rbp)
|
fldt 16(%rbp)
|
||||||
fld %st
|
|
||||||
#ifdef __FAST_MATH__
|
|
||||||
fmul %st(1),%st
|
|
||||||
fsubrs .Lone(%rip)
|
|
||||||
#else
|
|
||||||
fld1
|
fld1
|
||||||
fsubp
|
fld %st
|
||||||
fld1
|
fsub %st(2)
|
||||||
fadd %st(2)
|
fxch
|
||||||
|
fadd %st(2)
|
||||||
fmulp
|
fmulp
|
||||||
#endif
|
|
||||||
fsqrt
|
fsqrt
|
||||||
fpatan
|
fpatan
|
||||||
pop %rbp
|
leave
|
||||||
ret
|
ret
|
||||||
.endfn asinl,globl
|
.endfn asinl,globl
|
||||||
|
|
||||||
.rodata.cst4
|
|
||||||
.Lone: .float 1.0
|
|
||||||
|
|
|
@ -17,7 +17,6 @@
|
||||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/macros.internal.h"
|
#include "libc/macros.internal.h"
|
||||||
.source __FILE__
|
|
||||||
|
|
||||||
// Returns arc tangent of 𝑥.
|
// Returns arc tangent of 𝑥.
|
||||||
//
|
//
|
||||||
|
|
|
@ -17,7 +17,6 @@
|
||||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/macros.internal.h"
|
#include "libc/macros.internal.h"
|
||||||
.source __FILE__
|
|
||||||
|
|
||||||
// Returns arc tangent of 𝑥.
|
// Returns arc tangent of 𝑥.
|
||||||
//
|
//
|
||||||
|
|
|
@ -17,7 +17,6 @@
|
||||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/macros.internal.h"
|
#include "libc/macros.internal.h"
|
||||||
.source __FILE__
|
|
||||||
|
|
||||||
// Returns 𝑥^𝑦.
|
// Returns 𝑥^𝑦.
|
||||||
//
|
//
|
||||||
|
@ -27,4 +26,3 @@
|
||||||
pow: ezlea powl,ax
|
pow: ezlea powl,ax
|
||||||
jmp _d2ld2
|
jmp _d2ld2
|
||||||
.endfn pow,globl
|
.endfn pow,globl
|
||||||
.alias pow,__pow_finite
|
|
||||||
|
|
|
@ -26,4 +26,3 @@
|
||||||
powf: ezlea powl,ax
|
powf: ezlea powl,ax
|
||||||
jmp _f2ld2
|
jmp _f2ld2
|
||||||
.endfn powf,globl
|
.endfn powf,globl
|
||||||
.alias powf,__powf_finite
|
|
||||||
|
|
|
@ -18,6 +18,13 @@
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/math.h"
|
#include "libc/math.h"
|
||||||
|
|
||||||
long double __powl_finite(long double x, long double y) {
|
#define powl __powl_finite
|
||||||
return powl(x, y);
|
#include "libc/tinymath/powl.c"
|
||||||
|
|
||||||
|
double __pow_finite(double x, double y) {
|
||||||
|
return __powl_finite(x, y);
|
||||||
|
}
|
||||||
|
|
||||||
|
float __powf_finite(float x, float y) {
|
||||||
|
return __powl_finite(x, y);
|
||||||
}
|
}
|
|
@ -17,7 +17,6 @@
|
||||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/macros.internal.h"
|
#include "libc/macros.internal.h"
|
||||||
.source __FILE__
|
|
||||||
|
|
||||||
// Returns 𝑥 × 2ʸ.
|
// Returns 𝑥 × 2ʸ.
|
||||||
//
|
//
|
||||||
|
|
|
@ -17,7 +17,6 @@
|
||||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/macros.internal.h"
|
#include "libc/macros.internal.h"
|
||||||
.source __FILE__
|
|
||||||
|
|
||||||
// Returns sine of 𝑥.
|
// Returns sine of 𝑥.
|
||||||
//
|
//
|
||||||
|
|
|
@ -17,7 +17,6 @@
|
||||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/macros.internal.h"
|
#include "libc/macros.internal.h"
|
||||||
.source __FILE__
|
|
||||||
|
|
||||||
// Returns sine and cosine of 𝑥.
|
// Returns sine and cosine of 𝑥.
|
||||||
//
|
//
|
||||||
|
|
|
@ -17,7 +17,6 @@
|
||||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/macros.internal.h"
|
#include "libc/macros.internal.h"
|
||||||
.source __FILE__
|
|
||||||
|
|
||||||
// Returns sine and cosine of 𝑥.
|
// Returns sine and cosine of 𝑥.
|
||||||
//
|
//
|
||||||
|
|
|
@ -18,7 +18,6 @@
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/runtime/pc.internal.h"
|
#include "libc/runtime/pc.internal.h"
|
||||||
#include "libc/macros.internal.h"
|
#include "libc/macros.internal.h"
|
||||||
.source __FILE__
|
|
||||||
|
|
||||||
// Returns sine and cosine of 𝑥.
|
// Returns sine and cosine of 𝑥.
|
||||||
//
|
//
|
||||||
|
|
|
@ -17,7 +17,6 @@
|
||||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/macros.internal.h"
|
#include "libc/macros.internal.h"
|
||||||
.source __FILE__
|
|
||||||
|
|
||||||
// Returns sine of 𝑥.
|
// Returns sine of 𝑥.
|
||||||
//
|
//
|
||||||
|
|
|
@ -17,7 +17,6 @@
|
||||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/macros.internal.h"
|
#include "libc/macros.internal.h"
|
||||||
.source __FILE__
|
|
||||||
|
|
||||||
// Returns tangent of 𝑥.
|
// Returns tangent of 𝑥.
|
||||||
//
|
//
|
||||||
|
|
|
@ -18,7 +18,6 @@
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/runtime/pc.internal.h"
|
#include "libc/runtime/pc.internal.h"
|
||||||
#include "libc/macros.internal.h"
|
#include "libc/macros.internal.h"
|
||||||
.source __FILE__
|
|
||||||
|
|
||||||
// Returns tangent of 𝑥.
|
// Returns tangent of 𝑥.
|
||||||
//
|
//
|
||||||
|
|
|
@ -40,6 +40,10 @@ $(LIBC_TINYMATH_A).pkg: \
|
||||||
$(LIBC_TINYMATH_A_OBJS) \
|
$(LIBC_TINYMATH_A_OBJS) \
|
||||||
$(foreach x,$(LIBC_TINYMATH_A_DIRECTDEPS),$($(x)_A).pkg)
|
$(foreach x,$(LIBC_TINYMATH_A_DIRECTDEPS),$($(x)_A).pkg)
|
||||||
|
|
||||||
|
o/$(MODE)/libc/tinymath/powfin.o: \
|
||||||
|
OVERRIDE_CFLAGS += \
|
||||||
|
-ffast-math
|
||||||
|
|
||||||
LIBC_TINYMATH_LIBS = $(foreach x,$(LIBC_TINYMATH_ARTIFACTS),$($(x)))
|
LIBC_TINYMATH_LIBS = $(foreach x,$(LIBC_TINYMATH_ARTIFACTS),$($(x)))
|
||||||
LIBC_TINYMATH_HDRS = $(foreach x,$(LIBC_TINYMATH_ARTIFACTS),$($(x)_HDRS))
|
LIBC_TINYMATH_HDRS = $(foreach x,$(LIBC_TINYMATH_ARTIFACTS),$($(x)_HDRS))
|
||||||
LIBC_TINYMATH_SRCS = $(foreach x,$(LIBC_TINYMATH_ARTIFACTS),$($(x)_SRCS))
|
LIBC_TINYMATH_SRCS = $(foreach x,$(LIBC_TINYMATH_ARTIFACTS),$($(x)_SRCS))
|
||||||
|
|
39
test/libc/tinymath/acos_test.c
Normal file
39
test/libc/tinymath/acos_test.c
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
/*-*- 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(acos, test) {
|
||||||
|
EXPECT_STREQ("1.5707963267949", gc(xasprintf("%.15g", acos(0.))));
|
||||||
|
EXPECT_STREQ("1.5707963267949", gc(xasprintf("%.15g", acos(-0.))));
|
||||||
|
EXPECT_STREQ("1.0471975511966", gc(xasprintf("%.15g", acos(.5))));
|
||||||
|
EXPECT_STREQ("2.0943951023932", gc(xasprintf("%.15g", acos(-.5))));
|
||||||
|
EXPECT_STREQ("0", gc(xasprintf("%.15g", acos(1.))));
|
||||||
|
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(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__)));
|
||||||
|
}
|
40
test/libc/tinymath/asin_test.c
Normal file
40
test/libc/tinymath/asin_test.c
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
/*-*- 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(asin, test) {
|
||||||
|
EXPECT_STREQ("0", gc(xasprintf("%.15g", asin(0.))));
|
||||||
|
EXPECT_STREQ("-0", gc(xasprintf("%.15g", asin(-0.))));
|
||||||
|
EXPECT_STREQ("0.523598775598299", gc(xasprintf("%.15g", asin(.5))));
|
||||||
|
EXPECT_STREQ("-0.523598775598299", gc(xasprintf("%.15g", asin(-.5))));
|
||||||
|
EXPECT_STREQ("1.5707963267949", gc(xasprintf("%.15g", asin(1.))));
|
||||||
|
EXPECT_STREQ("-1.5707963267949", gc(xasprintf("%.15g", asin(-1.))));
|
||||||
|
EXPECT_TRUE(isnan(asin(1.5)));
|
||||||
|
EXPECT_TRUE(isnan(asin(-1.5)));
|
||||||
|
EXPECT_TRUE(isnan(asin(NAN)));
|
||||||
|
EXPECT_TRUE(isnan(asin(-NAN)));
|
||||||
|
EXPECT_TRUE(isnan(asin(INFINITY)));
|
||||||
|
EXPECT_TRUE(isnan(asin(-INFINITY)));
|
||||||
|
EXPECT_STREQ("2.2250738585072e-308",
|
||||||
|
gc(xasprintf("%.15g", asin(__DBL_MIN__))));
|
||||||
|
EXPECT_TRUE(isnan(asin(__DBL_MAX__)));
|
||||||
|
}
|
40
test/libc/tinymath/atan_test.c
Normal file
40
test/libc/tinymath/atan_test.c
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
/*-*- 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(atan, test) {
|
||||||
|
EXPECT_STREQ("0", gc(xasprintf("%.15g", atan(0.))));
|
||||||
|
EXPECT_STREQ("-0", gc(xasprintf("%.15g", atan(-0.))));
|
||||||
|
EXPECT_STREQ("0.463647609000806", gc(xasprintf("%.15g", atan(.5))));
|
||||||
|
EXPECT_STREQ("-0.463647609000806", gc(xasprintf("%.15g", atan(-.5))));
|
||||||
|
EXPECT_STREQ("0.785398163397448", gc(xasprintf("%.15g", atan(1.))));
|
||||||
|
EXPECT_STREQ("-0.785398163397448", gc(xasprintf("%.15g", atan(-1.))));
|
||||||
|
EXPECT_STREQ("0.982793723247329", gc(xasprintf("%.15g", atan(1.5))));
|
||||||
|
EXPECT_STREQ("-0.982793723247329", gc(xasprintf("%.15g", atan(-1.5))));
|
||||||
|
EXPECT_STREQ("nan", gc(xasprintf("%.15g", atan(NAN))));
|
||||||
|
EXPECT_STREQ("-nan", gc(xasprintf("%.15g", atan(-NAN))));
|
||||||
|
EXPECT_STREQ("1.5707963267949", gc(xasprintf("%.15g", atan(INFINITY))));
|
||||||
|
EXPECT_STREQ("-1.5707963267949", gc(xasprintf("%.15g", atan(-INFINITY))));
|
||||||
|
EXPECT_STREQ("2.2250738585072e-308",
|
||||||
|
gc(xasprintf("%.15g", atan(__DBL_MIN__))));
|
||||||
|
EXPECT_STREQ("1.5707963267949", gc(xasprintf("%.15g", atan(__DBL_MAX__))));
|
||||||
|
}
|
41
test/libc/tinymath/cbrt_test.c
Normal file
41
test/libc/tinymath/cbrt_test.c
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
/*-*- 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(cbrt, test) {
|
||||||
|
EXPECT_STREQ("0", gc(xasprintf("%.15g", cbrt(0.))));
|
||||||
|
EXPECT_STREQ("-0", gc(xasprintf("%.15g", cbrt(-0.))));
|
||||||
|
EXPECT_STREQ("0.7937005259841", gc(xasprintf("%.15g", cbrt(.5))));
|
||||||
|
EXPECT_STREQ("-0.7937005259841", gc(xasprintf("%.15g", cbrt(-.5))));
|
||||||
|
EXPECT_STREQ("1", gc(xasprintf("%.15g", cbrt(1.))));
|
||||||
|
EXPECT_STREQ("-1", gc(xasprintf("%.15g", cbrt(-1.))));
|
||||||
|
EXPECT_STREQ("1.14471424255333", gc(xasprintf("%.15g", cbrt(1.5))));
|
||||||
|
EXPECT_STREQ("-1.14471424255333", gc(xasprintf("%.15g", cbrt(-1.5))));
|
||||||
|
EXPECT_STREQ("nan", gc(xasprintf("%.15g", cbrt(NAN))));
|
||||||
|
EXPECT_STREQ("-nan", gc(xasprintf("%.15g", cbrt(-NAN))));
|
||||||
|
EXPECT_STREQ("inf", gc(xasprintf("%.15g", cbrt(INFINITY))));
|
||||||
|
EXPECT_STREQ("-inf", gc(xasprintf("%.15g", cbrt(-INFINITY))));
|
||||||
|
EXPECT_STREQ("2.81264428523626e-103",
|
||||||
|
gc(xasprintf("%.15g", cbrt(__DBL_MIN__))));
|
||||||
|
EXPECT_STREQ("5.64380309412236e+102",
|
||||||
|
gc(xasprintf("%.15g", cbrt(__DBL_MAX__))));
|
||||||
|
}
|
|
@ -192,7 +192,7 @@ BENCH(powl, bench) {
|
||||||
double _pow(double, double) asm("pow");
|
double _pow(double, double) asm("pow");
|
||||||
float _powf(float, float) asm("powf");
|
float _powf(float, float) asm("powf");
|
||||||
long double _powl(long double, long double) asm("powl");
|
long double _powl(long double, long double) asm("powl");
|
||||||
EZBENCH2("pow", donothing, _pow(.7, .2)); /* ~51ns */
|
EZBENCH2("pow", donothing, _pow(.7, .2)); /* ~56ns */
|
||||||
EZBENCH2("powf", donothing, _powf(.7, .2)); /* ~52ns */
|
EZBENCH2("powf", donothing, _powf(.7, .2)); /* ~56ns */
|
||||||
EZBENCH2("powl", donothing, _powl(.7, .2)); /* ~53ns */
|
EZBENCH2("powl", donothing, _powl(.7, .2)); /* ~56ns */
|
||||||
}
|
}
|
||||||
|
|
41
test/libc/tinymath/tan_test.c
Normal file
41
test/libc/tinymath/tan_test.c
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
/*-*- 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(tan, test) {
|
||||||
|
EXPECT_STREQ("0", gc(xasprintf("%.15g", tan(0.))));
|
||||||
|
EXPECT_STREQ("-0", gc(xasprintf("%.15g", tan(-0.))));
|
||||||
|
EXPECT_STREQ("0.54630248984379", gc(xasprintf("%.15g", tan(.5))));
|
||||||
|
EXPECT_STREQ("-0.54630248984379", gc(xasprintf("%.15g", tan(-.5))));
|
||||||
|
EXPECT_STREQ("1.5574077246549", gc(xasprintf("%.15g", tan(1.))));
|
||||||
|
EXPECT_STREQ("-1.5574077246549", gc(xasprintf("%.15g", tan(-1.))));
|
||||||
|
EXPECT_STREQ("14.1014199471717", gc(xasprintf("%.15g", tan(1.5))));
|
||||||
|
EXPECT_STREQ("-14.1014199471717", gc(xasprintf("%.15g", tan(-1.5))));
|
||||||
|
EXPECT_STREQ("nan", gc(xasprintf("%.15g", tan(NAN))));
|
||||||
|
EXPECT_STREQ("-nan", gc(xasprintf("%.15g", tan(-NAN))));
|
||||||
|
EXPECT_STREQ("-nan", gc(xasprintf("%.15g", tan(INFINITY))));
|
||||||
|
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__)))); */
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue