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,FREEMAIL_FROM, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,181acb4d59c58e23 X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news2.google.com!news.glorb.com!feeder.erje.net!news.mixmin.net!aioe.org!not-for-mail From: anon@att.net Newsgroups: comp.lang.ada Subject: Re: evaluation of named numbers Date: Sun, 17 Oct 2010 22:32:53 +0000 (UTC) Organization: Aioe.org NNTP Server Message-ID: References: <2304722c-027d-42f6-a45d-5a7646c35cf6@t8g2000yqk.googlegroups.com> Reply-To: anon@anon.org NNTP-Posting-Host: BNOX81N54uOP/dmFKRRRLQ.user.speranza.aioe.org X-Complaints-To: abuse@aioe.org X-Notice: Filtered by postfilter v. 0.8.2 X-Newsreader: IBM NewsReader/2 2.0 Xref: g2news2.google.com comp.lang.ada:15568 Date: 2010-10-17T22:32:53+00:00 List-Id: In <2304722c-027d-42f6-a45d-5a7646c35cf6@t8g2000yqk.googlegroups.com>, Rolf writes: >I always thought that named numbers are fully evaluated with (almost) >unlimited precision at compile time. I was quite astonished to see > > Ticks : constant := 20 / 1000 * 16_000_000 / 8; -- 40_000 ticks > >evaluated to 0 and not to the expected 40.000. It seems that the >compiler uses integer numbers also for intermediate results and 20 / >1000 ends up to be 0 instead of 0.02. Any decent pocket calculator >gets that right. > >The workaround is simple once I understood the problem: > > Ticks : constant := 20 * 16_000_000 / 8 / 1000; -- 40_000 ticks > >Are expressions for named numbers always evaluated left to right? I >think I'll add an item to the review check list to always put >multiplications on the left before any divisions. > > Rolf Since, Rm 4.5(8) states the Ada's answer to this problem but it solution in using parentheses will not corrent the problem so rewrite the equation may be needed. Ticks : constant := 20 * 16_000_000 / 8 / 1000 ; -- 40_000 ticks