comp.lang.ada
 help / color / mirror / Atom feed
From: eyal@wisdom.BITNET (Eyal mozes)
Subject: Re: Numeric Conversion
Date: Thu, 12-Jun-86 04:57:27 EDT	[thread overview]
Date: Thu Jun 12 04:57:27 1986
Message-ID: <8606120856.AA07663@ucbvax.Berkeley.EDU> (raw)

> Now we have encountered a problem, trivial by  nature,  which  has  us
> baffled.   The problem is simply that of obtaining the integer part of
> a positive fixed-point value.  We can find no simple way of  achieving
> this  in Ada: use of numeric conversion leads to uncertainty regarding
> the direction of rounding (ARM 4.6 p7).

Well, one way is to substract 0.5 from the number before converting
it; this should always give you the correct result.

Another way is to use the following function (which I write when I
had to do the same thing a few months ago:

function integer_part(value: real) return integer is
   temp: integer := integer(value);
begin
   if real(temp) > value then
      return temp-1;
   else
      return temp;
   end if;
end;

        Eyal Mozes

        BITNET:                         eyal@wisdom
        CSNET and ARPA:                 eyal%wisdom.bitnet@wiscvm.ARPA
        UUCP:                           ..!ucbvax!eyal%wisdom.bitnet

             reply	other threads:[~1986-06-12  8:57 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1986-06-12  8:57 Eyal mozes [this message]
  -- strict thread matches above, loose matches on Subject: below --
1986-06-11 17:55 Numeric Conversion 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