May 7, 2010 at 10:02pm May 7, 2010 at 10:02pm UTC
I have:
printf("%f", ceil(1/2)); //0.0000
Can somebody explain me this outcome. I have something similar in my program end it cause everything to go wrong
May 7, 2010 at 10:06pm May 7, 2010 at 10:06pm UTC
i tried:
printf("%f", ceil(1/(2+0.0))); //1.0000
worked but still ...
May 8, 2010 at 3:23am May 8, 2010 at 3:23am UTC
1/2 is performed using integer math since both 1 and 2 are integers.
2+0.0 is a floating point expression (due to the 0.0) and therefore
the division is performed using floating point (the denominator is
a floating point result).
May 8, 2010 at 5:09am May 8, 2010 at 5:09am UTC
is there other way to do it except adding 0.0?
May 9, 2010 at 1:00pm May 9, 2010 at 1:00pm UTC
another similar problem:
int z;
z=3;
printf("%d", (int)pow(10,z-1)); //99
what is going on
May 9, 2010 at 3:13pm May 9, 2010 at 3:13pm UTC
Last edited on May 9, 2010 at 3:19pm May 9, 2010 at 3:19pm UTC