comp.lang.ada
 help / color / mirror / Atom feed
From: milton!mfeldman@beaver.cs.washington.edu  (Michael Feldman)
Subject: Re: Red-faced professor gets bitten in search for portability
Date: 16 Nov 91 00:01:20 GMT	[thread overview]
Message-ID: <1991Nov16.000120.25606@milton.u.washington.edu> (raw)

In article <11919@spim.mips.COM> murphy@mips.com (Mike Murphy) writes:
>
>You are right about your first version not being portable, but
>your second version seems a bit convulated to me.  Why not just
>check whether you indeed rounded down after doing the integer conversion?
>For example:
>	FUNCTION Trunc (X: Float) RETURN Integer IS
>		itrunc : integer = integer(x - 0.5);
>	BEGIN
>		if x - float(itrunc) >= 1.0 then
>			-- rounded down, so add back a 1
>			return itrunc+1;
>		else
>			return itrunc;
>		end if;
>	END Trunc;
Sure - this seems equivalent. I kinda like the halving and doubling,
because these are pretty fast to implement (as shifts) given a
good optimizer. Your method has the advantage, I suppose, of being immune
to a possible overflow from the doubling.

>p.s. btw, some machines, e.g. MIPS, can either round down, or round up,
>or round to the even number (the default setting).
Right. My argument about Trunc is that it's such a common (and easy to
implement) operation that it's better done as an intrinsic, so that
the compiler writer can use whatever hardware trickery is available.

Mike

             reply	other threads:[~1991-11-16  0:01 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1991-11-16  0:01 Michael Feldman [this message]
  -- strict thread matches above, loose matches on Subject: below --
1991-11-25  6:09 Red-faced professor gets bitten in search for portability csus.edu!wupost!spool.mu.edu!munnari.oz.au!metro!cluster!swift!sunaus!ass
1991-11-22 22:16 Dik T. Winter
1991-11-22 22:11 Dik T. Winter
1991-11-22 21:10 Jonathan Parker
1991-11-22 15:24 The Sunset Kid
1991-11-22 14:06 psinntp!vitro.com!v7.vitro.com!vaxs09
1991-11-22  2:29 micro-heart-of-gold.mit.edu!wupost!zaphod.mps.ohio-state.edu!uakari.prima
1991-11-20 23:59 micro-heart-of-gold.mit.edu!wupost!sdd.hp.com!uakari.primate.wisc.edu!use
1991-11-20  2:55 csus.edu!wupost!cs.utexas.edu!sun-barr!cronkite.Central.Sun.COM!newstop!s
1991-11-19 15:06 Norman H. Cohen
1991-11-15 20:58 Mike Murphy
1991-11-15 18:59 Michael Feldman
replies disabled

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