Skip to content

Commit

Permalink
[libc][math] Fix setting exceptional value for tanf to work with gcc.
Browse files Browse the repository at this point in the history
See #59866

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D143098
  • Loading branch information
lntue committed Feb 1, 2023
1 parent 05e62db commit 135cea4
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion libc/src/math/generic/tanf.cpp
Expand Up @@ -97,7 +97,12 @@ LLVM_LIBC_FUNCTION(float, tanf, (float x)) {
// |x| = 0x1.143ec4p0
float sign = x_sign ? -1.0f : 1.0f;

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

return tmp;
}

// |x| > 0x1.ada6a8p+27f
Expand Down

0 comments on commit 135cea4

Please sign in to comment.