Mail Archives: djgpp/1998/04/12/10:30:48
Eli Zaretskii wrote:
>
> On Thu, 9 Apr 1998, Michael Phelps wrote:
>
> > number %= (int)pow(10, digit_to_start_with);
> > number /= (int)pow(10, (digit_to_start_with - length));
>
> Don't forget that 10 doesn't have an exact representation as a
> floating-point number. So it is subject to round-off errors.
Not quite. 10, as all integers, *has* an exact floating
point representation (and all basic, +,-,*,/, integer calculations are
correctly done in floats). However, pow() (or at least libc pow()) uses
log2(10) to make its calculations, and log2(10) has no exact
representation as a floating point number...
Regards,
Francois
- Raw text -