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,65b3f028266fd999 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!news2.google.com!npeer03.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!nx02.iad01.newshosting.com!newshosting.com!198.186.194.249.MISMATCH!transit3.readnews.com!textspool1.readnews.com!news-out.readnews.com!postnews3.readnews.com!not-for-mail Date: Sun, 15 Aug 2010 20:46:03 -0400 From: "Peter C. Chapin" User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.8) Gecko/20100802 Lightning/1.0b2 Thunderbird/3.1.2 MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Question about ordinary fixed point types. References: <4c685fac$0$2373$4d3efbfe@news.sover.net> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Message-ID: <4c688a68$0$2376$4d3efbfe@news.sover.net> Organization: SoVerNet (sover.net) NNTP-Posting-Host: fde1d800.news.sover.net X-Trace: DXC=4imJhInEG;H]dI?8hh>1UOK6_LM2JZB_CW?2c0[Uf7DO:WUUlR<856OCQKb6PN3DlJ`\hJ@PBeK:L X-Complaints-To: abuse@sover.net Xref: g2news1.google.com comp.lang.ada:13376 Date: 2010-08-15T20:46:03-04:00 List-Id: On 2010-08-15 17:55, Shark8 wrote: >> type Angle_Type is delta 0.0005 range -3.1416 .. 3.1416; > > The first thing I see here is that 0.0005 doesn't evenly divide > 2*3.1416; is that going to be a problem? In theory it is not a problem. My reading of the Ada Reference Manual tells me that the implementation chooses a value of Small (the actual difference between represented numbers) that is no more than the specified delta. Note that Small must be a power of 2, but can be controlled with a representation clause. In my case GNAT appears to be using 2**(-11) which is 0.0004883. Implementations can choose a smaller Small if they want. The values in the type then become all the multiples of Small "between" the endpoints of the specified range. However, those endpoints are converted to the nearest multiple of Small (unless they fall exactly between two multiples in which case the value closer to zero wins). You can probably tell I've been reading the manual. :) I'm not sure which multiple of 2**(-11) are involved here exactly but it appears that the mathematical value of -3.1416 is rounding down... meaning more negative. I'm not too worried about that right now. I just wondered how I could visit all the values of the type in a loop. Probably I should use extra digits in the definition of the range to communicate my intentions to the compiler more precisely. Thus type Angle_Type is delta 0.0005 range -3.1415926535 .. 3.1415926535; That way when the compiler decides how to round the end points of the range, it will definitely do the right thing. Peter