mirror of
https://github.com/postgres/postgres.git
synced 2025-07-03 20:02:46 +03:00
Make FLOAT(p) measure the precision p in bits, not decimal digits, to
match the SQL standard. Document FLOAT and FLOAT(p) notations in datatype.sgml. Per recent pghackers discussion.
This commit is contained in:
@ -1,5 +1,5 @@
|
|||||||
<!--
|
<!--
|
||||||
$Header: /cvsroot/pgsql/doc/src/sgml/datatype.sgml,v 1.116 2003/03/13 01:30:27 petere Exp $
|
$Header: /cvsroot/pgsql/doc/src/sgml/datatype.sgml,v 1.117 2003/06/17 23:12:36 tgl Exp $
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<chapter id="datatype">
|
<chapter id="datatype">
|
||||||
@ -607,16 +607,47 @@ NUMERIC
|
|||||||
</para>
|
</para>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
Normally, the <type>real</type> type has a range of at least
|
On most platforms, the <type>real</type> type has a range of at least
|
||||||
-1E+37 to +1E+37 with a precision of at least 6 decimal digits. The
|
1E-37 to 1E+37 with a precision of at least 6 decimal digits. The
|
||||||
<type>double precision</type> type normally has a range of around
|
<type>double precision</type> type typically has a range of around
|
||||||
-1E+308 to +1E+308 with a precision of at least 15 digits. Values that
|
1E-307 to 1E+308 with a precision of at least 15 digits. Values that
|
||||||
are too large or too small will cause an error. Rounding may
|
are too large or too small will cause an error. Rounding may
|
||||||
take place if the precision of an input number is too high.
|
take place if the precision of an input number is too high.
|
||||||
Numbers too close to zero that are not representable as distinct
|
Numbers too close to zero that are not representable as distinct
|
||||||
from zero will cause an underflow error.
|
from zero will cause an underflow error.
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
|
<para>
|
||||||
|
<productname>PostgreSQL</productname> also supports the SQL-standard
|
||||||
|
notations <type>float</type> and
|
||||||
|
<type>float(<replaceable>p</replaceable>)</type> for specifying
|
||||||
|
inexact numeric types. Here, <replaceable>p</replaceable> specifies
|
||||||
|
the minimum acceptable precision in binary digits.
|
||||||
|
<productname>PostgreSQL</productname> accepts
|
||||||
|
<type>float(1)</type> to <type>float(24)</type> as selecting the
|
||||||
|
<type>real</type> type, while
|
||||||
|
<type>float(25)</type> to <type>float(53)</type> select
|
||||||
|
<type>double precision</type>. Values of <replaceable>p</replaceable>
|
||||||
|
outside the allowed range draw an error.
|
||||||
|
<type>float</type> with no precision specified is taken to mean
|
||||||
|
<type>double precision</type>.
|
||||||
|
</para>
|
||||||
|
|
||||||
|
<note>
|
||||||
|
<para>
|
||||||
|
Prior to <productname>PostgreSQL</productname> 7.4, the precision in
|
||||||
|
<type>float(<replaceable>p</replaceable>)</type> was taken to mean
|
||||||
|
so many decimal digits. This has been corrected to match the SQL
|
||||||
|
standard, which specifies that the precision is measured in binary
|
||||||
|
digits. The assumption that <type>real</type> and
|
||||||
|
<type>double precision</type> have exactly 24 and 53 bits in the
|
||||||
|
mantissa respectively is correct for IEEE-standard floating point
|
||||||
|
implementations. On non-IEEE platforms it may be off a little, but
|
||||||
|
for simplicity the same ranges of <replaceable>p</replaceable> are used
|
||||||
|
on all platforms.
|
||||||
|
</para>
|
||||||
|
</note>
|
||||||
|
|
||||||
</sect2>
|
</sect2>
|
||||||
|
|
||||||
<sect2 id="datatype-serial">
|
<sect2 id="datatype-serial">
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
<!--
|
<!--
|
||||||
$Header: /cvsroot/pgsql/doc/src/sgml/release.sgml,v 1.192 2003/05/28 16:03:55 tgl Exp $
|
$Header: /cvsroot/pgsql/doc/src/sgml/release.sgml,v 1.193 2003/06/17 23:12:36 tgl Exp $
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<appendix id="release">
|
<appendix id="release">
|
||||||
@ -24,6 +24,7 @@ CDATA means the content is "SGML-free", so you can write without
|
|||||||
worries about funny characters.
|
worries about funny characters.
|
||||||
-->
|
-->
|
||||||
<literallayout><![CDATA[
|
<literallayout><![CDATA[
|
||||||
|
Precision in FLOAT(p) is now interpreted as bits, not decimal digits
|
||||||
Functional indexes have been generalized into expressional indexes
|
Functional indexes have been generalized into expressional indexes
|
||||||
CHAR(n) to TEXT conversion automatically strips trailing blanks
|
CHAR(n) to TEXT conversion automatically strips trailing blanks
|
||||||
Pattern matching operations can use indexes regardless of locale
|
Pattern matching operations can use indexes regardless of locale
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.416 2003/05/29 20:40:36 tgl Exp $
|
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.417 2003/06/17 23:12:36 tgl Exp $
|
||||||
*
|
*
|
||||||
* HISTORY
|
* HISTORY
|
||||||
* AUTHOR DATE MAJOR EVENT
|
* AUTHOR DATE MAJOR EVENT
|
||||||
@ -5051,8 +5051,8 @@ GenericType:
|
|||||||
|
|
||||||
/* SQL92 numeric data types
|
/* SQL92 numeric data types
|
||||||
* Check FLOAT() precision limits assuming IEEE floating types.
|
* Check FLOAT() precision limits assuming IEEE floating types.
|
||||||
* Provide real DECIMAL() and NUMERIC() implementations now - Jan 1998-12-30
|
|
||||||
* - thomas 1997-09-18
|
* - thomas 1997-09-18
|
||||||
|
* Provide real DECIMAL() and NUMERIC() implementations now - Jan 1998-12-30
|
||||||
*/
|
*/
|
||||||
Numeric: INT_P
|
Numeric: INT_P
|
||||||
{
|
{
|
||||||
@ -5107,14 +5107,14 @@ opt_float: '(' Iconst ')'
|
|||||||
{
|
{
|
||||||
if ($2 < 1)
|
if ($2 < 1)
|
||||||
elog(ERROR,
|
elog(ERROR,
|
||||||
"precision for FLOAT must be at least 1");
|
"precision for FLOAT must be at least 1 bit");
|
||||||
else if ($2 < 7)
|
else if ($2 <= 24)
|
||||||
$$ = SystemTypeName("float4");
|
$$ = SystemTypeName("float4");
|
||||||
else if ($2 < 16)
|
else if ($2 <= 53)
|
||||||
$$ = SystemTypeName("float8");
|
$$ = SystemTypeName("float8");
|
||||||
else
|
else
|
||||||
elog(ERROR,
|
elog(ERROR,
|
||||||
"precision for FLOAT must be less than 16");
|
"precision for FLOAT must be less than 54 bits");
|
||||||
}
|
}
|
||||||
| /*EMPTY*/
|
| /*EMPTY*/
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user