From: Tucker Taft <stt@avercom.net>
Subject: Re: Decimal number of interger?
Date: Mon, 29 Oct 2001 10:36:54 -0500
Date: 2001-10-29T15:36:51+00:00 [thread overview]
Message-ID: <3BDD7796.AF6ABCE4@avercom.net> (raw)
In-Reply-To: 3BD70DE5.C2D2B6FD@ida.his.se
a98mican@ida.his.se wrote:
>
> Hi!
> How do I determine weather the result from a function has a decimal part
> or not?
> I want to use the log function to se weather the width of the terrain is
> (2^x)+1. In order to do this I want to use the following:
> log2(width-1) = "float without decimal part"
>
> Thanks in advance!
> /Michael Andersson
The attribute function S'Remainder(x, y) can be used to get the
"fractional" part, as follows:
if Float'Remainder(X, 1.0) = 0.0 then
-- X has no fractional part
else
-- X has a fractional part
end if;
On the other hand, you are using two relatively expensive floating
point operations to determine something that might be done more cheaply
in some other way. E.g., getting the exponent (presuming the
Machine_Radix is 2, which it almost certainly is unless you are
on a mainframe) using Float'Exponent() and then using Float'Compose()
to build a new value that is 2^exponent. Alternatively, Float'Fraction
might be the perfect function, because Float'Fraction(width-1) will be
exactly 0.50 in the case of interest (again, presuming Machine_Radix
is 2).
--
-Tucker Taft stt@avercom.net http://www.avercom.net
Chief Technology Officer, AverCom Corporation (A Titan Company)
Bedford, MA USA (AverCom was formerly the Commercial Division of AverStar:
http://www.averstar.com/~stt)
prev parent reply other threads:[~2001-10-29 15:36 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-10-24 17:46 Decimal number of interger? a98mican
2001-10-24 19:54 ` tmoran
2001-10-24 23:35 ` Jeffrey Carter
2001-10-25 1:38 ` DuckE
2001-10-29 15:36 ` Tucker Taft [this message]
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox