comp.lang.ada
 help / color / mirror / Atom feed
From: dewar@cs.nyu.edu (Robert Dewar)
Subject: Re: Truncation of FLOAT values
Date: 1996/04/19
Date: 1996-04-19T00:00:00+00:00	[thread overview]
Message-ID: <dewar.829887687@schonberg> (raw)
In-Reply-To: 4l6bjn$b96@cliffy.lfwc.lockheed.com

Mike said

"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."

First, you clearly meant to say subtract rather than round,

e.g. 2.3 - 0.5 = 1.8, conversion rounds to 2 = integer part of 2.3

but that's wrong, because

3.0 - 0.5 = 2.5, which is allowed in Ada 83 to round to 2 when you want 3.

There is no trivial solution  to this in Ada 83, which is why the
truncation attribues was added to Ada 95.





  parent reply	other threads:[~1996-04-19  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
1996-04-19  0:00   ` Peter Hermann
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   ` Robert Dewar [this message]
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