comp.lang.ada
 help / color / mirror / Atom feed
From: Nick Roberts <nick.roberts@acm.org>
Subject: Re: Why no 'Floor for fixed point types
Date: Fri, 24 Oct 2003 22:46:14 +0100
Date: 2003-10-24T22:46:14+01:00	[thread overview]
Message-ID: <bnc6j8$v8sd4$1@ID-25716.news.uni-berlin.de> (raw)
In-Reply-To: <mailman.194.1066939697.25614.comp.lang.ada@ada-france.org>

Duncan Sands wrote:

> I think the subject says it all.  Just curious.
> 
> Duncan.

For a fixed point type Tf -- assuming it has a delta which is less than 1 
-- you can write:

    Scale: constant := 1/Tf'Small;

    type Ti is range Tf'First*Scale .. Tf'Last*Scale;

    function Scaled_Floor (X: in Tf) return Ti is
    begin
       return Ti(X*Scale) - Ti(X*Scale) mod Ti(Scale);
    end;

The basic idea is that with fixed point types, a 'floor' function will 
inevitably need to be scaled, and the integer type it returns needs to be 
customised to the fixed point type (its range and delta) and the chosen 
scale. I've shown a scale of 1/Tf'Small, but the chances are that the scale 
you will require in a certain situation will be different (it might be unity).

A little more information about your specific problem would enable us to 
give a more detailed diagnosis.

-- 
Nick Roberts




  parent reply	other threads:[~2003-10-24 21:46 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-10-23 20:09 Why no 'Floor for fixed point types Duncan Sands
2003-10-23 22:06 ` Robert I. Eachus
2003-10-24 16:00   ` Stephen Leake
2003-10-24 18:13     ` Duncan Sands
2003-10-23 23:10 ` Martin Dowie
2003-10-24 21:46 ` Nick Roberts [this message]
2003-10-25  4:29   ` Robert I. Eachus
2003-10-25 20:42     ` Nick Roberts
2003-10-25 22:40       ` Robert I. Eachus
2003-10-27 18:59         ` Randy Brukardt
2003-10-28  1:19           ` Robert I. Eachus
2003-10-28 18:23             ` Nick Roberts
2003-10-28 18:34               ` Stephane Richard
2003-10-29 19:26               ` Randy Brukardt
2003-10-30  4:55                 ` Robert I. Eachus
2003-10-28 18:10         ` Nick Roberts
2003-10-27 18:49       ` Randy Brukardt
2003-10-28 18:32         ` Nick Roberts
2003-10-29 19:29           ` Randy Brukardt
2003-10-30 23:41             ` Nick Roberts
2003-10-31 22:25               ` Randy Brukardt
2003-11-06  2:41                 ` Nick Roberts
replies disabled

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