Infinity vs Error for division by zero

From: Matt Pulver <mpulver(at)unitytechgroup(dot)com>
To: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Infinity vs Error for division by zero
Date: 2019-03-01 17:46:55
Message-ID: CAHiCE4X7NH9cBWRmAeHOK3cUKjTG6mZSnE0d9bN+ovXVOBF_6Q@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hello,

PostgreSQL FLOAT appears to support +/-Infinity and NaN per the IEEE 754
standard, with expressions such as CAST('NaN' AS FLOAT) and CAST('Infinity'
AS FLOAT) and even supports ordering columns of floats that contain NaN.

However the query "SELECT 1.0/0.0;" produces an exception:

ERROR: division by zero

Question: If Infinity and NaN are supported, then why throw an exception
here, instead of returning Infinity? Is it purely for historical reasons,
or if it could all be done again, would an exception still be preferred?

For purely integer arithmetic, I can see how an exception would make sense.
However for FLOAT, I would expect/prefer Infinity to be returned.

Best regards,
Matt

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Andrew Gierth 2019-03-01 17:59:42 Re: Infinity vs Error for division by zero
Previous Message Andres Freund 2019-03-01 17:46:28 Re: Minimal logical decoding on standbys