comp.lang.ada
 help / color / mirror / Atom feed
* Getting the integer part of a real
@ 1986-11-05 14:25 emery
  1986-11-07 13:47 ` Robert Firth
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: emery @ 1986-11-05 14:25 UTC (permalink / 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

^ permalink raw reply	[flat|nested] 6+ messages in thread
* Re: Getting the integer part of a real
@ 1986-11-12 13:34 Hazel
  0 siblings, 0 replies; 6+ messages in thread
From: Hazel @ 1986-11-12 13:34 UTC (permalink / raw)


Oops, you got me!  OK, first check if the number is positive or negative, and
do the 'correct' thing.  Obviously, I hadn't thought it all through when
I posted that.  The context of our discussion (at Siemens) on that was 
1.  realizing what the language said, and
2.  coming up with a strategy to get the integer part that didn't depend on
    underlying implementation.  
"The details are left to the reader"  (Meaning, I'm too lazy to work them 
out.  

Thanks, Ken.

				Dave Emery

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~1986-11-12 13:34 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1986-11-05 14:25 Getting the integer part of a real emery
1986-11-07 13:47 ` 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

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