comp.lang.ada
 help / color / mirror / Atom feed
From: Gautier write-only <gautier_niouzes@hotmail.com>
Subject: Re: Cannot summate small float values
Date: Sun, 21 Nov 2010 17:23:17 -0800 (PST)
Date: 2010-11-21T17:23:17-08:00	[thread overview]
Message-ID: <decc1511-11db-4b82-a787-f8cd9457b46a@s5g2000yqm.googlegroups.com> (raw)
In-Reply-To: d21c568c-fddd-4da6-8131-43d18610397a@y23g2000yqd.googlegroups.com

On 21 nov, 22:06, tolkamp wrote:

> Thank you your reaction.
> Using your procedure Sums I found out that when the start value of X <
> 0.24 the summation works correct with Dx = 1.0E-8
> When start X > 0.25 the summation remains 0.250000000.

Anyway, since Dx is constant, you should never add it over and over:
it will accumulate numerical errors (with very rare exceptions) even
if it looks to work correctly on a few iterations.
The right way is
  X:= N * Real(Dx);
  N:= N + 1;
where Real is your floating-point type.
Cheers
______________________________________________________________
Gautier's Ada programming -- http://gautiersblog.blogspot.com/
NB: follow the above link for a working e-mail address




  parent reply	other threads:[~2010-11-22  1:23 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-11-20 12:47 Cannot summate small float values tolkamp
2010-11-20 13:49 ` Niklas Holsti
2010-11-21 21:06   ` tolkamp
2010-11-21 21:18     ` Niklas Holsti
2010-11-22  1:23     ` Gautier write-only [this message]
2010-11-22  8:35     ` Julian Leyh
2010-11-22 16:30     ` Adam Beneschan
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox