Skip to content

Commit a0fad97

Browse files
committed
Re-implement division for numeric values using the traditional "schoolbook"
algorithm. This is a good deal slower than our old roundoff-error-prone code for long inputs, so we keep the old code for use in the transcendental functions, where everything is approximate anyway. Also create a user-accessible function div(numeric, numeric) to provide access to the exact result of trunc(x/y) --- since the regular numeric / operator will round off its result, simply computing that expression in SQL doesn't reliably give the desired answer. This fixes bug #3387 and various related corner cases, and improves the usefulness of PG for high-precision integer arithmetic.
1 parent b6f0ad4 commit a0fad97

File tree

7 files changed

+470
-32
lines changed

7 files changed

+470
-32
lines changed

doc/src/sgml/func.sgml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $PostgreSQL: pgsql/doc/src/sgml/func.sgml,v 1.426 2008/04/04 16:57:21 momjian Exp $ -->
1+
<!-- $PostgreSQL: pgsql/doc/src/sgml/func.sgml,v 1.427 2008/04/04 18:45:36 tgl Exp $ -->
22

33
<chapter id="functions">
44
<title>Functions and Operators</title>
@@ -617,6 +617,9 @@
617617
<indexterm>
618618
<primary>degrees</primary>
619619
</indexterm>
620+
<indexterm>
621+
<primary>div</primary>
622+
</indexterm>
620623
<indexterm>
621624
<primary>exp</primary>
622625
</indexterm>
@@ -717,6 +720,15 @@
717720
<entry><literal>28.6478897565412</literal></entry>
718721
</row>
719722

723+
<row>
724+
<entry><literal><function>div</function>(<parameter>y</parameter> <type>numeric</>,
725+
<parameter>x</parameter> <type>numeric</>)</literal></entry>
726+
<entry><type>numeric</></entry>
727+
<entry>integer quotient of <parameter>y</parameter>/<parameter>x</parameter></entry>
728+
<entry><literal>div(9,4)</literal></entry>
729+
<entry><literal>2</literal></entry>
730+
</row>
731+
720732
<row>
721733
<entry><literal><function>exp</function>(<type>dp</type> or <type>numeric</type>)</literal></entry>
722734
<entry>(same as input)</entry>

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy