[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: int-function: programming error or bug?
From: |
John Cowan |
Subject: |
Re: int-function: programming error or bug? |
Date: |
Fri, 27 Feb 2009 10:31:55 -0500 |
User-agent: |
Mutt/1.5.13 (2006-08-11) |
Aron Brunner scripsit:
> for (alfa=8.6;alfa<=9.2;alfa=alfa+0.1) {
This line is your problem. Floating-point numbers do *not* behave like
mathematical real numbers; in particular, there is no guarantee that
a loop like this will iterate the correct number of times or have the
values you expect.
Instead, work your problem in terms of integers:
for (alfa = 86; alfa <= 92; alfa = alfa + 1) {
and divide by 10 just before doing the output.
--
John Cowan http://www.ccil.org/~cowan address@hidden
To say that Bilbo's breath was taken away is no description at all. There are
no words left to express his staggerment, since Men changed the language that
they learned of elves in the days when all the world was wonderful. --The Hobbit