comp.lang.ada
 help / color / mirror / Atom feed
From: l117593@cliffy.lfwc.lockheed.com (Cordes MJ)
Subject: Re: Truncation of FLOAT values
Date: 1996/04/18
Date: 1996-04-18T00:00:00+00:00	[thread overview]
Message-ID: <4l6bjn$b96@cliffy.lfwc.lockheed.com> (raw)
In-Reply-To: 4l5nmq$fhv@inrou.erno.de

Franz Kruse (Franz.Kruse@erno.de) wrote:

: Is there a simple way in Ada 83 to determine the integer part or the fraction part
: of a FLOAT value?

: A conversion to INTEGER cannot be used, because it rounds.

: Franz Kruse

If your compiler rounds, then you can simply add 0.5 to the FLOAT value
prior to converting it an INTEGER. You get the fractional part by 
converting the result back to FLOAT and subtracting it from the 
original FLOAT value.

Seems pretty simple to me (although it doesn't use any fancy Ada
features)  ;)

P.S., take care to check how your compiler rounds for numbers less
than zero and how it rounds (with the addition of 0.5) at the upper
and lower limits of the valid range.

Mike Cordes
###





  reply	other threads:[~1996-04-18  0:00 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-04-18  0:00 Truncation of FLOAT values Franz Kruse
1996-04-18  0:00 ` Cordes MJ [this message]
1996-04-19  0:00   ` John Herro
1996-04-19  0:00     ` Robert Dewar
1996-04-22  0:00       ` John Herro
1996-04-22  0:00     ` Robert I. Eachus
1996-04-19  0:00   ` Peter Hermann
1996-04-19  0:00   ` Robert Dewar
1996-04-20  0:00     ` Cordes MJ
1996-04-21  0:00       ` Robert Dewar
replies disabled

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