Skip to content

Commit 01fdc47

Browse files
ZERICO2005mateoconlechuga
authored andcommitted
Fixed the precision of expm1(float x) when x is small. Two versions are provided, one with 12.0 bits of precision, and another with 16.0 bits of precision. Tested all inputs on x86_64
1 parent 266dffa commit 01fdc47

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

src/libc/expm1.c

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,24 @@
11
#include <math.h>
22

3-
float expm1f(float x)
3+
float M_expm1f(const float x)
44
{
5-
return expf(x) - 1; // FIXME: accuracy
5+
#if 1
6+
/**
7+
* 0x1.0p-12f: At least 12.0bits of precision
8+
*/
9+
if (fabsf(x) < 2.44140625e-4f /* 0x1.0p-12f */) {
10+
return x;
11+
}
12+
#else
13+
/**
14+
* 0x1.0p-8f: At least 16.0bits of precision
15+
*/
16+
if (fabsf(x) < 3.90625e-3f /* 0x1.0p-8f */) {
17+
return x + 0.5f * (x * x);
18+
}
19+
#endif
20+
return expf(x) - 1.0f;
621
}
722

23+
824
double expm1(double) __attribute__((alias("expm1f")));

0 commit comments

Comments
 (0)