comp.lang.ada
 help / color / mirror / Atom feed
From: Chris Moore <zmower@ntlworld.com>
Subject: Re: Way to use Ada Mod function on floats?
Date: Fri, 01 Dec 2006 21:13:19 GMT
Date: 2006-12-01T21:13:19+00:00	[thread overview]
Message-ID: <PV0ch.1563$r95.1194@newsfe6-win.ntli.net> (raw)
In-Reply-To: <1164987168.477589.240140@j44g2000cwa.googlegroups.com>

AAFellow@hotmail.com wrote:
> Hi guys,
> 
> I need to perform the mod operation on floats.  Does anyone know of a
> simple way to do this in Ada? It seems the mod function is only for
> integers.  I can probably multiply out the decimal places, and then
> divide my answer back, but if there is a more simple way that saves
> computations, I'd rather do that.
> 
> Thank you for any help you can provide!
> 
> AA

Something like this (I don't have a compiler near me atm) :

function Mod (N, M : Float) return Float is
   I : Integer := Integer (N / M - 0.5);
begin
   if I < 0 then I := I + 1; end if;
   return N - Float (I) * M;
end Mod;

Chris

-- 
Sig pending!



  parent reply	other threads:[~2006-12-01 21:13 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 [this message]
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
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