Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

An Ada quiz on type conversions

1 view
Skip to first unread message

em...@gypsy.uucp

unread,
Oct 27, 1986, 4:33:00 PM10/27/86
to

quiz time, Ada fans:

consider

declare
x : integer;
y : my_float := 1.5;
begin
x := integer(y);
end;

What is the value of x?

(a) 1
(b) 2
(c) constraint_error is raised
(d) it depends

The right answer is (d), it depends.

"4.6 (a)

... The conversion of a real value to an integer type rounds
to the nearest integer; if the operand is halfway between two
integers (within the accuracy of the real subtype), rounding may
be either up or down.

"

So the implementor can pick how he wants to round. This strikes me as
a portability bug, but, on the other hand, I don't have a lot of sympathy
for people who depend on these kinds of type conversion....


Dave Emery
Siemens Research
...princeton!siemens!emery
princeton!siemens!em...@seismo.css.gov

Anton Gibbs

unread,
Nov 3, 1986, 8:59:46 AM11/3/86
to

In article 899, on the uncertainty of integer type conversion,
Dave Emery, concludes:

" So the implementor can pick how he wants to round. This strikes me as
a portability bug, but, on the other hand, I don't have a lot of sympathy
for people who depend on these kinds of type conversion...."

Obtaining the integer part of a real number strikes me as a reasonable thing
to want to do in a software engineering application. How are you meant to do
this in Ada ?
--
Regards,

Anton Gibbs <..seismo!mcvax!ukc!stc!idec!anton>
+44 438 726161 x8283

0 new messages