Skip to content

Commit 135cea4

Browse files
committed
[libc][math] Fix setting exceptional value for tanf to work with gcc.
See llvm#59866 Reviewed By: sivachandra Differential Revision: https://reviews.llvm.org/D143098
1 parent 05e62db commit 135cea4

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

libc/src/math/generic/tanf.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,12 @@ LLVM_LIBC_FUNCTION(float, tanf, (float x)) {
9797
// |x| = 0x1.143ec4p0
9898
float sign = x_sign ? -1.0f : 1.0f;
9999

100-
return fputil::multiply_add(sign, 0x1.ddf9f4p0f, sign * 0x1.1p-24f);
100+
// volatile is used to prevent compiler (gcc) from optimizing the
101+
// computation, making the results incorrect in different rounding modes.
102+
volatile float tmp = 0x1.ddf9f4p0f;
103+
tmp = fputil::multiply_add(sign, tmp, sign * 0x1.1p-24f);
104+
105+
return tmp;
101106
}
102107

103108
// |x| > 0x1.ada6a8p+27f

0 commit comments

Comments
 (0)