-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[libc] fix error: implicit conversion loses floating-point precision: 'double' to 'float' in shared_math_test.cpp #159934
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@llvm/pr-subscribers-libc Author: Maksim Levental (makslevental) ChangesThis test fails under -Werror=implicit-float-conversion (like in our pre-merge CI) because
Fixes #159932 Full diff: https://github.com/llvm/llvm-project/pull/159934.diff 1 Files Affected:
diff --git a/libc/test/shared/shared_math_test.cpp b/libc/test/shared/shared_math_test.cpp
index 9e4d4d52e7f5e..bfff5ecb8cf81 100644
--- a/libc/test/shared/shared_math_test.cpp
+++ b/libc/test/shared/shared_math_test.cpp
@@ -57,7 +57,7 @@ TEST(LlvmLibcSharedMathTest, AllFloat) {
EXPECT_FP_EQ(0x1p+0f, LIBC_NAMESPACE::shared::cosf(0.0f));
EXPECT_FP_EQ(0x1p+0f, LIBC_NAMESPACE::shared::coshf(0.0f));
EXPECT_FP_EQ(0x1p+0f, LIBC_NAMESPACE::shared::cospif(0.0f));
- EXPECT_FP_EQ(0x0p+0f, LIBC_NAMESPACE::shared::dsqrtl(0.0f));
+ EXPECT_FP_EQ(0x0p+0f, (float)LIBC_NAMESPACE::shared::dsqrtl(0.0f));
EXPECT_FP_EQ(0x0p+0f, LIBC_NAMESPACE::shared::erff(0.0f));
EXPECT_FP_EQ(0x1p+0f, LIBC_NAMESPACE::shared::exp10f(0.0f));
EXPECT_FP_EQ(0x1p+0f, LIBC_NAMESPACE::shared::expf(0.0f));
|
Note, I'm not sure if this is the right - the alternative could be EXPECT_FP_EQ(0x0p+0, LIBC_NAMESPACE::shared::dsqrtl(0.0)); but all the values in this test are single 🤷. |
@@ -57,7 +57,7 @@ TEST(LlvmLibcSharedMathTest, AllFloat) { | |||
EXPECT_FP_EQ(0x1p+0f, LIBC_NAMESPACE::shared::cosf(0.0f)); | |||
EXPECT_FP_EQ(0x1p+0f, LIBC_NAMESPACE::shared::coshf(0.0f)); | |||
EXPECT_FP_EQ(0x1p+0f, LIBC_NAMESPACE::shared::cospif(0.0f)); | |||
EXPECT_FP_EQ(0x0p+0f, LIBC_NAMESPACE::shared::dsqrtl(0.0f)); | |||
EXPECT_FP_EQ(0x0p+0f, (float)LIBC_NAMESPACE::shared::dsqrtl(0.0f)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Either just use the double constant without the f
or use a C++ cast.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it fixes the warning without the f
constant then that's probably the better solution, since technically the double result could be outisde a float's ULP and get rounded to zero. Though the chances of that happening are quite slim.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
f40bc6f
to
44882b2
Compare
44882b2
to
2db3b36
Compare
… 'double' to 'float' in shared_math_test.cpp
2db3b36
to
e6bc6f8
Compare
The input should be 0.0L and the output should be 0.0 |
This test fails under
-Werror=implicit-float-conversion
(like in our pre-merge CI) becausedsqrtl
returns a doublellvm-project/libc/src/__support/math/dsqrtl.h
Line 18 in 2b937da
Fixes #159932