comp.lang.ada
 help / color / mirror / Atom feed
From: emery@gypsy.UUCP
Subject: An Ada quiz on type conversions
Date: Mon, 27-Oct-86 16:33:00 EST	[thread overview]
Date: Mon Oct 27 16:33:00 1986
Message-ID: <38000033@gypsy.UUCP> (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

             reply	other threads:[~1986-10-27 21:33 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1986-10-27 21:33 emery [this message]
1986-11-03 13:59 ` An Ada quiz on type conversions Anton Gibbs
replies disabled

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