aboutsummaryrefslogtreecommitdiff
path: root/src/test/regress/sql/numeric.sql
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2008-04-04 18:45:36 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2008-04-04 18:45:36 +0000
commita0fad9762a22e739de69c85b51ff7a47e672732f (patch)
tree9224424c35267ba173351e4a59aea8fc2714d3c7 /src/test/regress/sql/numeric.sql
parentb6f0ad4b0ed7942654a26f04ca167cd2fe3c5d41 (diff)
downloadpostgresql-a0fad9762a22e739de69c85b51ff7a47e672732f.tar.gz
postgresql-a0fad9762a22e739de69c85b51ff7a47e672732f.zip
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.
Diffstat (limited to 'src/test/regress/sql/numeric.sql')
-rw-r--r--src/test/regress/sql/numeric.sql18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/test/regress/sql/numeric.sql b/src/test/regress/sql/numeric.sql
index dc1452f9ef0..9fd6bba31ee 100644
--- a/src/test/regress/sql/numeric.sql
+++ b/src/test/regress/sql/numeric.sql
@@ -805,3 +805,21 @@ INSERT INTO num_input_test(n1) VALUES ('');
INSERT INTO num_input_test(n1) VALUES (' N aN ');
SELECT * FROM num_input_test;
+
+--
+-- Test some corner cases for division
+--
+
+select 999999999999999999999::numeric/1000000000000000000000;
+select div(999999999999999999999::numeric,1000000000000000000000);
+select mod(999999999999999999999::numeric,1000000000000000000000);
+select div(-9999999999999999999999::numeric,1000000000000000000000);
+select mod(-9999999999999999999999::numeric,1000000000000000000000);
+select div(-9999999999999999999999::numeric,1000000000000000000000)*1000000000000000000000 + mod(-9999999999999999999999::numeric,1000000000000000000000);
+select mod (70.0,70) ;
+select div (70.0,70) ;
+select 70.0 / 70 ;
+select 12345678901234567890 % 123;
+select 12345678901234567890 / 123;
+select div(12345678901234567890, 123);
+select div(12345678901234567890, 123) * 123 + 12345678901234567890 % 123;