Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22113

C++ compile time result differs from run time result. Bug or valid behavior [duplicate]

$
0
0

This question already has an answer here:

I am doing a x86 cross compile using gcc 8.3.0 with -ffast-math enabled of the following code:

#include <cmath>

double diff_double(double in)
{
  auto tmp = 10 * std::log10(1. * 15e3);
  return tmp - (10 * std::log10(1. * in));
}

int main()
{
    return diff_double(15e3) == 0.;
}

On execution, I get a return value of 0 because the compiler optimized result for "tmp" differs from the runtime result.

Is this a valid behavior?

Thanks for your help


Viewing all articles
Browse latest Browse all 22113


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>