comp.lang.ada
 help / color / mirror / Atom feed
From: Simon Wright <simon@pushface.org>
Subject: Re: Truncating a fixed-point value
Date: Sat, 10 Jul 2010 09:12:55 +0100
Date: 2010-07-10T09:12:55+01:00	[thread overview]
Message-ID: <m28w5jwy9k.fsf@pushface.org> (raw)
In-Reply-To: 6d238b76-10ba-4ac8-ac16-86bc691fc96f@v6g2000prd.googlegroups.com

Adam Beneschan <adam@irvine.com> writes:

> On Jul 9, 1:34 pm, Simon Wright <si...@pushface.org> wrote:
>> Adam Beneschan <a...@irvine.com> writes:
>> > I must be suffering from an embarrassing mental block, because I'm
>> > sure there's a simple solution, but I can't see what it is.
>>
>> > I have a value X of a fixed-point type, X >= 0.0, and I need to
>> > compute Floor(X) as an Integer.  'Truncation and 'Floor aren't defined
>> > for fixed-point types; the type conversion Integer(X) rounds; and
>> > Integer(X-0.5) fails if X=0.0.
>>
>> > How do others do this?  Or do I have to resort to an IF statement (or
>> > conditional expression in Ada 2012) to handle the different cases?
>>
>> Looks as though Integer(X+0.5)-1 might do the trick ..
>
> Yes, it looks like it, as long as X >= 0.0 and 0.5 is a model number
> of the fixed-point type (I think I'm using the right term).  Those
> conditions do hold for the code I need it for.  It isn't useful for
> negative numbers---it yields -2 if X=-1.0, which is not useful whether
> you want a truncation or a floor operation---but I did stipulate
> nonnegative X in my original question.

I hadn't considered the model number aspect, but nonnegative X is
indeed necessary for this solution!



  parent reply	other threads:[~2010-07-10  8:12 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-07-09 19:06 Truncating a fixed-point value Adam Beneschan
2010-07-09 20:34 ` Simon Wright
2010-07-09 23:21   ` Adam Beneschan
2010-07-10  3:13     ` Gene
2010-07-11 19:43       ` Gene
2010-07-10  8:12     ` Simon Wright [this message]
2010-07-09 20:39 ` Gene
2010-07-09 21:20   ` Jeffrey R. Carter
2010-07-09 21:52   ` Adam Beneschan
2010-07-13 11:26     ` Jacob Sparre Andersen
2010-07-09 22:58 ` Shark8
replies disabled

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