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, 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!feeder.news-service.com!94.75.214.39.MISMATCH!aioe.org!not-for-mail From: "Nasser M. Abbasi" Newsgroups: comp.lang.ada Subject: Re: evaluation of named numbers Date: Sun, 17 Oct 2010 11:57:17 -0700 Organization: Aioe.org NNTP Server Message-ID: References: <2304722c-027d-42f6-a45d-5a7646c35cf6@t8g2000yqk.googlegroups.com> Reply-To: nma@12000.org NNTP-Posting-Host: tUYQ4Ty9mMw9Pdc8TJRFQA.user.speranza.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org X-Notice: Filtered by postfilter v. 0.8.2 User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.9) Gecko/20100915 Thunderbird/3.1.4 Xref: g2news2.google.com comp.lang.ada:15565 Date: 2010-10-17T11:57:17-07:00 List-Id: On 10/17/2010 8:01 AM, Rolf wrote: > 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. > Lets see: ------------------------- matlab: 20/1000 ans = 0.0200 int8(20)/int8(1000) ans = 0 ------------------- Pyhton IDLE 2.6.5 >>> 20/1000 0 >>> 20.0/1000 0.02 >>> ------------------ Fortran: PROGRAM Main implicit none PRINT *, 2/1000 PRINT *, 2.0/1000.0 END PROGRAM Main $ gfortran t1.f90 $ ./a.exe 0 2.00000009E-03 -------------------------------- So, if Ada is wrong, then so all these other systems, right? --Nasser