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.43.167.135 with SMTP id ne7mr38626icc.8.1412638566239; Mon, 06 Oct 2014 16:36:06 -0700 (PDT) X-Received: by 10.140.30.36 with SMTP id c33mr297536qgc.2.1412638566205; Mon, 06 Oct 2014 16:36:06 -0700 (PDT) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!mx02.eternal-september.org!news.eternal-september.org!feeder.eternal-september.org!news.glorb.com!h18no2364349igc.0!news-out.google.com!q8ni45qal.1!nntp.google.com!dc16no1105545qab.1!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Mon, 6 Oct 2014 16:36:05 -0700 (PDT) In-Reply-To: <87iok1d09g.fsf@adaheads.sparre-andersen.dk> Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=50.111.113.147; posting-account=Ies7ywoAAACcdHZMiIRy0M84lcJvfxwg NNTP-Posting-Host: 50.111.113.147 References: <0e236d4b-2ece-4179-850c-46a0572f8339@googlegroups.com> <87iok1d09g.fsf@adaheads.sparre-andersen.dk> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <5e669b7a-21ac-46cf-b850-50692c38541d@googlegroups.com> Subject: Re: casting types From: brbarkstrom@gmail.com Injection-Date: Mon, 06 Oct 2014 23:36:06 +0000 Content-Type: text/plain; charset=ISO-8859-1 Xref: news.eternal-september.org comp.lang.ada:22160 Date: 2014-10-06T16:36:05-07:00 List-Id: On Friday, October 3, 2014 4:29:34 AM UTC-4, Jacob Sparre Andersen wrote: > Stribor40 wrote: > > > > > Now I would like to save this 81.00000 as an integer to some > > > variable. Can you please show me how to do this please > > > > You can't do that without having declared (or chosen) an appropriate > > integer type, and declared a variable of that type. > > > > Once that is done, you write: > > > > Variable := Type (81.00000); > > > > Greetings, > > > > Jacob > > -- > > "constructive ambiguity" First, to be safe in doing any floating point arithmetic, you should use the Ada type long_float. You can rename this to double or real if you want. Create a package that that creates a new Ada.Numerics (or some such - I need to check the definitions I usually use on my Windows XP machine that doesn't connect to the Web) Next, the equivalent to type casting is that you can then create a function like With Common_Defs; use Common_Defs; function Multiply(x : in float; y : in float) return real; function Multiply(x : in float; y : in float) return real is Result : real; begin Result := real(x*y); return (Result); end Multiply; You will reduce both truncation and round-off errors by doing all floating point computations with Ada long_float variables and operations. If you do, just replace the "float" types in the snippet with "real" and carry on. If you need an introduction, consult Acton, 1970: "Numerical Methods That Work", Haroer & Row. It's the only book I know on numerical methods that has a sense of humor - as well as a whole interlude on "What Not To Compute". Bruce B.