Skip to content

Commit 94bc1cd

Browse files
ZERICO2005mateoconlechuga
authored andcommitted
added expm1l logp1l and improved acoshl atanhl
1 parent 2d72eb5 commit 94bc1cd

File tree

5 files changed

+40
-28
lines changed

5 files changed

+40
-28
lines changed

src/libc/acoshl.c

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
#include <math.h>
22
#include "__float64_constants.h"
33

4-
/* enable when log1pl is implemented */
5-
#if 0
6-
74
/**
85
* @remarks Minimum relative precision of:
96
* 2^-42.37 at +1.000000358e+00 with ideal log1pl
@@ -15,14 +12,3 @@ long double acoshl(long double x) {
1512
}
1613
return logl(x) + F64_LN2;
1714
}
18-
19-
#else
20-
21-
long double acoshl(long double x) {
22-
if (x < 0x1.0p+511L) {
23-
return logl(x + sqrtl(x * x - 1.0L));
24-
}
25-
return logl(x) + F64_LN2;
26-
}
27-
28-
#endif

src/libc/atanhl.c

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,13 @@
11
#include <math.h>
22

3-
/* enable when log1pl is implemented */
4-
#if 0
5-
63
/**
7-
* @remarks Relative precision of:
8-
* 2^-51 at +1.277396381e-01 with ideal log1pl
4+
* @remarks Minimum ulp:
5+
* ulp of -2 at +0x1.cf33c905a6324p-4 with ideal log1pl
6+
* ulp of +4098 at +0x1.ffff1c95280b8p-15 with current log1pl and ideal logl
7+
* ulp of +4135 at -0x1.f319bfec310c4p-14 with current log1pl and logl
98
*/
109
long double atanhl(long double arg) {
1110
long double x = fabsl(arg);
1211
x = 0.5L * log1pl((2.0L * x) / (1.0L - x));
1312
return copysignl(x, arg);
1413
}
15-
16-
#else
17-
18-
long double atanhl(long double x)
19-
{
20-
return 0.5L * logl((1.0L + x) / (1.0L - x));
21-
}
22-
23-
#endif

src/libc/expm1l.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#include <math.h>
2+
#include "__float64_constants.h"
3+
4+
/**
5+
* @remarks Approximate minimum ulp:
6+
* ulp of -4098 at +0x1.3683c27b9c856p-13 with ideal expl
7+
*/
8+
long double expm1l(long double x) {
9+
if (fabsl(x) < 0x1.0p-13L) {
10+
long double x_sqr = x * x;
11+
return (x_sqr * x) * F64_1_DIV_3 + 0.5L * (x_sqr) + x;
12+
}
13+
return expl(x) - 1.0L;
14+
}

src/libc/log1pl.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#include <math.h>
2+
#include "__float64_constants.h"
3+
4+
/**
5+
* @remarks Approximate minimum ulp:
6+
* ulp of +4097 at +0x1.0003239899b0ap-13 with ideal expl
7+
*/
8+
long double log1pl(long double x) {
9+
if (fabsl(x) < 0x1.2p-13L) {
10+
long double x_sqr = x * x;
11+
return (x_sqr * x) * F64_1_DIV_3 - 0.5L * (x_sqr) + x;
12+
}
13+
return logl(1.0L + x);
14+
}

test/floating_point/float64_math/src/main.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,24 @@ static size_t run_test(void) {
4646
if (test_result(std::atanh( -0.9L), -1.472219489583220230004513715944L)) { return __LINE__; }
4747
if (test_result(std::atan ( 12.0L), 1.487655094906455389320653376989L)) { return __LINE__; }
4848
if (test_result(std::atan ( -1.1L), -0.832981266674431705417693561837L)) { return __LINE__; }
49+
4950
// if (test_result(std::sinh ( 5.0L), 74.20321057778875897700947199607L)) { return __LINE__; }
5051
// if (test_result(std::sinh ( -9.0L), -4051.541902082789960515223595898L)) { return __LINE__; }
5152
// if (test_result(std::cosh ( 8.0L), 1490.479161252178088627715460421L)) { return __LINE__; }
5253
// if (test_result(std::cosh ( -2.0L), 3.762195691083631459562213477774L)) { return __LINE__; }
5354
// if (test_result(std::tanh ( 0.8L), 0.664036770267848963684844656400L)) { return __LINE__; }
5455
// if (test_result(std::tanh ( -3.2L), -0.996682397839651156180968063061L)) { return __LINE__; }
56+
5557
if (test_result(std::exp ( 6.3L), 544.5719101259290330593886677332L)) { return __LINE__; }
5658
if (test_result(std::exp ( -4.2L), 0.014995576820477706211984360229L)) { return __LINE__; }
5759
if (test_result(std::log (1.0e-6L), -13.81551055796427410410794872811L)) { return __LINE__; }
5860
if (test_result(std::log (3.0e+8L), 19.51929303262047516353917687440L)) { return __LINE__; }
61+
62+
if (test_result(std::expm1 ( 0.2L), 0.221402758160169833921071994640L)) { return __LINE__; }
63+
if (test_result(std::expm1 (-1.0e-8L), -9.999999950000000166666666250e-9L)) { return __LINE__; }
64+
if (test_result(std::log1p ( -0.2L), -0.223143551314209755766295090310L)) { return __LINE__; }
65+
if (test_result(std::log1p ( 1.0e-8L), 9.999999950000000333333330833e-9L)) { return __LINE__; }
66+
5967
if (test_result(std::erfc ( -1.3L), 1.934007944940652436603893327504L)) { return __LINE__; }
6068
if (test_result(std::erfc ( 3.1L), 0.000011648657367199596033706164L)) { return __LINE__; }
6169
if (test_result(std::erf ( -2.2L), -0.998137153702018108556548243971L)) { return __LINE__; }

0 commit comments

Comments
 (0)