comp.lang.ada
 help / color / mirror / Atom feed
From: Mark Johnson <mark_h_johnson@raytheon.com>
Subject: Re: float with 24-bit resolution
Date: Fri, 22 Aug 2003 09:07:35 -0500
Date: 2003-08-22T09:07:35-05:00	[thread overview]
Message-ID: <3F4623A7.6718B8C0@raytheon.com> (raw)
In-Reply-To: m3brujrsd6.fsf@insalien.org

Ludovic Brenta wrote:
> 
> Mark Johnson <mark_h_johnson@raytheon.com> writes:
> > [snip explanation of integer based fixed point decimal values]
> 
> What you describe is a second-best solution, and by your own accord
> you only used it because the target hardware did not support
> packed-decimal representations.  Your divide-by-10 routine was the
> weak point; 10 happens not to be a power of two, and therefore any
> division of a binary number by 10 is bound to introduce rounding and
> imprecision.  
Perhaps you don't understand the solution I proposed. Using the example
I provided, to get the digits for display of 0.42, you would:
 - divide 42 by 10, getting result 4 and remainder 2 (last digit)
 - note that 4<10, getting result 0 and remainder 4 (second digit)
 - generate the decimal point
 - generate the zero
and display the value 0.42. No round off errors or any imprecision. This
approach can be generalized to any fixed point decimal type. Depending
on the range of values / precision required, it may require the
occasional use of double precision values and integer division that
produces both the result and remainder.

As I mentioned before, you certainly have to do the "right thing" when
it comes to doing arithmetic and conversions to other forms, but fixed
point decimal arithmetic without packed decimal data types can be done
without introducing any errors.

> You may minimise the impact of that by doing the
> division as late as possible, e.g. for display purposes; this is
> probably what made the solution acceptable to you.  However, if your
> program must write to a text file that serves as input to another
> program (and then another, etc.), then the loss of precision quickly
> becomes unacceptable.
Once you understand how to generate the correct values w/o any error,
you will find that this statement does not apply.
  --Mark



  reply	other threads:[~2003-08-22 14:07 UTC|newest]

Thread overview: 49+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-08-15 11:59 float with 24-bit resolution mailbox
2003-08-15 12:24 ` Jeffrey Creem
2003-08-15 12:52   ` Adrian Hoe
2003-08-15 12:54     ` Adrian Hoe
2003-08-15 15:01       ` Jeffrey Creem
2003-08-16 15:29         ` Matthew Heaney
2003-08-15 13:39     ` Mark Johnson
2003-08-15 16:56       ` Robert I. Eachus
2003-08-15 18:08         ` Mark Johnson
2003-08-16  3:30           ` Robert I. Eachus
2003-08-18 13:39             ` Mark Johnson
2003-08-20 21:12               ` Robert I. Eachus
2003-08-21 13:38                 ` Mark Johnson
2003-08-16 15:32         ` Matthew Heaney
2003-08-16 15:26     ` Matthew Heaney
2003-08-15 19:56   ` Simon Wright
2003-08-16  4:21     ` Adrian Hoe
2003-08-16 12:59       ` Jeffrey Creem
2003-08-16 15:35     ` Matthew Heaney
2003-08-17 11:40       ` Simon Wright
2003-08-17 13:46         ` Matthew Heaney
2003-08-18  5:05       ` Adrian Hoe
2003-08-18 13:14         ` Matthew Heaney
2003-08-19  3:09           ` Adrian Hoe
2003-08-19 13:00             ` Matthew Heaney
2003-08-30  5:02           ` Randy Brukardt
2003-09-02 16:05             ` Adrian Hoe
2003-09-03  3:31               ` Matthew Heaney
2003-09-03 20:46                 ` Simon Wright
2003-09-04  1:43                   ` Randy Brukardt
2003-09-04  9:53                     ` Jean-Pierre Rosen
2003-09-05  3:46                       ` Randy Brukardt
2003-09-05 17:16                     ` Warren W. Gay VE3WWG
2003-09-05 19:37                       ` Randy Brukardt
2003-09-06 20:48                         ` Warren W. Gay VE3WWG
2003-09-08  7:53                         ` Dmitry A. Kazakov
2003-09-04  1:45                 ` Randy Brukardt
2003-08-16  3:42   ` Robert I. Eachus
2003-08-16 15:38     ` Matthew Heaney
2003-08-16 16:36       ` Robert I. Eachus
2003-08-16 15:22 ` Matthew Heaney
2003-08-17 11:46   ` Simon Wright
2003-08-18 10:04     ` Martin Dowie
2003-08-20 19:53       ` Robert I. Eachus
2003-08-20 23:36         ` Ludovic Brenta
2003-08-21 13:54           ` Mark Johnson
2003-08-21 14:35             ` Ludovic Brenta
2003-08-22 14:07               ` Mark Johnson [this message]
2003-08-22 15:12                 ` Jean-Pierre Rosen
replies disabled

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