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,UTF8 Path: g2news1.google.com!news2.google.com!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!feedme.ziplink.net!news.swapon.de!eternal-september.org!.POSTED!not-for-mail From: Simon Wright Newsgroups: comp.lang.ada Subject: Re: Truncating a fixed-point value Date: Sat, 10 Jul 2010 09:12:55 +0100 Organization: A noiseless patient Spider Message-ID: References: <732bea9d-aacb-4b87-b64b-657aabce6736@w31g2000yqb.googlegroups.com> <6d238b76-10ba-4ac8-ac16-86bc691fc96f@v6g2000prd.googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Date: Sat, 10 Jul 2010 08:12:57 +0000 (UTC) Injection-Info: mx01.eternal-september.org; posting-host="KCXegvZb5vh43D+f3BR6Ew"; logging-data="4108"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19xSiFQTWf5WSRL0NEkaGIY4bY9LETJ+hI=" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (darwin) Cancel-Lock: sha1:zAlfvPqqiID5xsNLvm+htV+VCxo= sha1:GXPMWSCXLkxh8Ejw2FNs7EUHy14= Xref: g2news1.google.com comp.lang.ada:12306 X-Original-Bytes: 2393 Date: 2010-07-10T09:12:55+01:00 List-Id: Adam Beneschan writes: > On Jul 9, 1:34 pm, Simon Wright wrote: >> Adam Beneschan writes: >> > I must be suffering from an embarrassing mental block, because I'm >> > sure there's a simple solution, but I can't see what it is. >> >> > I have a value X of a fixed-point type, X >= 0.0, and I need to >> > compute Floor(X) as an Integer.  'Truncation and 'Floor aren't defined >> > for fixed-point types; the type conversion Integer(X) rounds; and >> > Integer(X-0.5) fails if X=0.0. >> >> > How do others do this?  Or do I have to resort to an IF statement (or >> > conditional expression in Ada 2012) to handle the different cases? >> >> Looks as though Integer(X+0.5)-1 might do the trick .. > > Yes, it looks like it, as long as X >= 0.0 and 0.5 is a model number > of the fixed-point type (I think I'm using the right term). Those > conditions do hold for the code I need it for. It isn't useful for > negative numbers---it yields -2 if X=-1.0, which is not useful whether > you want a truncation or a floor operation---but I did stipulate > nonnegative X in my original question. I hadn't considered the model number aspect, but nonnegative X is indeed necessary for this solution!