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,9ea5d59767aa4a7d X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news1.google.com!npeer01.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!nntp.club.cc.cmu.edu!feeder.erje.net!nuzba.szn.dk!news.jacob-sparre.dk!pnx.dk!not-for-mail From: Jacob Sparre Andersen Newsgroups: comp.lang.ada Subject: Re: Truncating a fixed-point value Date: Tue, 13 Jul 2010 13:26:49 +0200 Organization: Jacob Sparre Andersen Message-ID: <87hbk3pqpy.fsf@hugsarin.sparre-andersen.dk> References: <732bea9d-aacb-4b87-b64b-657aabce6736@w31g2000yqb.googlegroups.com> <5a96a81e-12a6-4f30-84c3-4b76e079b198@l25g2000prn.googlegroups.com> NNTP-Posting-Host: 95.209.238.202.bredband.3.dk Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: munin.nbi.dk 1279020410 19215 95.209.238.202 (13 Jul 2010 11:26:50 GMT) X-Complaints-To: news@jacob-sparre.dk NNTP-Posting-Date: Tue, 13 Jul 2010 11:26:50 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:GDTv8RW4PX1zKVacydoKM12mmBo= Xref: g2news1.google.com comp.lang.ada:12372 Date: 2010-07-13T13:26:49+02:00 List-Id: Adam Beneschan wrote: > That will probably work for my purpose; but in general, it's easy to > define a fixed-point number with a 'Small of 2**(-N) that has more > bits to the right of the binary point than are available in the > mantissa part of the floating-point. If that's the case, this > approach will fail on certain values (probably M - (K * T'Small) for > integer M and suitably small integer K). Since this situation lends > itself to really efficient code (basically just a bit shift), it's > kind of a shame that the language doesn't give you a good way to do > this. Isn't it possible to write a truncation function, which uses bit shift when it is appropriate? If the 'Small is statically known, there is a fair chance that the compiler will remove the unused branch at compile-time. Jacob -- "If we weren't at least occasionally surprised by the results, we might as well save ourselves the trouble of measuring :)"