comp.lang.ada
 help / color / mirror / Atom feed
From: "G.B." <rm-dash-bau-haus@dash.futureapps.de>
Subject: Re: How to round to the nearest fixed-point value?
Date: Wed, 22 Jan 2014 18:53:29 +0100
Date: 2014-01-22T18:53:11+01:00	[thread overview]
Message-ID: <52e00586$0$6658$9b4e6d93@newsspool2.arcor-online.net> (raw)
In-Reply-To: <slrnldvtim.1lme.lithiumcat@sigil.instinctive.eu>

On 22.01.14 17:48, Natasha Kerensikova wrote:
>     function Convert (Value : High) return Low is
>     begin
>        return Low'Round (Value);
>     end Convert;

In view of LRM 4.6, Numeric Type Conversion,
I speculate that the compiler might be right. If only I knew
how truncation might play a role(+):

      * If the target type is a decimal fixed point type, then
        the result is truncated (toward 0) if the value of the
        operand is not a multiple of the small of the target
        type.

Then, rewriting,

    function Convert (Value : High) return Low is
       Result : constant High := High'Round (Value);
    begin
       return Low (Result);
    end Convert;

Result has 0.999 exactly if this is a multiple of High'Small
(it is, with GNAT on Intel), but converting to Low truncates
because Low'Small is too big by a factor of 10.

__
(+) Low'Round takes a universal_real (and returns Low'Base); does
universality affect things?

  reply	other threads:[~2014-01-22 17:53 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-22 16:48 How to round to the nearest fixed-point value? Natasha Kerensikova
2014-01-22 17:53 ` G.B. [this message]
2014-01-22 22:26   ` adambeneschan
2014-01-23  9:21     ` Georg Bauhaus
2014-01-22 22:45 ` adambeneschan
2014-01-23  5:29   ` J-P. Rosen
2014-01-23  7:00     ` Natasha Kerensikova
2014-01-23  9:42     ` Georg Bauhaus
2014-01-23  7:02   ` Natasha Kerensikova
2014-01-23 16:41     ` adambeneschan
2014-01-24  9:58 ` Natasha Kerensikova
2014-01-24 22:30   ` Randy Brukardt
2014-01-24 22:47     ` Randy Brukardt
2014-01-26 14:19     ` Natasha Kerensikova
2014-01-28 23:43       ` Randy Brukardt
replies disabled

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