comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: OT: definition of "significant figures"
Date: Sun, 31 Jul 2005 10:36:22 +0200
Date: 2005-07-31T10:36:22+02:00	[thread overview]
Message-ID: <16rocpq66tyxr.x4l3edv2c9ce$.dlg@40tude.net> (raw)
In-Reply-To: wtadnWiKJtOxMnTfRVn-ug@comcast.com

On Thu, 28 Jul 2005 23:23:08 -0500, tmoran@acm.org wrote:

> Given a set of measurements x(i), I'd like to print their average to
> the "correct" number of significant figures.  eg
>   1.11, 1.12, 1.08 => "1.1",   1.11, 1.25, 1.35 => "1"
> I've got some adhocery that more or less does it, but is there a
> moderately standard, formal, definition?

1.11, 1.25, 1.35 => "1.0", I'd say. Zero is a figure as any other.

BTW, the result depends on the way you are evaluating the average, whether
fixed or floating-point is used. If you have, say, 100_000 approximately
same FP numbers, then a naive implementation

Average := 0.0;
for I in X'Range loop
   Average := Average + X (I);
end loop;
Average := Average / Float (X'Length);

would perform awfully. Near to the end of the loop you will heavily loose
accuracy. Because the ratio Sum to X (I) would be around 100_000. To
cascade it would be a better idea.

So basically it is difficult to tell in advance how many "right" figures
you get.

Also you can use interval arithmetic, then you'll exactly know the accuracy
of the result.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



  parent reply	other threads:[~2005-07-31  8:36 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-07-29  4:23 OT: definition of "significant figures" tmoran
2005-07-29 14:46 ` Jacob Sparre Andersen
2005-07-30 23:44   ` Dr. Adrian Wrigley
2005-07-31  7:02     ` tmoran
2005-08-01  7:31     ` Jacob Sparre Andersen
2005-07-31  8:36 ` Dmitry A. Kazakov [this message]
2005-07-31 19:08   ` tmoran
     [not found] <e3nqe19bqp99h20anetgc7m63ai8ol84nv@4ax.com>
2005-08-01  4:11 ` tmoran
2005-08-01  6:50 ` tmoran
2005-08-01 16:58   ` tmoran
2005-08-01 23:56     ` tmoran
replies disabled

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