diff options
author | Tom Hughes <tomhughes@google.com> | 2023-01-17 19:44:04 (GMT) |
---|---|---|
committer | Copybara-Service <copybara-worker@google.com> | 2023-01-17 19:44:46 (GMT) |
commit | 5cd81a7848203d3df6959c148eb91f1a4ff32c1d (patch) | |
tree | cc85122a366921cc024bf8b2c5b100250b35fe2f | |
parent | 9d697cc81cafa7e6c35d056cd8a31eac725a96ea (diff) | |
download | googletest-5cd81a7848203d3df6959c148eb91f1a4ff32c1d.zip googletest-5cd81a7848203d3df6959c148eb91f1a4ff32c1d.tar.gz googletest-5cd81a7848203d3df6959c148eb91f1a4ff32c1d.tar.bz2 |
Fix -Wimplicit-int-float-conversion warning
We're intentionally losing precision in this case, so add a cast.
googletest/googletest/include/gtest/gtest-printers.h:532:9: error:
implicit conversion from 'int32_t' (aka 'int') to 'float' may lose precision
[-Werror,-Wimplicit-int-float-conversion]
if (static_cast<int32_t>(val * mulfor6 + 0.5) / mulfor6 == val) return 6;
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~
googletest/googletest/include/gtest/gtest-printers.h:544:9: error:
implicit conversion from 'int32_t' (aka 'int') to 'float' may lose precision
[-Werror,-Wimplicit-int-float-conversion]
if (static_cast<int32_t>(val / divfor6 + 0.5) * divfor6 == val) return 6;
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~
PiperOrigin-RevId: 502646042
Change-Id: I05989ee42675b531a9907616c9582a5a7c77bed6
-rw-r--r-- | googletest/include/gtest/gtest-printers.h | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/googletest/include/gtest/gtest-printers.h b/googletest/include/gtest/gtest-printers.h index 0055e37..7d7e77c 100644 --- a/googletest/include/gtest/gtest-printers.h +++ b/googletest/include/gtest/gtest-printers.h @@ -529,7 +529,10 @@ int AppropriateResolution(FloatType val) { } else if (val >= 0.0001) { mulfor6 = 1e9; } - if (static_cast<int32_t>(val * mulfor6 + 0.5) / mulfor6 == val) return 6; + if (static_cast<float>(static_cast<int32_t>(val * mulfor6 + 0.5)) / + mulfor6 == + val) + return 6; } else if (val < 1e10) { FloatType divfor6 = 1.0; if (val >= 1e9) { // 1,000,000,000 to 9,999,999,999 @@ -541,7 +544,10 @@ int AppropriateResolution(FloatType val) { } else if (val >= 1e6) { // 1,000,000 to 9,999,999 divfor6 = 10; } - if (static_cast<int32_t>(val / divfor6 + 0.5) * divfor6 == val) return 6; + if (static_cast<float>(static_cast<int32_t>(val / divfor6 + 0.5)) * + divfor6 == + val) + return 6; } return full; } |