V
vippstar
The return value of sqrt is implicity converted to long.Hello,
given a simple code:
#include <math.h>
long hyp(long height, long base)
{
return sqrt(height * height + base * base);
}
int main(void)
{
long h = hyp(10, 20);
return 0;
}
I compile this on Debian 4.0 (gcc (GCC) 4.1.2 20061115 (prerelease) (Debian
4.1.1-21)):
#gcc -ansi -pedantic -W -Wall -lm hyp.c
As I understand, according to standard sqrt returns double, but we assign
result to long, resulting in information loss. Nevertheless I get no
warning, why is it so?
Hope it's strictly C related question.
6.3.1.4 --
When a ï¬nite value of real floating type is converted to an integer
type other than _Bool,
the fractional part is discarded (i.e., the value is truncated toward
zero). If the value of
the integral part cannot be represented by the integer type, the
behavior is undeï¬ned.