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: 103376,b2993a94987e380e X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!news4.google.com!out03a.usenetserver.com!news.usenetserver.com!in01.usenetserver.com!news.usenetserver.com!in03.usenetserver.com!news.usenetserver.com!pc02.usenetserver.com!news.flashnewsgroups.com-b7.4zTQh5tI3A!not-for-mail Newsgroups: comp.lang.ada Subject: Re: Epsilon References: From: Stephen Leake Date: Tue, 13 May 2008 07:42:35 -0400 Message-ID: User-Agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/22.1 (windows-nt) Cancel-Lock: sha1:oZSkCs6nAZ07BUXepN+BmgR1U0k= MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Complaints-To: abuse@flashnewsgroups.com Organization: FlashNewsgroups.com X-Trace: e54b748297a38e05e48ed10922 Xref: g2news1.google.com comp.lang.ada:54 Date: 2008-05-13T07:42:35-04:00 List-Id: writes: > I am looking for some short, practical examples of the Epsilon > attribute. If you do have some source code examples to post, > please also send them to my academic email: rdriehle@nps.edu -- These values guarantee Integer_16 (value) or Unsigned_16 -- (value) won't raise Constraint_Error, and allow for maximum -- round-off error. Useful with Clip_Scale_Limit when result will -- be converted to Integer_16 or Unsigned_16. Integer_16_First_Real : constant Real_Type := Real_Type (Interfaces.Integer_16'First) - 0.5 + (Real_Type'Epsilon * Real_Type (Interfaces.Integer_16'Last)); Integer_16_Last_Real : constant Real_Type := Real_Type (Interfaces.Integer_16'Last) + 0.5 - (Real_Type'Epsilon * Real_Type (Interfaces.Integer_16'Last)); Unsigned_16_First_Real : constant Real_Type := -0.5 + Real_Type'Epsilon; Unsigned_16_Last_Real : constant Real_Type := Real_Type (Interfaces.Unsigned_16'Last) + 0.5 - (Real_Type'Epsilon * Real_Type (Interfaces.Unsigned_16'Last)); function First_Order_Trig return Real_Type is begin return Elementary.Sqrt (Real_Type'Model_Epsilon); end First_Order_Trig; function Half_Trig (Trig : in Trig_Pair_Type) return Trig_Pair_Type is -- The result Trig.Cos is >= 0.0. -- -- A linear approximation is used when Trig.Sin < -- First_Order_Trig. this is exact since cos x = 1 - x**2 for -- this range of x. begin if abs Trig.Sin < First_Order_Trig then -- angle near 0 or Pi. if Trig.Cos > 0.0 then -- angle near 0 return (Trig.Sin / 2.0, 1.0); else -- angle near Pi if Trig.Sin >= 0.0 then return (1.0 - Trig.Sin / 2.0, 0.0); else return (-1.0 + Trig.Sin / 2.0, 0.0); end if; end if; else -- angle not near 0 or Pi if Trig.Sin >= 0.0 then return (Elementary.Sqrt ((1.0 - Trig.Cos) / 2.0), Elementary.Sqrt ((1.0 + Trig.Cos) / 2.0)); else return (-Elementary.Sqrt ((1.0 - Trig.Cos) / 2.0), Elementary.Sqrt ((1.0 + Trig.Cos) / 2.0)); end if; end if; end Half_Trig; -- -- Stephe