* Re: Numeric Conversion
@ 1986-06-12 8:57 Eyal mozes
0 siblings, 0 replies; 2+ messages in thread
From: Eyal mozes @ 1986-06-12 8:57 UTC (permalink / 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
^ permalink raw reply [flat|nested] 2+ messages in thread
* Numeric Conversion
@ 1986-06-11 17:55 Anton Gibbs
0 siblings, 0 replies; 2+ messages in thread
From: Anton Gibbs @ 1986-06-11 17:55 UTC (permalink / raw)
We are relatively new to using Ada and, whilst learning the language,
have used as a guideline the principle that there always seems to be
an Ada way of doing things. Whenever code we have written turns out
to be messy in Ada, subsequent analysis has revealed that a different,
better approach leads to a neater solution. Usually it is the data
modelling that is wrong.
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).
No doubt we are going wrong again somewhere, but we cannot see where.
Maybe just wanting to examine the integer part of a fixed-point value
is against the principles of Ada real numbers.
Any ideas ?
Thanks in advance.
--
Regards,
Anton Gibbs <..seismo!mcvax!ukc!stc!idec!anton>
+44 438 726161 x8283
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~1986-06-12 8:57 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1986-06-12 8:57 Numeric Conversion Eyal mozes
-- strict thread matches above, loose matches on Subject: below --
1986-06-11 17:55 Anton Gibbs
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox