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: a07f3367d7,86d4e48d5a9b02a1 X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news4.google.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Niklas Holsti Newsgroups: comp.lang.ada Subject: Re: Cannot summate small float values Date: Sat, 20 Nov 2010 15:49:16 +0200 Organization: Tidorum Ltd Message-ID: <8kq1usFojgU1@mid.individual.net> References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net A0cdZN8JwKTIUNEG4T8iogikMXOqtucKa4GquUpTkGni/xOH0b Cancel-Lock: sha1:HL6xIcHSjSbjekvWhM146yfKRVk= User-Agent: Mozilla-Thunderbird 2.0.0.24 (X11/20100328) In-Reply-To: Xref: g2news2.google.com comp.lang.ada:16598 Date: 2010-11-20T15:49:16+02:00 List-Id: tolkamp wrote: > When I summate Float values smaller then 1.0E-6 then the summation is > not done. > > Code Example: > > X, Dx : Float; > X := 0.0; > Dx := 1.0E-7; > lwhile X < 1.0 loop > X = X + Dx; > Float_Io.Put(X, 3,9,0); New_Line; > end loop; Certainly the addition is done. Your program (after some small syntactic corrections) prints: 0.000000100 0.000000200 0.000000300 0.000000400 0.000000500 0.000000600 0.000000700 and so on. If your program prints out something else, please show the source code of your whole program, exactly as you compile and run it. Don't re-type it into your message. However, when X approaches 1.0, at some point the addition of 1.0E-7 may be lost in round-off, since it is close to the precision limit of the Float type, relative to 1.0. On my system (Debian, Gnat) the X variable does reach 1.0 and the program stops. What are you really trying to do? There are probably safer and more accurate ways of doing it. Here is the program that I used: with Ada.Text_IO; with Ada.Float_Text_IO; procedure Sums is use Ada.Text_IO, Ada.Float_Text_IO; X, Dx : Float; begin X := 0.0; Dx := 1.0E-7; while X < 1.0 loop X := X + Dx; Put(X, 3,9,0); New_Line; end loop; end Sums; -- Niklas Holsti Tidorum Ltd niklas holsti tidorum fi . @ .