comp.lang.ada
 help / color / mirror / Atom feed
From: Adam Beneschan <adam@irvine.com>
Subject: Re: Duration'Image, Duration'Value and Duration'Last
Date: Thu, 19 Feb 2009 07:44:01 -0800 (PST)
Date: 2009-02-19T07:44:01-08:00	[thread overview]
Message-ID: <3d28adba-fdc7-43e1-b25e-e986276d7897@k36g2000pri.googlegroups.com> (raw)
In-Reply-To: f264e89b-9890-4b88-9d4a-1c16d824cded@f24g2000vbf.googlegroups.com

On Feb 19, 7:33 am, dhenry <tfc.d...@gmail.com> wrote:
> Hello,
>
> I'm experimenting something strange when manipulating Duration'Image,
> Duration'Value and Duration'Last with GNAT :
>
> The result of Duration'Value(Duration'Image(Duration'Last)) is
> different from the result of S : String := Duration'Image
> (Duration'Last) and then Duration'Value(S).
>
> Here is a test program that shows the issue:
>
> -----------------------------------------------------
> with Ada.Text_IO; use Ada.Text_IO;
>
> procedure Test is
>    S : String   := Duration'Image (Duration'Last);
>    D : Duration := Duration'Value (S);
> begin
>    Put_Line (Duration'Image (D));
>    Put_Line (Duration'Image (Duration'Last));
> end Test;
> -----------------------------------------------------
>
> This test program gives me:
> -9223372036.854775810
>  9223372036.854775810
>
> Note that -9223372036.854775810 seems to be Duration'First...
>
> Is it expected? Can someone tell me what happens here? why this
> difference?

This is pretty obviously a GNAT bug.  From experimentation, it appears
that the problem is in the Duration'Value; Duration'Value
("9223372036.854775810") yields a negative value.  Fixed-point types
are usually represented as integers with an implied binary point
somewhere in there.  The integer whose leftmost bit is 1 and all other
bits 0 is always tricky to deal with, because you can't negate it, so
special care must be taken.  If Duration'First is represented as
exactly this integer, it's understandable why this sort of error may
have come up.

                                 -- Adam





  reply	other threads:[~2009-02-19 15:44 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-02-19 15:33 Duration'Image, Duration'Value and Duration'Last dhenry
2009-02-19 15:44 ` Adam Beneschan [this message]
2009-02-19 17:00   ` anon
replies disabled

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