Commit f1885386 authored by Tom Lane's avatar Tom Lane

Make float exponent output on Windows look the same as elsewhere.

Windows, alone among our supported platforms, likes to emit three-digit
exponent fields even when two digits would do.  Adjust such results to
look like the way everyone else does it.  Eliminate a bunch of variant
expected-output files that were needed only because of this quirk.

Discussion: https://postgr.es/m/2934.1539122454@sss.pgh.pa.us
parent b34e84f1
---
--- Testing cube output in scientific notation. This was put into separate
--- test, because has platform-depending output.
---
SELECT '1e27'::cube AS cube;
cube
----------
(1e+027)
(1 row)
SELECT '-1e27'::cube AS cube;
cube
-----------
(-1e+027)
(1 row)
SELECT '1.0e27'::cube AS cube;
cube
----------
(1e+027)
(1 row)
SELECT '-1.0e27'::cube AS cube;
cube
-----------
(-1e+027)
(1 row)
SELECT '1e+27'::cube AS cube;
cube
----------
(1e+027)
(1 row)
SELECT '-1e+27'::cube AS cube;
cube
-----------
(-1e+027)
(1 row)
SELECT '1.0e+27'::cube AS cube;
cube
----------
(1e+027)
(1 row)
SELECT '-1.0e+27'::cube AS cube;
cube
-----------
(-1e+027)
(1 row)
SELECT '1e-7'::cube AS cube;
cube
----------
(1e-007)
(1 row)
SELECT '-1e-7'::cube AS cube;
cube
-----------
(-1e-007)
(1 row)
SELECT '1.0e-7'::cube AS cube;
cube
----------
(1e-007)
(1 row)
SELECT '-1.0e-7'::cube AS cube;
cube
-----------
(-1e-007)
(1 row)
SELECT '1e-300'::cube AS cube;
cube
----------
(1e-300)
(1 row)
SELECT '-1e-300'::cube AS cube;
cube
-----------
(-1e-300)
(1 row)
SELECT '1234567890123456'::cube AS cube;
cube
-------------------------
(1.23456789012346e+015)
(1 row)
SELECT '+1234567890123456'::cube AS cube;
cube
-------------------------
(1.23456789012346e+015)
(1 row)
SELECT '-1234567890123456'::cube AS cube;
cube
--------------------------
(-1.23456789012346e+015)
(1 row)
This diff is collapsed.
from int = 1407.0
add = 2379.7
sub = 2369.7
mul = 13306998429.873000000
div = 1330699.84298730000 1.330700e+006
to long(0) = 20000000 14
compat_informix/dec_test:stdout:i.86-pc-win32vc=compat_informix-dec_test-MinGW32.stdout
compat_informix/dec_test:stdout:i.86-pc-mingw32=compat_informix-dec_test-MinGW32.stdout
compat_informix/dec_test:stdout:x86_64-w64-mingw32=compat_informix-dec_test-MinGW32.stdout
compat_informix/dec_test:stdout:i.86-w64-mingw32=compat_informix-dec_test-MinGW32.stdout
pgtypeslib/num_test:stdout:i.86-pc-win32vc=pgtypeslib-num_test-MinGW32.stdout
pgtypeslib/num_test:stdout:i.86-pc-mingw32=pgtypeslib-num_test-MinGW32.stdout
pgtypeslib/num_test:stdout:x86_64-w64-mingw32=pgtypeslib-num_test-MinGW32.stdout
pgtypeslib/num_test:stdout:i.86-w64-mingw32=pgtypeslib-num_test-MinGW32.stdout
pgtypeslib/num_test2:stdout:i.86-pc-win32vc=pgtypeslib-num_test2-MinGW32.stdout
pgtypeslib/num_test2:stdout:i.86-pc-mingw32=pgtypeslib-num_test2-MinGW32.stdout
pgtypeslib/num_test2:stdout:x86_64-w64-mingw32=pgtypeslib-num_test2-MinGW32.stdout
pgtypeslib/num_test2:stdout:i.86-w64-mingw32=pgtypeslib-num_test2-MinGW32.stdout
...@@ -1181,6 +1181,22 @@ fmtfloat(double value, char type, int forcesign, int leftjust, ...@@ -1181,6 +1181,22 @@ fmtfloat(double value, char type, int forcesign, int leftjust,
} }
if (vallen < 0) if (vallen < 0)
goto fail; goto fail;
/*
* Windows, alone among our supported platforms, likes to emit
* three-digit exponent fields even when two digits would do. Hack
* such results to look like the way everyone else does it.
*/
#ifdef WIN32
if (vallen >= 6 &&
convert[vallen - 5] == 'e' &&
convert[vallen - 3] == '0')
{
convert[vallen - 3] = convert[vallen - 2];
convert[vallen - 2] = convert[vallen - 1];
vallen--;
}
#endif
} }
padlen = compute_padlen(minlen, vallen + zeropadlen, leftjust); padlen = compute_padlen(minlen, vallen + zeropadlen, leftjust);
...@@ -1298,6 +1314,17 @@ pg_strfromd(char *str, size_t count, int precision, double value) ...@@ -1298,6 +1314,17 @@ pg_strfromd(char *str, size_t count, int precision, double value)
target.failed = true; target.failed = true;
goto fail; goto fail;
} }
#ifdef WIN32
if (vallen >= 6 &&
convert[vallen - 5] == 'e' &&
convert[vallen - 3] == '0')
{
convert[vallen - 3] = convert[vallen - 2];
convert[vallen - 2] = convert[vallen - 1];
vallen--;
}
#endif
} }
} }
......
--
-- FLOAT4
--
CREATE TABLE FLOAT4_TBL (f1 float4);
INSERT INTO FLOAT4_TBL(f1) VALUES (' 0.0');
INSERT INTO FLOAT4_TBL(f1) VALUES ('1004.30 ');
INSERT INTO FLOAT4_TBL(f1) VALUES (' -34.84 ');
INSERT INTO FLOAT4_TBL(f1) VALUES ('1.2345678901234e+20');
INSERT INTO FLOAT4_TBL(f1) VALUES ('1.2345678901234e-20');
-- test for over and under flow
INSERT INTO FLOAT4_TBL(f1) VALUES ('10e70');
ERROR: value out of range: overflow
LINE 1: INSERT INTO FLOAT4_TBL(f1) VALUES ('10e70');
^
INSERT INTO FLOAT4_TBL(f1) VALUES ('-10e70');
ERROR: value out of range: overflow
LINE 1: INSERT INTO FLOAT4_TBL(f1) VALUES ('-10e70');
^
INSERT INTO FLOAT4_TBL(f1) VALUES ('10e-70');
ERROR: value out of range: underflow
LINE 1: INSERT INTO FLOAT4_TBL(f1) VALUES ('10e-70');
^
INSERT INTO FLOAT4_TBL(f1) VALUES ('-10e-70');
ERROR: value out of range: underflow
LINE 1: INSERT INTO FLOAT4_TBL(f1) VALUES ('-10e-70');
^
-- bad input
INSERT INTO FLOAT4_TBL(f1) VALUES ('');
ERROR: invalid input syntax for type real: ""
LINE 1: INSERT INTO FLOAT4_TBL(f1) VALUES ('');
^
INSERT INTO FLOAT4_TBL(f1) VALUES (' ');
ERROR: invalid input syntax for type real: " "
LINE 1: INSERT INTO FLOAT4_TBL(f1) VALUES (' ');
^
INSERT INTO FLOAT4_TBL(f1) VALUES ('xyz');
ERROR: invalid input syntax for type real: "xyz"
LINE 1: INSERT INTO FLOAT4_TBL(f1) VALUES ('xyz');
^
INSERT INTO FLOAT4_TBL(f1) VALUES ('5.0.0');
ERROR: invalid input syntax for type real: "5.0.0"
LINE 1: INSERT INTO FLOAT4_TBL(f1) VALUES ('5.0.0');
^
INSERT INTO FLOAT4_TBL(f1) VALUES ('5 . 0');
ERROR: invalid input syntax for type real: "5 . 0"
LINE 1: INSERT INTO FLOAT4_TBL(f1) VALUES ('5 . 0');
^
INSERT INTO FLOAT4_TBL(f1) VALUES ('5. 0');
ERROR: invalid input syntax for type real: "5. 0"
LINE 1: INSERT INTO FLOAT4_TBL(f1) VALUES ('5. 0');
^
INSERT INTO FLOAT4_TBL(f1) VALUES (' - 3.0');
ERROR: invalid input syntax for type real: " - 3.0"
LINE 1: INSERT INTO FLOAT4_TBL(f1) VALUES (' - 3.0');
^
INSERT INTO FLOAT4_TBL(f1) VALUES ('123 5');
ERROR: invalid input syntax for type real: "123 5"
LINE 1: INSERT INTO FLOAT4_TBL(f1) VALUES ('123 5');
^
-- special inputs
SELECT 'NaN'::float4;
float4
--------
NaN
(1 row)
SELECT 'nan'::float4;
float4
--------
NaN
(1 row)
SELECT ' NAN '::float4;
float4
--------
NaN
(1 row)
SELECT 'infinity'::float4;
float4
----------
Infinity
(1 row)
SELECT ' -INFINiTY '::float4;
float4
-----------
-Infinity
(1 row)
-- bad special inputs
SELECT 'N A N'::float4;
ERROR: invalid input syntax for type real: "N A N"
LINE 1: SELECT 'N A N'::float4;
^
SELECT 'NaN x'::float4;
ERROR: invalid input syntax for type real: "NaN x"
LINE 1: SELECT 'NaN x'::float4;
^
SELECT ' INFINITY x'::float4;
ERROR: invalid input syntax for type real: " INFINITY x"
LINE 1: SELECT ' INFINITY x'::float4;
^
SELECT 'Infinity'::float4 + 100.0;
?column?
----------
Infinity
(1 row)
SELECT 'Infinity'::float4 / 'Infinity'::float4;
?column?
----------
NaN
(1 row)
SELECT 'nan'::float4 / 'nan'::float4;
?column?
----------
NaN
(1 row)
SELECT 'nan'::numeric::float4;
float4
--------
NaN
(1 row)
SELECT '' AS five, * FROM FLOAT4_TBL;
five | f1
------+--------------
| 0
| 1004.3
| -34.84
| 1.23457e+020
| 1.23457e-020
(5 rows)
SELECT '' AS four, f.* FROM FLOAT4_TBL f WHERE f.f1 <> '1004.3';
four | f1
------+--------------
| 0
| -34.84
| 1.23457e+020
| 1.23457e-020
(4 rows)
SELECT '' AS one, f.* FROM FLOAT4_TBL f WHERE f.f1 = '1004.3';
one | f1
-----+--------
| 1004.3
(1 row)
SELECT '' AS three, f.* FROM FLOAT4_TBL f WHERE '1004.3' > f.f1;
three | f1
-------+--------------
| 0
| -34.84
| 1.23457e-020
(3 rows)
SELECT '' AS three, f.* FROM FLOAT4_TBL f WHERE f.f1 < '1004.3';
three | f1
-------+--------------
| 0
| -34.84
| 1.23457e-020
(3 rows)
SELECT '' AS four, f.* FROM FLOAT4_TBL f WHERE '1004.3' >= f.f1;
four | f1
------+--------------
| 0
| 1004.3
| -34.84
| 1.23457e-020
(4 rows)
SELECT '' AS four, f.* FROM FLOAT4_TBL f WHERE f.f1 <= '1004.3';
four | f1
------+--------------
| 0
| 1004.3
| -34.84
| 1.23457e-020
(4 rows)
SELECT '' AS three, f.f1, f.f1 * '-10' AS x FROM FLOAT4_TBL f
WHERE f.f1 > '0.0';
three | f1 | x
-------+--------------+---------------
| 1004.3 | -10043
| 1.23457e+020 | -1.23457e+021
| 1.23457e-020 | -1.23457e-019
(3 rows)
SELECT '' AS three, f.f1, f.f1 + '-10' AS x FROM FLOAT4_TBL f
WHERE f.f1 > '0.0';
three | f1 | x
-------+--------------+--------------
| 1004.3 | 994.3
| 1.23457e+020 | 1.23457e+020
| 1.23457e-020 | -10
(3 rows)
SELECT '' AS three, f.f1, f.f1 / '-10' AS x FROM FLOAT4_TBL f
WHERE f.f1 > '0.0';
three | f1 | x
-------+--------------+---------------
| 1004.3 | -100.43
| 1.23457e+020 | -1.23457e+019
| 1.23457e-020 | -1.23457e-021
(3 rows)
SELECT '' AS three, f.f1, f.f1 - '-10' AS x FROM FLOAT4_TBL f
WHERE f.f1 > '0.0';
three | f1 | x
-------+--------------+--------------
| 1004.3 | 1014.3
| 1.23457e+020 | 1.23457e+020
| 1.23457e-020 | 10
(3 rows)
-- test divide by zero
SELECT '' AS bad, f.f1 / '0.0' from FLOAT4_TBL f;
ERROR: division by zero
SELECT '' AS five, * FROM FLOAT4_TBL;
five | f1
------+--------------
| 0
| 1004.3
| -34.84
| 1.23457e+020
| 1.23457e-020
(5 rows)
-- test the unary float4abs operator
SELECT '' AS five, f.f1, @f.f1 AS abs_f1 FROM FLOAT4_TBL f;
five | f1 | abs_f1
------+--------------+--------------
| 0 | 0
| 1004.3 | 1004.3
| -34.84 | 34.84
| 1.23457e+020 | 1.23457e+020
| 1.23457e-020 | 1.23457e-020
(5 rows)
UPDATE FLOAT4_TBL
SET f1 = FLOAT4_TBL.f1 * '-1'
WHERE FLOAT4_TBL.f1 > '0.0';
SELECT '' AS five, * FROM FLOAT4_TBL;
five | f1
------+---------------
| 0
| -34.84
| -1004.3
| -1.23457e+020
| -1.23457e-020
(5 rows)
This diff is collapsed.
This diff is collapsed.
float4:out:i.86-pc-mingw32=float4-exp-three-digits.out
float4:out:x86_64-w64-mingw32=float4-exp-three-digits.out
float4:out:i.86-w64-mingw32=float4-exp-three-digits.out
float4:out:i.86-pc-win32vc=float4-exp-three-digits.out
float8:out:i.86-.*-freebsd=float8-small-is-zero.out float8:out:i.86-.*-freebsd=float8-small-is-zero.out
float8:out:i.86-.*-openbsd=float8-small-is-zero.out float8:out:i.86-.*-openbsd=float8-small-is-zero.out
float8:out:i.86-.*-netbsd=float8-small-is-zero.out float8:out:i.86-.*-netbsd=float8-small-is-zero.out
float8:out:m68k-.*-netbsd=float8-small-is-zero.out float8:out:m68k-.*-netbsd=float8-small-is-zero.out
float8:out:i.86-pc-mingw32=float8-exp-three-digits-win32.out
float8:out:x86_64-w64-mingw32=float8-exp-three-digits-win32.out
float8:out:i.86-w64-mingw32=float8-exp-three-digits-win32.out
float8:out:i.86-pc-win32vc=float8-exp-three-digits-win32.out
float8:out:i.86-pc-cygwin=float8-small-is-zero.out float8:out:i.86-pc-cygwin=float8-small-is-zero.out
int8:out:i.86-pc-mingw32=int8-exp-three-digits.out
int8:out:x86_64-w64-mingw32=int8-exp-three-digits.out
int8:out:i.86-w64-mingw32=int8-exp-three-digits.out
int8:out:i.86-pc-win32vc=int8-exp-three-digits.out
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment