mirror of
https://git.postgresql.org/git/postgresql.git
synced 2025-01-06 15:24:56 +08: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:
parent
596652d6eb
commit
eab5d643b2
@ -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">
|
||||
@ -607,16 +607,47 @@ NUMERIC
|
||||
</para>
|
||||
|
||||
<para>
|
||||
Normally, 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
|
||||
<type>double precision</type> type normally has a range of around
|
||||
-1E+308 to +1E+308 with a precision of at least 15 digits. Values that
|
||||
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
|
||||
<type>double precision</type> type typically has a range of around
|
||||
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
|
||||
take place if the precision of an input number is too high.
|
||||
Numbers too close to zero that are not representable as distinct
|
||||
from zero will cause an underflow error.
|
||||
</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 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">
|
||||
@ -24,6 +24,7 @@ CDATA means the content is "SGML-free", so you can write without
|
||||
worries about funny characters.
|
||||
-->
|
||||
<literallayout><![CDATA[
|
||||
Precision in FLOAT(p) is now interpreted as bits, not decimal digits
|
||||
Functional indexes have been generalized into expressional indexes
|
||||
CHAR(n) to TEXT conversion automatically strips trailing blanks
|
||||
Pattern matching operations can use indexes regardless of locale
|
||||
|
@ -11,7 +11,7 @@
|
||||
*
|
||||
*
|
||||
* 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
|
||||
* AUTHOR DATE MAJOR EVENT
|
||||
@ -5051,8 +5051,8 @@ GenericType:
|
||||
|
||||
/* SQL92 numeric data types
|
||||
* Check FLOAT() precision limits assuming IEEE floating types.
|
||||
* Provide real DECIMAL() and NUMERIC() implementations now - Jan 1998-12-30
|
||||
* - thomas 1997-09-18
|
||||
* Provide real DECIMAL() and NUMERIC() implementations now - Jan 1998-12-30
|
||||
*/
|
||||
Numeric: INT_P
|
||||
{
|
||||
@ -5107,14 +5107,14 @@ opt_float: '(' Iconst ')'
|
||||
{
|
||||
if ($2 < 1)
|
||||
elog(ERROR,
|
||||
"precision for FLOAT must be at least 1");
|
||||
else if ($2 < 7)
|
||||
"precision for FLOAT must be at least 1 bit");
|
||||
else if ($2 <= 24)
|
||||
$$ = SystemTypeName("float4");
|
||||
else if ($2 < 16)
|
||||
else if ($2 <= 53)
|
||||
$$ = SystemTypeName("float8");
|
||||
else
|
||||
elog(ERROR,
|
||||
"precision for FLOAT must be less than 16");
|
||||
"precision for FLOAT must be less than 54 bits");
|
||||
}
|
||||
| /*EMPTY*/
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user