Re: Rounding error when doing float-to-integer
From: Richard Maine (nospam_at_see.signature)
Date: 10/16/03
- Next message: Glen Herrmannsfeldt: "Re: Rounding error when doing float-to-integer"
- Previous message: Gordon Sande: "Re: sound with fortran (gnu g77)"
- In reply to: José Rui Faustino de Sousa: "Re: Rounding error when doing float-to-integer"
- Next in thread: Glen Herrmannsfeldt: "Re: Rounding error when doing float-to-integer"
- Reply: Glen Herrmannsfeldt: "Re: Rounding error when doing float-to-integer"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 15 Oct 2003 16:12:53 -0700
José Rui Faustino de Sousa <jrfsousaKXVAMC@esoterica.pt> writes:
> "Richard Maine" <nospam@see.signature> wrote in message
> > For example, if you have x+y+z in two different places in the
> > code, I don't think there is any basis for believing that the
> > two results will necessarily be the same. In one case, it
> > might be evaluated as (x+y)+z, while in another it might be
> > x+(y+z). Rounding can make those results different.
> >
>
> OK that I knew. But is it still not assured to get the same result if
> one explicitly writes ((x+y)+z)?
Now you are getting into the subtle part. I argue that it is not
assured, but I think there might be people who argue otherwise. I
have too much real work (well, anyway, work other than posting here)
to feel like resurecting that debate, or even checking the fine points
to see whether they apply to exactly this case or not, so I restrict
myself to the following advice.
Regardless of whether or not a strict interpretation of the standard
requires the two evaluations of (x+y)+z to get the exact same result,
the cautious programmer is well advised not to count on it. Some real
compilers in some situations are likely not to get the same result.
You can spend your time debating whether your code should have worked
or you can make sure that your code actually does work. While
admitting the philosophical merits of the abstract debate, I still
advise the cautious programmer to write code that works anyway.
There are very few things that you can in practice count on being
exact in floating point world. I'd say that some of the things that
you *CAN* actually count on in real life are things that the Fortran
standard doesn't guarantee. (Mostly things like that small values
with no fractional part are going to be exactly representable).
-- Richard Maine | Good judgment comes from experience; email: my first.last at org.domain | experience comes from bad judgment. org: nasa, domain: gov | -- Mark Twain
- Next message: Glen Herrmannsfeldt: "Re: Rounding error when doing float-to-integer"
- Previous message: Gordon Sande: "Re: sound with fortran (gnu g77)"
- In reply to: José Rui Faustino de Sousa: "Re: Rounding error when doing float-to-integer"
- Next in thread: Glen Herrmannsfeldt: "Re: Rounding error when doing float-to-integer"
- Reply: Glen Herrmannsfeldt: "Re: Rounding error when doing float-to-integer"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|