Divid by zero bug in float

Поиск
Список
Период
Сортировка
Искать

Divid by zero bug in float

От:
"Jim C. Nasby" <jnasby@pervasive.com>
Дата:
Shouldn't this produce Infinity instead of an error?
postgresql=# select 5::float/0::float;
ERROR:  division by zero
postgresql=# select 5::float/'Infinity'::float;?column? 
----------       0
(1 row)

postgresql=# 
-- 
Jim C. Nasby, Sr. Engineering Consultant      jnasby@pervasive.com
Pervasive Software      http://pervasive.com    work: 512-231-6117
vcard: http://jim.nasby.net/pervasive.vcf       cell: 512-569-9461

Re: Divid by zero bug in float

От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
"Jim C. Nasby"  writes:
> Shouldn't this produce Infinity instead of an error?
> postgresql=# select 5::float/0::float;
> ERROR:  division by zero

No, I don't think so.  SQL92 6.12  quoth:
        4) The dyadic arithmetic operators , , , and  (+, -, *, and /, respectively) specify           addition, subtraction, multiplication, and division, respec-           tively. If the value of a divisor is zero, then an exception           condition is raised: data exception-division by zero.

There is nothing in there about allowing IEEE infinities instead, and
I very strongly doubt that the average database user would expect such
behavior.
		regards, tom lane

Re: Divid by zero bug in float

От:
"Jim C. Nasby" <jnasby@pervasive.com>
Дата:
On Wed, Feb 22, 2006 at 12:40:11PM -0500, Tom Lane wrote:
> "Jim C. Nasby"  writes:
> > Shouldn't this produce Infinity instead of an error?
> > postgresql=# select 5::float/0::float;
> > ERROR:  division by zero
> 
> No, I don't think so.  SQL92 6.12  quoth:
> 
>          4) The dyadic arithmetic operators , ,              terisk>, and  (+, -, *, and /, respectively) specify
>             addition, subtraction, multiplication, and division, respec-
>             tively. If the value of a divisor is zero, then an exception
>             condition is raised: data exception-division by zero.
> 
> There is nothing in there about allowing IEEE infinities instead, and
> I very strongly doubt that the average database user would expect such
> behavior.

Guess the spec is pretty clear then. Do you think it's worth mentioning
this in the floating point section of the docs?
-- 
Jim C. Nasby, Sr. Engineering Consultant      jnasby@pervasive.com
Pervasive Software      http://pervasive.com    work: 512-231-6117
vcard: http://jim.nasby.net/pervasive.vcf       cell: 512-569-9461

FAQ