bolero-MURAKAMI / Sprout

C++11/14 constexpr based Containers, Algorithms, Random numbers, Parsing, Ray tracing, Synthesizer, and others.

Home Page:http://bolero-murakami.github.io/Sprout/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

pow wrong???

a-day-old-bagel opened this issue · comments

Building with Clang 9.0.1 on Manjaro Linux, I'm getting the result that
sprout::pow(8, 4) is equal to 4095 instead of 4096. Am I dumb, or is there a problem here?

Ok, just tried it with gcc 9.2.0 and it gives the right answer. (4096). Spooky.

@a-day-old-bagel I looked at the code here and noticed that sprout::pow returns a floating point value when integral typed arguments are passed, so maybe in your case it returns 4095.999999999... and then you or your compiler casts that to an integral type, so you get 4095 ?

@OlivierSohn Well switching the compiler from gcc to clang was the literal only thing I had to change to reproduce the problem, so I don't think it was any cast of mine. I decided not to use this library for the moment, since no matter who's fault it is, if I'm getting different results between compilers (all else remaining constant) from a math library, that's not a good place to be.

4096 has a perfect representation in floating point, too, so if for some reason the function is returning 4095.9999999..., that's something that it should not be doing, right?

clang 9.0.1 on Arch Linux, installed from the LLVM github releases fails to reproduce the reported issue. If it is still a problem for you and you wish to investigate further I would like to help.

@thinkoid Let me see if I can dig up that old system I had back then and reproduce the problem. If you don't hear back from me after a while we can probably just close this issue.