From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,94fc86d98e502e9d X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!postnews.google.com!k36g2000pri.googlegroups.com!not-for-mail From: Adam Beneschan Newsgroups: comp.lang.ada Subject: Re: Duration'Image, Duration'Value and Duration'Last Date: Thu, 19 Feb 2009 07:44:01 -0800 (PST) Organization: http://groups.google.com Message-ID: <3d28adba-fdc7-43e1-b25e-e986276d7897@k36g2000pri.googlegroups.com> References: NNTP-Posting-Host: 66.126.103.122 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Trace: posting.google.com 1235058242 25776 127.0.0.1 (19 Feb 2009 15:44:02 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Thu, 19 Feb 2009 15:44:02 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: k36g2000pri.googlegroups.com; posting-host=66.126.103.122; posting-account=duW0ogkAAABjRdnxgLGXDfna0Gc6XqmQ User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.7.12) Gecko/20050922 Fedora/1.7.12-1.3.1,gzip(gfe),gzip(gfe) Xref: g2news2.google.com comp.lang.ada:4673 Date: 2009-02-19T07:44:01-08:00 List-Id: On Feb 19, 7:33 am, dhenry 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