comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Simulation of fixed point in c WITH DIFFERENT BIT-WIDTH
Date: Thu, 3 Nov 2005 15:33:54 +0100
Date: 2005-11-03T15:33:58+01:00	[thread overview]
Message-ID: <hbojdi82rqii$.1jkm8bqzmm7ik$.dlg@40tude.net> (raw)
In-Reply-To: wccu0etyhar.fsf@shell01.TheWorld.com

On 03 Nov 2005 08:47:24 -0500, Robert A Duff wrote:

> Simon Wright <simon@pushface.org> writes:
> 
>> I'm not sure what is actually required for portability here. AARM95
>> 3.5.9(22-24) says
>> 
>>    The base range of an ordinary fixed point type need not include the
>>    specified bounds themselves so that the range specification can be
>>    given in a natural way, such as:
>> 
>>    type Fraction is delta 2.0**(-15) range -1.0 .. 1.0;
>> 
>>    With 2's complement hardware, such a type could have a signed
>>    16-bit representation, using 1 bit for the sign and 15 bits for
>>    fraction, resulting in a base range of -1.0 .. 1.0-2.0**(-15).
> 
> This is a language design flaw, in my opinion.  "T'Last in T" and
> "T'Last in T'Base" should both always be true.

Yes it is painful. It forces to use T'Last instead of 1.0. Then conversions
to and back from float (for internal FP computations) become tricky,
because T(Float'(1.0)) may raise Constraint_Error.

>  If you want 16 bits, you
> should say "-1.0 .. 1.0-2.0**(-15)."  After all, we don't play these
> games with integers -- if you say "range -2**15..2**15", you get at
> least 17 bits (probably 32 bits).
> 
> The "need not" in the above wording means that the implementation has a
> choice.  It can include 1.0 in the base range of Fraction, or not.
> Some implementations will include the upper bound if and only if it
> does not require extra bits.  I think that kind of non-portability
> is unhelpful to programmers.

The abstraction many people mean is actually:

   type Fraction is delta <> range -1.0 .. 1.0;
   for Fraction'Size use 16*8; -- Give me as much as you can

So delta isn't exactly 2.0**(-15), it is 2.0/(2.0**16 + 1.0).

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



  reply	other threads:[~2005-11-03 14:33 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-10-30 16:41 Simulation of fixed point in c WITH DIFFERENT BIT-WIDTH mnamky
2005-10-30 17:00 ` Dmitry A. Kazakov
2005-10-30 21:46 ` Gautier Write-only
2005-11-01  2:50 ` Steve
2005-11-02 10:42 ` Colin Paul Gloster
2005-11-02 20:43   ` Gautier Write-only
2005-11-03  6:13   ` Simon Wright
2005-11-03 10:46     ` Colin Paul Gloster
2005-11-03 13:47     ` Robert A Duff
2005-11-03 14:33       ` Dmitry A. Kazakov [this message]
2005-11-03 18:19         ` Jeffrey R. Carter
2005-11-03 20:55         ` Simon Wright
2005-11-02 10:57 ` Colin Paul Gloster
2005-11-02 14:49   ` Martin Krischik
2005-11-02 20:40   ` Gautier Write-only
replies disabled

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