Commit Graph

17 Commits

Author SHA1 Message Date
Tom Lane 5e7c3d91bf Add documentation and regression tests concerning rounding of numerics.
Michael Paquier, reviewed by Fabien Coelho
2015-07-03 17:04:39 -04:00
Tom Lane 06bf0dd6e3 Upgrade src/port/rint.c to be POSIX-compliant.
The POSIX spec says that rint() rounds halfway cases to nearest even.
Our substitute implementation failed to do that, rather rounding halfway
cases away from zero; and it also got some other cases (such as minus
zero) wrong.  This led to observable cross-platform differences, as
reported in bug #12885 from Rich Schaaf; in particular, casting from
float to int didn't honor round-to-nearest-even on builds using rint.c.

Implement something that attempts to cover all cases per spec, and add
some simple regression tests so that we'll notice if any platforms still
get this wrong.

Although this is a bug fix, no back-patch, as a behavioral change in
the back branches was agreed not to be a good idea.

Pedro Gimeno Fortea, reviewed by Michael Paquier and myself
2015-03-25 15:54:18 -04:00
Tom Lane 1f7cb5c309 Improve handling of INT_MIN / -1 and related cases.
Some platforms throw an exception for this division, rather than returning
a necessarily-overflowed result.  Since we were testing for overflow after
the fact, an exception isn't nice.  We can avoid the problem by treating
division by -1 as negation.

Add some regression tests so that we'll find out if any compilers try to
optimize away the overflow check conditions.

This ought to be back-patched, but I'm going to see what the buildfarm
reports about the regression tests first.

Per discussion with Xi Wang, though this is different from the patch he
submitted.
2012-11-19 12:24:25 -05:00
Peter Eisentraut fc946c39ae Remove useless whitespace at end of lines 2010-11-23 22:34:55 +02:00
Robert Haas 815810ed31 Attempt to fix breakage caused by signed integer conversion patch.
Use INT_MIN rather than INT32_MIN as we do elsewhere in the code, and
try to work around nonexistence of INT64_MIN if necessary.  Adjust the
new regression tests to something hopefully saner, per observation by
Tom Lane.
2010-11-20 01:09:26 -05:00
Robert Haas 4fc115b2e9 Speed up conversion of signed integers to C strings.
A hand-coded implementation turns out to be much faster than calling
printf().  In passing, add a few more regresion tests.

Andres Freund, with assorted, mostly cosmetic changes.
2010-11-19 22:13:11 -05:00
Peter Eisentraut 6151e89e8b Remove some unportable tests 2008-10-05 18:56:09 +00:00
Peter Eisentraut 34411cfac5 Additional test coverage for int8 type (int8.c)
int8-exp-three-digits.out update untested, might need refinement.
2008-10-05 14:26:30 +00:00
Tom Lane 8cb4e4f6bd Add regression test to see if the min/max values of int8 convert correctly. 2005-12-05 04:13:38 +00:00
Bruce Momjian bb3cce4ec9 Add E'' syntax so eventually normal strings can treat backslashes
literally.

Add GUC variables:

        "escape_string_warning" - warn about backslashes in non-E strings
        "escape_string_syntax" - supports E'' syntax?
        "standard_compliant_strings" - treats backslashes literally in ''

Update code to use E'' when escapes are used.
2005-06-26 03:04:37 +00:00
Tom Lane 4171bb869f Detect overflow in integer arithmetic operators (integer, smallint, and
bigint variants).  Clean up some inconsistencies in error message wording.
Fix scanint8 to allow trailing whitespace in INT64_MIN case.  Update
int8-exp-three-digits.out, which seems to have been ignored by the last
couple of people to modify the int8 regression test, and remove
int8-exp-three-digits-win32.out which is thereby exposed as redundant.
2004-10-04 14:42:48 +00:00
Neil Conway e2ded829f6 Revise int2/int4/int8/float4/float8 input routines to allow for
any amount of leading or trailing whitespace (where "whitespace"
is defined by isspace()). This is for SQL conformance, as well
as consistency with other numeric types (e.g. oid, numeric).

Also refactor pg_atoi() to avoid looking at errno where not
necessary, and add a bunch of regression tests for the input
to these types.
2004-03-11 02:11:14 +00:00
Tom Lane b78d1bed07 Change float8-to-int8 conversion to round to nearest, rather than
truncating to integer.  Remove regress test that checks whether
4567890123456789 can be converted to float without loss; since that's
52 bits, it's on the hairy edge of failing with IEEE float8s, and indeed
rint seems to give platform-dependent results for it.
2001-01-26 22:50:26 +00:00
Bruce Momjian 28fb1c196b Update create_rule manual page. 2000-04-07 19:17:51 +00:00
Bruce Momjian eae5184d11 Hi,
the to_char() source code is large, here are regression tests for
numeric/timestamp/int8 part. It is probably enough test for formatting
code in the formatting.c module. The others (float4/float8/int4) types
share this formatting code and eventual bugs for these types aren't
few probable.

 Patch fix timestamp_to_char() for infinity/invalid timestamp too.


                                                Karel
2000-03-08 01:34:41 +00:00
Thomas G. Lockhart 61ef6a1a3f Clean up syntax to use SQL92-ish type coersion
rather than the Postgres "::" notation.
All of these tests have been completely inspected and give correct results.
2000-01-04 16:21:02 +00:00
Thomas G. Lockhart e2ba4ee2a8 Include tests for new 8-byte integer.
Include tests for HAVING clause.
1998-07-08 14:31:02 +00:00