* An Ada quiz on type conversions
@ 1986-10-27 21:33 emery
1986-11-03 13:59 ` Anton Gibbs
0 siblings, 1 reply; 2+ messages in thread
From: emery @ 1986-10-27 21:33 UTC (permalink / raw)
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!emery@seismo.css.gov
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: An Ada quiz on type conversions
1986-10-27 21:33 An Ada quiz on type conversions emery
@ 1986-11-03 13:59 ` Anton Gibbs
0 siblings, 0 replies; 2+ messages in thread
From: Anton Gibbs @ 1986-11-03 13:59 UTC (permalink / raw)
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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~1986-11-03 13:59 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1986-10-27 21:33 An Ada quiz on type conversions emery
1986-11-03 13:59 ` Anton Gibbs
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox