Re: Does the order matter to add a sequence of floating numbers
- From: Chris Bore <chris.bore@xxxxxxxxx>
- Date: Wed, 31 Oct 2007 04:49:08 -0700
On Oct 30, 4:10 pm, JosephLee <shoupe...@xxxxxxxxx> wrote:
Let's say float arr[100], we want to add them up, does the order
matter? what is the different between arr[0] +..+ arr[99], and
arr[99]+...+arr[0]?
Floating point addition is not associative. That means, the order does
matter. Within an expression, float operations should be evaluated in
a strict sequence that is defined in the standards. The reason is that
in float additions the two numbers must be shifted so that their
exponents match, which means truncation errors depend on the size of
each number. The effect may be highly significant - for example in IIR
filters and other operations that use feedback.
In C, the order for floating point evaluation is defined as left-to-
right through an expression, and respecting the order of sequence
points (, and ;). Many C compilers ignore the requirement to respect
the order of sequence points (strictly, all operations between two
sequence points must be completed and all their side effects evaluated
before any operation within the next papir of sequence points can
begin). Some compilers assume float is associative, which leads to
different results on different optimiztion settings. Some compilers
allow a pragma like dirty_float.
Chris
================
Chris Bore
BORES Signal Processing
www.bores.com
.
- References:
- Does the order matter to add a sequence of floating numbers
- From: JosephLee
- Does the order matter to add a sequence of floating numbers
- Prev by Date: Re: Calculate the precision of a floating point number (ie: the number of decimal places)
- Next by Date: Re: Calculate the precision of a floating point number (ie: the number of decimal places)
- Previous by thread: Re: Does the order matter to add a sequence of floating numbers
- Next by thread: Binary search trees
- Index(es):
Relevant Pages
|