Monday, 24 March 2014

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

On 22/03/2014 20:16, Bob Brand wrote:
> Hello Duncan,
>
> In message <bug-250-73@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


_______________________________________________
GCCSDK mailing list gcc@gccsdk.riscos.info
Bugzilla: http://www.riscos.info/bugzilla/index.cgi
List Info: http://www.riscos.info/mailman/listinfo/gcc
Main Page: http://www.riscos.info/index.php/GCCSDK

No comments:

Post a Comment