I'm developing a program in C++. I have to perform some calculations with pow
of math library.
When a run this code:
#include <math.h>
#include <stdio.h>
int main (void)
{
unsigned long l;
double d1,d2,d3;
l = 13831305406817642647;
d1 = 2.;
d2 = *((double*)(&l));
d3 = pow(2.,d2);
printf ("%lu,%20.20f\n",*((unsigned long *)(&d1)),d1);
printf ("%lu,%20.20f\n",*((unsigned long *)(&d2)),d2);
printf ("%lu,%20.20f\n",*((unsigned long *)(&d3)),d3);
return 0;
}
With Fedora 35 I obtain:
4611686018427387904,2.00000000000000000000
13831305406817642647,-1.16674465427289475450
4601695688420081959,0.44542528011426657519
But with Fedora 36:
4611686018427387904,2.00000000000000000000
13831305406817642647,-1.16674465427289475450
4601695688420081958,0.44542528011426651968
I converted the doubles to a binary image of unsigned long to detect any change for just one bit.
In the third line you can observe this kind of change. Why I obtain a different result when I calculate over the same values with pow?
The full information about the version of Fedora (obtained with uname -r
):
For Fedora 35: 5.17.11-200.fc35.x86_64
For Fedora 36: 5.17.0-0.rc7.116.fc36.x86_64
Any help will be welcome.