Thread View: net.lang.ada
2 messages
2 total messages
Started by emery
Mon, 27 Oct 1986 21:33
An Ada quiz on type conversions
Author: emery
Date: Mon, 27 Oct 1986 21:33
Date: Mon, 27 Oct 1986 21:33
44 lines
1368 bytes
1368 bytes
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
Re: An Ada quiz on type conversions
Author: Anton Gibbs
Date: Mon, 03 Nov 1986 13:59
Date: Mon, 03 Nov 1986 13:59
16 lines
1104 bytes
1104 bytes
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
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads