bug in float8in()

Started by Richard Wangalmost 18 years ago4 messages
#1Richard Wang
ruc_wang@hotmail.com

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

I check the code and find that float8in exists a bug:
the strtod() function in linux dosen't set errno when dealing with
1.7976931348623159E308 but in windows it does
How should we improve it?

#2Zdenek Kotala
Zdenek.Kotala@Sun.COM
In reply to: Richard Wang (#1)
Re: bug in float8in()

If you look into documentation, the behavior of float/double is platform depend.
If you want to same result on any platform, use numeric instead.

Zdenek

Richard Wang napsal(a):

Show quoted text

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

I check the code and find that float8in exists a bug:
the strtod() function in linux dosen't set errno when dealing with
1.7976931348623159E308 but in windows it does
How should we improve it?

#3Magnus Hagander
magnus@hagander.net
In reply to: Richard Wang (#1)
Re: bug in float8in()

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

#4Tom Lane
tgl@sss.pgh.pa.us
In reply to: Magnus Hagander (#3)
Re: bug in float8in()

Magnus Hagander <magnus@hagander.net> writes:

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.

Note that the behavior isn't consistent across Unixen either ---
my HPUX box acts like Windows here. Basically Postgres just tries
to reflect the platform's floating-point support.

regards, tom lane