Subject Re: [firebird-support] Is this a bug in ROUND function?
Author Richard Damon
On 8/19/19 4:46 AM, m.djorov@... [firebird-support] wrote:
>  
>
> The following query shows that ROUND function does not give similar
> results for similar values:
>
>
> select
>     round(cast(0.725 as double precision), 2),
>     round(cast(1.725 as double precision), 2),
>     round(cast(2.725 as double precision), 2),
>     round(cast(3.725 as double precision), 2),
>     round(cast(4.725 as double precision), 2),
>     round(cast(5.725 as double precision), 2),
>     round(cast(6.725 as double precision), 2),
>     round(cast(7.725 as double precision), 2),
>     round(cast(8.725 as double precision), 2),
>     round(cast(9.725 as double precision), 2),
>     round(cast(10.725 as double precision), 2)
> from
>     rdb$database
>
>
> All statements give result X.73, only 4.725 gives 4.72
>
>
> I know that floating point values have their speciality, but still the
> function should work the same way for all values.
>
> The query is run with IBExpert, but I don't think it's the problem in
> that case.
>
>
> What do you think Should I report it as a bug?
>
X.725 has no exact binary representation, so each of the number will
actually be something slightly different. If the 'closest' represented
value is greater than the specified number, it will round up to

X.73, if the 'closest' value is less, than you will get X.72. (And
standard precision rules don't actually require getting the absolutly
closest value, normally both the value just less or just greater are
considered 'good enough'.

Therefore, this really isn't a bug.

--
Richard Damon