🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: net.lang.ada
Article #1029

An Ada quiz on type conversions

#1029
From: emery
Date: Mon, 27 Oct 1986 21:33
44 lines
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
Technical Details
Message-ID: <38000033@gypsy.UUCP>
Path: arc1-ca.pugleaf.net!utzoo!mnetor!seismo!rutgers!clyde!bellcore!ulysses!allegra!princeton!siemens!gypsy!emery

Show Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: arc1-ca.pugleaf.net!utzoo!mnetor!seismo!rutgers!clyde!bellcore!ulysses!allegra!princeton!siemens!gypsy!emery
From: emery@gypsy.UUCP
Newsgroups: net.lang.ada
Subject: An Ada quiz on type conversions
Message-ID: <38000033@gypsy.UUCP>
Date: Mon, 27-Oct-86 16:33:00 EST
Article-I.D.: gypsy.38000033
Posted: Mon Oct 27 16:33:00 1986
Date-Received: Tue, 28-Oct-86 19:10:54 EST
Lines: 44
Nf-ID: #N:gypsy:38000033:000:809
Nf-From: gypsy!emery    Oct 27 16:33:00 1986