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,FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.66.102.97 with SMTP id fn1mr37276703pab.7.1430700451353; Sun, 03 May 2015 17:47:31 -0700 (PDT) X-Received: by 10.50.61.231 with SMTP id t7mr107887igr.14.1430700451305; Sun, 03 May 2015 17:47:31 -0700 (PDT) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!mx02.eternal-september.org!feeder.eternal-september.org!usenet.blueworldhosting.com!feeder01.blueworldhosting.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!m20no8182962iga.0!news-out.google.com!kd3ni7465igb.0!nntp.google.com!l13no13497132iga.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Sun, 3 May 2015 17:47:30 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=123.2.70.40; posting-account=S_MdrwoAAAD7T2pxG2e393dk6y0tc0Le NNTP-Posting-Host: 123.2.70.40 References: User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <7a09830f-dc68-4a29-92a0-064eb9f1f05f@googlegroups.com> Subject: Re: getting same output as gfortran, long_float From: robin.vowels@gmail.com Injection-Date: Mon, 04 May 2015 00:47:31 +0000 Content-Type: text/plain; charset=ISO-8859-1 Xref: news.eternal-september.org comp.lang.ada:25716 Date: 2015-05-03T17:47:30-07:00 List-Id: On Friday, May 1, 2015 at 11:40:17 AM UTC+10, Nasser M. Abbasi wrote: > On 4/30/2015 8:16 PM, Jeffrey R. Carter wrote: > > > You could always do > > > > with Ada.Text_IO; > > with PragmARC.Rational_Numbers; > > with PragmARC.Unbounded_Integers; > > > > procedure Foo_Rational is > > use PragmARC; > > > > use type Rational_Numbers.Rational; > > use type Unbounded_Integers.Unbounded_Integer; > > > > One_I : constant Unbounded_Integers.Unbounded_Integer := +1; > > Twelve : constant Rational_Numbers.Rational := Unbounded_Integers."+" (12) / > > One_I; > > P0001 : constant Rational_Numbers.Rational := One_I / (+10_000); -- 0.0001 > > P1 : constant Rational_Numbers.Rational := One_I / (+10); -- 0.1 > > > > One : Rational_Numbers.Rational renames Rational_Numbers.One; > > > > Result : constant Rational_Numbers.Rational := Twelve * P0001 / (One * (One - > > P1) ** 4); > > begin -- Foo_Rational > > Ada.Text_IO.Put_Line (Item => Rational_Numbers.Image (Result) ); > > end Foo_Rational; > > > > $ gnatmake -gnatano -gnatwa -O2 -fstack-check -I../RAC foo_rational.adb > > gcc-4.6 -c -gnatano -gnatwa -O2 -fstack-check -I../RAC foo_rational.adb > > gnatbind -I../RAC -x foo_rational.ali > > gnatlink foo_rational.ali -O2 -fstack-check > > jrcarter@jcarter-singo-laptop:~/Code$ ./foo_rational > > 0.0018289894833104709647919524462734339277549154092363968907178783 > >72199359853680841335162322816643804298125285779606767261088248742569 > >7302240512117055326931870141746684956561499771376314586191129401005 > >94421582075903063557384545038866026520347508001828989483310470964791 > >95244627343392775491540923639689071787837219935985368084133516232281 > >664380429812528577960676726108824874256973022405121170553269318701 > > > The referenced PragmARC pkgs are available in the beta version of the PragmAda > > Reusable Components available from > > > > https://pragmada.x10hosting.com/pragmarc.htm > > > > Thanks, this is very useful. I noticed small difference in output: > side-by-side: > > Ada: 0.00182898948331047096479195244627343392775491540.. > Mathematica*: 0.00182898948331047096479195244627343392775491540.. > gfortran: 0.00182898948331047112025871115292829927 > > at digit 18, gfortran result is different. That's because your constants are double precision, not quad precision, as I said before. > But your Ada rational > package gives same result as Mathematica. This tells me your > result is the accurate one ! > > Mathematica code: > 12*1/(10000)/(1*(1 - 1/10)^4) -- do it all in symbolic first > ---> 4/2187 > > N[%, 100] ; -- ask for 100 digits numerical > > humm....I do not know why these are different. I would have expected > gfortran to be accurate for at least 34 digits, not just 18. They cannot be any more accurate than double precision (about 16 digits) because your constants are double precision. > May be > I am doing something wrong in gfortran. Here is the gfortran again > for reference: > > ------------------- > PROGRAM foo > IMPLICIT NONE > REAL(KIND = 16) :: x !-- kind=16 tells it is double quad > x = 12.0D0 * 0.0001D0/(1.0D0 * (1.0D0 - 0.1D0)**4 ) > PRINT *, x > END PROGRAM > ------------------