From: Dirk Herrmann <fight_spam@invalid.invalid>
Subject: Re: conversions between fixed-point types
Date: Sun, 20 Sep 2009 21:13:40 +0200
Date: 2009-09-20T21:13:40+02:00 [thread overview]
Message-ID: <h95ut9$6lk$1@news.albasani.net> (raw)
In-Reply-To: <nospam-F2F5EF.11185320092009@news.aioe.org>
John B. Matthews wrote:
> I see what you mean. Here's my understanding: The Ada Reference Manual
> [1], section 3.6(32) on numeric type conversion refers to section G.2.1
> and G.2.3 for floating- and fixed-point arithmetic, respectively. The
> value -1.5 is exactly representable as type Float, but not as type FpB.
> The conversion to FpB is governed by G.2.3(10), so both -1.2 and -1.6
> are in the close result set. Because FpB is an ordinary fixed point
> type, rather than a decimal fixed point type, there's no requirement to
> prefer one element of the result set over another.
Thanks for your detailed analysis. It confirms what I had suspected. The bad
thing seems to be that there is no easy approach to achieve a more specific
behaviour.
> The conversion back
> to Float is discussed in G.2.1(10). Because small is not a power of
> T'Machine_Radix, the result is implementation defined. I'm not sure if
> GNAT fully implements Annex G, and I may be overlooking something
> obvious.
I see. Probably the conversion back to float itself was not the problem, though.
> From another perspective, I'm curious to know why the conversions are
> needed.
As I said, in my company we are using lots of fixed-point arithmetics. Most
of it is in powers of 2, but even then you have to care about rounding when
converting between different fixed-point representations.
However, some data is represented with different resolutions. For example,
when you have some code that is executed cyclically every 100ms and delivers
sensor sample values. Then, a gradient of two sensor samples is
(value2-value1)/dt. Since dt is known to be 100ms, you can save a division
operation if you choose a small of 100ms for dt.
At some point during the calculation, however, you will have to make the
conversion from the world of types with "physical" representations (like,
small of 100ms), to the world of binary representations. This is the moment
when conversions between smalls of 0.5 and 0.4 can be interesting.
Best regards,
Dirk
next prev parent reply other threads:[~2009-09-20 19:13 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-09-18 21:35 conversions between fixed-point types Dirk Herrmann
2009-09-18 22:42 ` Adam Beneschan
2009-09-19 12:41 ` Dirk Herrmann
2009-09-19 14:48 ` John B. Matthews
2009-09-20 8:15 ` Dirk Herrmann
2009-09-20 14:22 ` Robert A Duff
2009-09-20 18:55 ` Dirk Herrmann
2009-09-20 20:34 ` Simon Clubley
2009-09-23 20:46 ` Dirk Herrmann
2009-09-27 17:15 ` Simon Clubley
2009-09-27 19:22 ` sjw
2009-09-28 20:18 ` Dirk Herrmann
2009-09-28 18:37 ` Robert A Duff
2009-09-28 20:50 ` Dirk Herrmann
2009-09-20 15:18 ` John B. Matthews
2009-09-20 19:13 ` Dirk Herrmann [this message]
2009-09-20 20:09 ` tmoran
2009-09-21 17:24 ` Jeffrey R. Carter
2009-09-23 20:57 ` Dirk Herrmann
2009-09-23 22:28 ` Jeffrey R. Carter
2009-09-24 1:05 ` Adam Beneschan
2009-09-24 3:57 ` Jeffrey R. Carter
2009-09-25 8:47 ` Stuart
2009-09-25 20:41 ` sjw
2009-09-25 21:58 ` Jeffrey R. Carter
2009-09-28 13:40 ` Stuart
2009-09-26 14:43 ` Dirk Herrmann
2009-09-28 15:15 ` Adam Beneschan
2009-09-26 14:31 ` Dirk Herrmann
2009-09-19 18:38 ` tmoran
2009-09-20 8:22 ` sjw
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox