googletest icon indicating copy to clipboard operation
googletest copied to clipboard

[Bug]: Rounding errors when printing floats/doubles

Open andreasbaumann opened this issue 1 year ago • 2 comments

Describe the issue

On IA-32 floating point literals are internally different, so a simple string compare with Print is not portable:

~/googletest/googletest/test/googletest-printers-test.cc:464: Failure
Expected equality of these values:
  "1.1"
  Print(1.10000002f)
    Which is: "1.10000002"

~/googletest/googletest/test/googletest-printers-test.cc:466: Failure
Expected equality of these values:
  "9e+09"
  Print(9e9f)
    Which is: "8.99999949e+09"

[  FAILED  ] PrintBuiltInTypeTest.FloatingPoints (0 ms)

Expected equality of these values:
  "(1.1)"
  PrintToString(internal::Optional<double>{1.1})
    Which is: "(1.1000000000000001)"

[  FAILED  ] PrintOptionalTest.Basic (0 ms)

Steps to reproduce the problem

make test on IA-32

What version of GoogleTest are you using?

1.13.0

What operating system and version are you using?

Archlinux32

What compiler and version are you using?

gcc (GCC) 12.2.1 20230111

What build system are you using?

cmake version 3.25.1 GNU Make 4.4.1

Additional context

No response

andreasbaumann avatar Apr 02 '23 07:04 andreasbaumann

hey, I'd like to work on this issue

NextThread avatar Aug 10 '23 04:08 NextThread

I'd be more than happy to take over the issue if someone can do a basic code walkthrough for me, regarding what all places do I need to look into and such.

shekhar-chauhan avatar Apr 09 '24 06:04 shekhar-chauhan