On Sat, 8 Sep 2018, sisyphus1@xxxxxxxxxxxxxxx wrote:
Hi,
The demo program:
/****/
/* try.c */
#include <stdio.h>
#include <math.h>
int main(void) {
int x = -1074;
printf("%e\n", pow (2.0, (double)x));
printf("%e\n", pow (2.0, x));
return 0;
}
/****/
If I build that program (using g++ version 7.3.0) with "g++ -ansi -o try
try.c" I get output of:
4.940656e-324
0.000000e+000
whereas I expected output to be:
4.940656e-324
4.940656e-324
I guess that means that either my expectation is buggy, or something else is
buggy.
Note 1:
If the "-ansi" switch is omitted, then the output matches my expectation.
Don't use -ansi, use -std= . Most likely you did not mean to use
-std=c++98.
The exact set of overloads of pow in the C++ standard has varied with
time, https://en.cppreference.com/w/cpp/numeric/math/pow gives some idea.
Note 2:
If cmath is #included instead of math.h, then the output matches my
expectation.
If you include cmath and not math.h, you should use std::pow.
--
Marc Glisse