Skip to content

Commit a79336e

Browse files
committed
fmath: workaround for bug in sinf_approx
A more correct solutions is being investigated
1 parent 2787538 commit a79336e

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/fmath.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,10 @@
55
*/
66
#include "fmath.h"
77
#include "debug.h"
8+
#include "utils.h"
89
#include <string.h>
910
#include <stdint.h>
1011

11-
/// Mark a branch as likely to be taken
12-
#define LIKELY(x) __builtin_expect((x),1)
13-
1412
static const float pi_hi = 3.14159274e+00f; // 0x1.921fb6p+01
1513
static const float pi_lo =-8.74227766e-08f; // -0x1.777a5cp-24
1614
static const float half_pi_hi = 1.57079637e+0f; // 0x1.921fb6p+0
@@ -42,7 +40,12 @@ float fm_sinf_approx(float x, int approx) {
4240
// very accurate for large numbers, so it will introduce more error compared
4341
// to the 5 ULP figure.
4442
x = fm_fmodf(x+pi_hi, 2*pi_hi) - pi_hi;
45-
return sinf_approx(x, approx);
43+
x = sinf_approx(x, approx);
44+
// FIXME: workaround for a bug in our sinf approximation. We found at least
45+
// one input (0xbfc915a2 => -1.570973) that produces an out of bounds result
46+
// -1.000000119209289551 (0xbf800001).
47+
x = CLAMP(x, -1.0f, 1.0f);
48+
return x;
4649
}
4750

4851
float fm_sinf(float x) {

0 commit comments

Comments
 (0)