Question regarding handling of infinity values in ROUND

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Question regarding handling of infinity values in ROUND

Manuel Rigger
Hi everyone,

I was surprised by how the ROUND function handles "Inf" REAL values.

A REAL infinity value can be created by using an overly-large number:

SELECT 1e5000; -- Inf

When casting infinity to an integer value, the largest integer is returned,
which seems intuitive to me:

SELECT CAST(1e5000 AS INT); -- 9223372036854775807 (2^63 - 1)

However, the ROUND function always converts Inf to zero, which is somehow
surprising, since a >= b does not imply ROUND(a) >= ROUND(b) (which
contrasts the behavior of a cast):

SELECT 1e500 >= 1,  CAST(1e500 AS INT) >= CAST(1 AS INT), ROUND(1e500) >=
ROUND(1); -- 1|1|0

Is this deliberate? Would it make sense to let ROUND(Inf) = Inf (and
ROUND(-Inf) = -Inf))?

Best,
Manuel
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|

Re: Question regarding handling of infinity values in ROUND

Manuel Rigger
I noticed that this has been fixed now (
https://www.sqlite.org/src/info/db9acef14d492121). Thanks!

Best,
Manuel

On Fri, May 10, 2019 at 12:09 PM Manuel Rigger <[hidden email]>
wrote:

> Hi everyone,
>
> I was surprised by how the ROUND function handles "Inf" REAL values.
>
> A REAL infinity value can be created by using an overly-large number:
>
> SELECT 1e5000; -- Inf
>
> When casting infinity to an integer value, the largest integer is
> returned, which seems intuitive to me:
>
> SELECT CAST(1e5000 AS INT); -- 9223372036854775807 (2^63 - 1)
>
> However, the ROUND function always converts Inf to zero, which is somehow
> surprising, since a >= b does not imply ROUND(a) >= ROUND(b) (which
> contrasts the behavior of a cast):
>
> SELECT 1e500 >= 1,  CAST(1e500 AS INT) >= CAST(1 AS INT), ROUND(1e500) >=
> ROUND(1); -- 1|1|0
>
> Is this deliberate? Would it make sense to let ROUND(Inf) = Inf (and
> ROUND(-Inf) = -Inf))?
>
> Best,
> Manuel
>
>
>
>
>
>
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users