comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Way to use Ada Mod function on floats?
Date: Sat, 2 Dec 2006 19:24:31 +0100
Date: 2006-12-02T19:24:15+01:00	[thread overview]
Message-ID: <v62si6vywqyx$.tjnq1980x45d.dlg@40tude.net> (raw)
In-Reply-To: n6qu43j28znm$.qol4paq183ks$.dlg@40tude.net

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 <gautier@fakeaddress.nil> 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



  reply	other threads:[~2006-12-02 18:24 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-12-01 15:32 Way to use Ada Mod function on floats? AAFellow
2006-12-01 16:37 ` Jeffrey Creem
2006-12-01 17:21 ` Adam Beneschan
2006-12-01 21:13 ` Chris Moore
2006-12-02 11:11 ` Stephen Leake
2006-12-02 16:40   ` Gautier
2006-12-02 17:48     ` Simon Wright
2006-12-02 18:21       ` Dmitry A. Kazakov
2006-12-02 18:24         ` Dmitry A. Kazakov [this message]
2006-12-03  0:50       ` Jeffrey R. Carter
2006-12-03  1:05     ` Randy Brukardt
2006-12-03 15:14     ` Stephen Leake
2006-12-03 22:27       ` Jeffrey R. Carter
2006-12-04 11:31         ` Stephen Leake
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox