comp.lang.ada
 help / color / mirror / Atom feed
From: emery@gypsy.UUCP
Subject: Getting the integer part of a real
Date: Wed, 5-Nov-86 09:25:00 EST	[thread overview]
Date: Wed Nov  5 09:25:00 1986
Message-ID: <38000034@gypsy.UUCP> (raw)




When we discovered the 'feature' in Ada that an implementor can pick how
he rounds, we discussed various ways to get the integer part of a number.
Here is the 'best' (meaning most portable) way:  (p.s. this 'algorithm' 
is obviously language-independent)

	declare
	    x : real;
	    i : integer;	-- integer part of x
	begin
	    i := integer(x);
	    if (i > x) then
		   -- machine rounded up
                i := i - 1;
	    end if;
	end;

				Dave Emery
until 7 Nov:	   ...princeton!siemens!emery
		      princeton!siemens!emery@seismo.css.gov
after 10 Nov:             	linus!emery
		      		emery@mitre-bedford.arpa

             reply	other threads:[~1986-11-05 14:25 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1986-11-05 14:25 emery [this message]
1986-11-07 13:47 ` Getting the integer part of a real Robert Firth
1986-11-07 14:27 ` Arny B. Engelson
1986-11-10 22:12   ` David desJardins
1986-11-07 15:31 ` emery
  -- strict thread matches above, loose matches on Subject: below --
1986-11-12 13:34 Hazel
replies disabled

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