comp.lang.ada
 help / color / mirror / Atom feed
From: Keith Thompson <kst-u@mib.org>
Subject: Re: Modify value - type duration
Date: Thu, 06 Nov 2008 13:14:25 -0800
Date: 2008-11-06T13:14:25-08:00	[thread overview]
Message-ID: <ln3ai4r1zi.fsf@nuthaus.mib.org> (raw)
In-Reply-To: nasQk.422242$yE1.14213@attbi_s21

"Jeffrey R. Carter" <spam.jrcarter.not@spam.acm.org> writes:
> Adam Beneschan wrote:
>> Hmmm ... now I wonder why there isn't a Truncation attribute for
>> fixed-
>> point types?  Maybe nobody before Andreas ever thought they'd need
>> one.  Might be useful.  (Also Floor, Ceiling.)
>
> No, I wondered about that long ago.
>
>> A possible problem with the floating-point conversion solution is that
>> there may be cases where you lose accuracy---if, e.g., the largest
>> floating-point type and fixed-point systems supported on the machine
>> are both 64 bits.  Since a floating-point number needs room for an
>> exponent, it's possible to define a fixed-point type with more bits in
>> the integer part than can be represented in the mantissa of a floating-
>> point type, e.g.
>
> One must always be careful in such cases that the conversion will not
> fail or lose important bits.

Well, you *could* do an Unchecked_Conversion to an appropriate integer
type, use integer arithmetic to truncate, and then convert back to
Duration.  It's ugly, but it should work on most systems, and it
avoids any accuracy problems.

Doing this in a way that will work under one specific compiler is
fairly straightforward.  Doing it reasonably portably is harder.

-- 
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
Nokia
"We must do something.  This is something.  Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"



  reply	other threads:[~2008-11-06 21:14 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-11-05 21:50 Modify value - type duration Andreas.Schmidl
2008-11-05 22:47 ` Jeffrey R. Carter
2008-11-06  1:03   ` Adam Beneschan
2008-11-06  1:57     ` Jeffrey R. Carter
2008-11-06 21:14       ` Keith Thompson [this message]
2008-11-07  1:33       ` Randy Brukardt
2008-11-07 11:10         ` Ludovic Brenta
replies disabled

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