Re: casts: max double precision > text > double precision fails with out or range error

From: Alvaro Herrera <alvherre(at)commandprompt(dot)com>
To: Maciej Sakrejda <m(dot)sakrejda(at)gmail(dot)com>
Cc: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: casts: max double precision > text > double precision fails with out or range error
Date: 2011-01-11 15:50:18
Message-ID: 1294760907-sup-6492@alvh.no-ip.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Excerpts from Maciej Sakrejda's message of mar ene 11 03:28:13 -0300 2011:
> Tried asking this in pgsql-general but I got no response, so I thought
> I'd give hackers a shot:
>
> postgres=# select (((1.7976931348623157081e+308)::double
> precision)::text)::double precision;
> ERROR: "1.79769313486232e+308" is out of range for type double precision
>
> I'm working on a pg driver and in my float data decoder functional
> tests, I ran into some errors that I eventually traced back to this
> behavior. Essentially, postgres seems to cast the max normal double
> (i.e., the bits of ~(1ULL<<52 | 1ULL<<63)) to text in such a manner
> that it's rounded up, and the reverse cast, text-to-double-precision,
> does not recognize it as being in range. Curiously, pg_dump seems to
> print doubles with more precision (in both COPY and INSERT modes),
> avoiding this issue.

Yeah, it sets the extra_float_digits parameter.

alvherre=# set extra_float_digits to 3;
SET
alvherre=# select (((1.7976931348623157081e+308)::double precision)::text)::double precision;
float8
──────────────────────────
1.79769313486231571e+308
(1 fila)

--
Álvaro Herrera <alvherre(at)commandprompt(dot)com>
The PostgreSQL Company - Command Prompt, Inc.
PostgreSQL Replication, Consulting, Custom Development, 24x7 support

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Joel Jacobson 2011-01-11 15:54:36 pg_depend explained
Previous Message Florian Pflug 2011-01-11 15:48:54 Re: Bug in pg_describe_object