[gccsdk] [Bug 250] New: GCC 4.7.4 Rel 1 Dev 2014-01-08: sqrt function

Duncan Moore duncan.moore at gmx.com
Mon Mar 24 11:12:38 PDT 2014


On 22/03/2014 20:16, Bob Brand wrote:
> Hello Duncan,
>
> In message <bug-250-73 at http.www.riscos.info/bugzilla3/> you wrote:
>
>>    printf("%f\n",sqrt(2.0));
> Looks like you have fallen in a classic C pitfall:
> passing a double argument to a vararg/stdarg function
> but interpreting it as float.
>

No, "%f" is a correct format specifier for double.

The same wrong output is given with C++ iostreams, where there's no 
format specifier:

#include <iostream>
#include <cmath>
int main(void) {
   std::cout << sqrt(2.0) << std::endl;
   return 0;
}

*g++ sqrt.cc
*a/out
1.4375

Regards, Duncan





More information about the gcc mailing list