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,1038abdfae2ba73 X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news1.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!t-online.de!news.k-dsl.de!news.swapon.de!news.eternal-september.org!news.motzarella.org!motzarella.org!not-for-mail From: Keith Thompson Newsgroups: comp.lang.ada Subject: Re: Modify value - type duration Date: Thu, 06 Nov 2008 13:14:25 -0800 Organization: None to speak of Message-ID: References: <7ef68540-6df1-4e47-b425-ab08c03f2db9@p31g2000prf.googlegroups.com> <6f0d9434-9489-4946-b29f-60957c83858c@w1g2000prk.googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: news.eternal-september.org U2FsdGVkX1+6yAEULxOou/zO4RC+nkVfU39lmyY023aM3PewmDYbxS8rdwIroawbIqCo8+1PH8lcjpSiPx4lykiSd4ivCrunL563b97QEbS9z33mhYlpi1NOXfss3+42edepJ+205J0= X-Complaints-To: Please send complaints to abuse@motzarella.org with full headers NNTP-Posting-Date: Thu, 6 Nov 2008 21:14:28 +0000 (UTC) X-Auth-Sender: U2FsdGVkX1/AcXTA2lYnwjRY0KxMxDcp Cancel-Lock: sha1:d3zNbutDOs9p/GTLdUx0o3O+8JM= sha1:ZWovHldRKgVKUz9STgfcBfBzhg8= User-Agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/21.3 (gnu/linux) Xref: g2news2.google.com comp.lang.ada:8338 Date: 2008-11-06T13:14:25-08:00 List-Id: "Jeffrey R. Carter" 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 Nokia "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister"