comp.lang.ada
 help / color / mirror / Atom feed
* Floats together with Integers
@ 2002-03-16  1:10 Max Power
  2002-03-16  1:30 ` Jeffrey Carter
  0 siblings, 1 reply; 2+ messages in thread
From: Max Power @ 2002-03-16  1:10 UTC (permalink / raw)



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?



^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Floats together with Integers
  2002-03-16  1:10 Floats together with Integers Max Power
@ 2002-03-16  1:30 ` Jeffrey Carter
  0 siblings, 0 replies; 2+ messages in thread
From: Jeffrey Carter @ 2002-03-16  1:30 UTC (permalink / raw)


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



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2002-03-16  1:30 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-03-16  1:10 Floats together with Integers Max Power
2002-03-16  1:30 ` Jeffrey Carter

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