[libc-commits] [libc] 135cea4 - [libc][math] Fix setting exceptional value for tanf to work with gcc.
Tue Ly via libc-commits
libc-commits at lists.llvm.org
Wed Feb 1 12:53:54 PST 2023
Author: Tue Ly
Date: 2023-02-01T15:53:38-05:00
New Revision: 135cea495bc1f13a3f6538ccbd8db723e35cbb9d
URL: https://github.com/llvm/llvm-project/commit/135cea495bc1f13a3f6538ccbd8db723e35cbb9d
DIFF: https://github.com/llvm/llvm-project/commit/135cea495bc1f13a3f6538ccbd8db723e35cbb9d.diff
LOG: [libc][math] Fix setting exceptional value for tanf to work with gcc.
See https://github.com/llvm/llvm-project/issues/59866
Reviewed By: sivachandra
Differential Revision: https://reviews.llvm.org/D143098
Added:
Modified:
libc/src/math/generic/tanf.cpp
Removed:
################################################################################
diff --git a/libc/src/math/generic/tanf.cpp b/libc/src/math/generic/tanf.cpp
index 8b720c48e5de..0f3961ee5422 100644
--- a/libc/src/math/generic/tanf.cpp
+++ b/libc/src/math/generic/tanf.cpp
@@ -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
diff erent rounding modes.
+ volatile float tmp = 0x1.ddf9f4p0f;
+ tmp = fputil::multiply_add(sign, tmp, sign * 0x1.1p-24f);
+
+ return tmp;
}
// |x| > 0x1.ada6a8p+27f
More information about the libc-commits
mailing list