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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no 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: g2news1.google.com!news1.google.com!news.glorb.com!news2.glorb.com!wn11feed!worldnet.att.net!bgtnsc04-news.ops.worldnet.att.net.POSTED!53ab2750!not-for-mail Newsgroups: comp.lang.ada From: anon@anon.org (anon) Subject: Re: Duration'Image, Duration'Value and Duration'Last Reply-To: no to spamers (No@email.given.org) References: <3d28adba-fdc7-43e1-b25e-e986276d7897@k36g2000pri.googlegroups.com> X-Newsreader: IBM NewsReader/2 2.0 Message-ID: Date: Thu, 19 Feb 2009 17:00:16 GMT NNTP-Posting-Host: 12.65.126.150 X-Complaints-To: abuse@worldnet.att.net X-Trace: bgtnsc04-news.ops.worldnet.att.net 1235062816 12.65.126.150 (Thu, 19 Feb 2009 17:00:16 GMT) NNTP-Posting-Date: Thu, 19 Feb 2009 17:00:16 GMT Organization: AT&T Worldnet Xref: g2news1.google.com comp.lang.ada:3704 Date: 2009-02-19T17:00:16+00:00 List-Id: Its actually a compiler bug. Even using a user created type that contains the Duration range, will cause the same type of error. type myDuration is delta 0.000000001 range -((2 ** 63 - 1) * 0.000000001) .. +((2 ** 63 - 1) * 0.000000001); for myDuration'Small use 0.000000001; But if you manual use the "System.Val_Real" package which is the work horse for Duration'Value attrubute it does work correctly. In <3d28adba-fdc7-43e1-b25e-e986276d7897@k36g2000pri.googlegroups.com>, Adam Beneschan writes: >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 > >