Sprout icon indicating copy to clipboard operation
Sprout copied to clipboard

pow wrong???

Open a-day-old-bagel opened this issue 5 years ago • 4 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 avatar Feb 04 '20 14:02 a-day-old-bagel

@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 avatar Oct 07 '20 11:10 OlivierSohn

@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?

a-day-old-bagel avatar Oct 08 '20 01:10 a-day-old-bagel

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 avatar Mar 26 '21 16:03 thinkoid

@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.

a-day-old-bagel avatar Mar 29 '21 01:03 a-day-old-bagel