|
|
Nicolas Alvarez wrote:
> Nicolas Alvarez wrote:
>> The problem with doing #declare V=V+1/100; is that it might not reach
>> 1.0000 exactly at the end of the loop (because of floating point
>> inaccuracies), so it might run one time too many.
>
> Or even if it runs runs the correct number of times, it may have slightly
> off values. And errors would *accumulate*.
>
> Tested in Python:
>>>> x = 0;
>>>> for i in range(0,100):
> ... x += 1.0/100;
> ...
>>>> print x;
> 1.0000000000000007
I see what you mean. I've never encountered any unwanted effects from
using fractional number-dependent loops, but it's a good thing to keep
in mind. Errors at the 16th decimal place are acceptable for most of the
things I do, but there will probably come a time when your input saves
me from beating my head against a hard surface :)
Sam
Post a reply to this message
|
|