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: 103376,fc647120984c9ad2 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news3.google.com!newsfeed2.dallas1.level3.net!news.level3.com!newsfeed-00.mathworks.com!kanaga.switch.ch!switch.ch!news-fra1.dfn.de!newsfeed.hanau.net!noris.net!newsfeed.arcor.de!newsspool3.arcor-online.net!news.arcor.de.POSTED!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: Way to use Ada Mod function on floats? Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.15.1 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Reply-To: mailbox@dmitry-kazakov.de Organization: cbb software GmbH References: <1164987168.477589.240140@j44g2000cwa.googlegroups.com> <4571ac78_6@news.bluewin.ch> Date: Sat, 2 Dec 2006 19:24:31 +0100 Message-ID: NNTP-Posting-Date: 02 Dec 2006 19:24:15 CET NNTP-Posting-Host: c88eaf7d.newsspool3.arcor-online.net X-Trace: DXC=ifW=e@KZiog_0Po7BmQ3]lMcF=Q^Z^V3h4Fo<]lROoRagUcjd<3m<;bDS4;jG_BEXj[6LHn;2LCVn[ On Sat, 2 Dec 2006 19:21:43 +0100, Dmitry A. Kazakov wrote: > On Sat, 02 Dec 2006 17:48:34 +0000, Simon Wright wrote: > >> Gautier writes: >> >>> Stephen Leake: >>> >>>> SAL (http://stephe-leake.org/ada/sal.html) has: >>>> >>>> function Modulo (Dividend, Divisor : in Real_Type) return Real_Type >>>> is >>>> -- match names in Ada LRM 4.5.5 >>>> >>>> A : Real_Type renames Dividend; >>>> B : Real_Type renames Divisor; >>>> N : constant Integer := Integer (Real_Type'Floor (A / B)); >>>> begin >>>> return A - B * Real_Type (N); >>>> end Modulo; >>> >>> Out of curiosity, what is the need of converting Real_Type'Floor (A / >>> B) to an Integer and back to a Real_Type ? >> >> Especially when it can overflow and give you a Constraint_Error. > > Hmm, why is it converted to integer? I would stay all the way in > Real_Type'Base: > > return Real_Type'Base > (Dividend - Divisor * Real_Type'Base'Floor (Dividend / Divisor)); Of course, a qualified expression meant, so Real_Type'Base' in the first line. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de