Skip site navigation (1) Skip section navigation (2)

Re: bug in float8in()

From: Magnus Hagander <magnus(at)hagander(dot)net>
To: "Richard Wang" <ruc_wang(at)hotmail(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: bug in float8in()
Date: 2008-04-02 09:25:19
Message-ID: 20080402112519.702080e7@mha-laptop (view raw or flat)
Thread:
Lists: pgsql-hackers
Richard Wang wrote:
> I run the following sql statements in linux and get the results:
> postgres=# create table test_double(col1 float8);
> CREATE TABLE
> postgres=# insert into test_double values(1.7976931348623159E308);
> INSERT 0 1
> postgres=# select * from test_double;
>    col1
> ----------
>  Infinity
> (1 row)
> 
> but in windows:
> postgres=# create table test_double(col1 float8);
> CREATE TABLE
> postgres=# insert into test_double values(1.7976931348623159E308);
> ERROR: 
> "17976931348623159000000000000000000000000000000000000000000000000000000
> 00000000000000000000000000000000000000000000000000000000000000000000000000000000
> 00000000000000000000000000000000000000000000000000000000000000000000000000000000
> 000000000000000000000000000000000000000000000000000000000000000000000000000000"
> is out of range for type double precision
> postgres=# select * from test_double;
>  col1
> ------
> (0 rows)
> 
> This is a bug, the behavior in windows and linux is not the smae

float relies on platform behavior, AFAIK. You're better off using
numeric if you need to process these values without that.

Float is an approximate datatype. In this case, linux makes a fairly
wild approximation (that it's the same as infinity) whereas windows
says it just can't approximate it. You could argue for either one being
correct, but in the end you just need to use a different datatype if
you need consistent behavior.

> the strtod() function in linux dosen't set errno when dealing with 
> 1.7976931348623159E308 but in windows it does
> How should we improve it?

Not sure we should, really...

//Magnus

In response to

Responses

pgsql-hackers by date

Next:From: Magnus HaganderDate: 2008-04-02 09:32:30
Subject: Re: [GENERAL] SHA1 on postgres 8.3
Previous:From: Zdenek KotalaDate: 2008-04-02 08:58:59
Subject: Re: bug in float8in()

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group