comp.lang.ada
 help / color / mirror / Atom feed
From: Jeffrey Carter <jrcarter@acm.org>
Subject: Re: Floats together with Integers
Date: Sat, 16 Mar 2002 01:30:57 GMT
Date: 2002-03-16T01:30:57+00:00	[thread overview]
Message-ID: <3C92A045.78ABDF75@acm.org> (raw)
In-Reply-To: 3c929b72$0$7414@motown.iinet.net.au

Max Power wrote:
> 
> Is there any possible way to have a float and an integer together in the same equation?
> 
> i.e.
> 
> Int1 := Integer
> Int2 := Float
> Sum := Float
> 
> Int1 * Int2 = Sum
> 
> If so, how can I make the equation work without errors, is there some
> sort of syntax/function used to enable a sum to be calculated when both
> a float and integer reside in the same equation?

A subprogram must have actual parameters that match the types of its
formal parameters. There is no predefined subprogram

function "*" (Left : Integer; Right : Float) return <anything>;

in Ada. However, you can define your own if you want.

Then, of course, you need to know how to implement it. Any numeric type
may be converted to any other numeric type, subject to meeting the
appropriate constraints; converting from a real type to an integer type
results in rounding. So perhaps you want to write

Float (Int1) * Int2 = Sum

This converts Int1 to Float before multiplying the result and Int2, then
compares the result of the multiplication to Sum using equality defined
for Float.

-- 
Jeff Carter
"You tiny-brained wipers of other people's bottoms!"
Monty Python & the Holy Grail



      reply	other threads:[~2002-03-16  1:30 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-03-16  1:10 Floats together with Integers Max Power
2002-03-16  1:30 ` Jeffrey Carter [this message]
replies disabled

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