123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372 |
- # Copyright 1994, Regents of the University of California.
- # Copyright 1996-2019 PostgreSQL Global Development Group.
- # Copyright Materialize, Inc. and contributors. All rights reserved.
- #
- # Use of this software is governed by the Business Source License
- # included in the LICENSE file at the root of this repository.
- #
- # As of the Change Date specified in that file, in accordance with
- # the Business Source License, use of this software will be governed
- # by the Apache License, Version 2.0.
- #
- # This file is derived from the regression test suite in PostgreSQL.
- # The original file was retrieved on February 10, 2021 from:
- #
- # https://github.com/postgres/postgres/blob/64990081504661ff5c04dbf20cc4252be66ab149/src/test/regress/expected/float8.out
- #
- # The original source code is subject to the terms of the PostgreSQL
- # license, a copy of which can be found in the LICENSE file at the
- # root of this repository.
- mode cockroach
- statement ok
- CREATE TABLE float8_tbl (f1 float8)
- statement ok
- INSERT INTO float8_tbl (f1) VALUES (' 0.0 '), ('1004.30 '), (' -34.84'), ('1.2345678901234e+200'), ('1.2345678901234e-200')
- # test for underflow and overflow handling
- query error "10e400" is out of range for type double precision
- SELECT '10e400'::float8
- query error "-10e400" is out of range for type double precision
- SELECT '-10e400'::float8
- query error "10e-400" is out of range for type double precision
- SELECT '10e-400'::float8
- query error "-10e-400" is out of range for type double precision
- SELECT '-10e-400'::float8
- # bad input
- query error invalid input syntax for type double precision: ""
- SELECT ''::float8
- query error invalid input syntax for type double precision: " "
- SELECT ' '::float8
- query error invalid input syntax for type double precision: "xyz"
- SELECT 'xyz'::float8
- query error invalid input syntax for type double precision: "5.0.0"
- SELECT '5.0.0'::float8
- query error invalid input syntax for type double precision: "5 . 0"
- SELECT '5 . 0'::float8
- query error invalid input syntax for type double precision: "5. 0"
- SELECT '5. 0'::float8
- query error invalid input syntax for type double precision: " - 3"
- SELECT ' - 3'::float8
- query error invalid input syntax for type double precision: "123 5"
- SELECT '123 5'::float8
- # special inputs
- query T
- SELECT 'NaN'::float8::text
- ----
- NaN
- query T
- SELECT 'nan'::float8::text
- ----
- NaN
- query T
- SELECT ' NAN '::float8::text
- ----
- NaN
- query T
- SELECT 'infinity'::float8::text
- ----
- Infinity
- query T
- SELECT ' -INFINiTY '::float8::text
- ----
- -Infinity
- # bad special inputs
- query error invalid input syntax for type double precision: "N A N"
- SELECT 'N A N'::float8::text
- query error invalid input syntax for type double precision: "NaN x"
- SELECT 'NaN x'::float8;
- query error invalid input syntax for type double precision: " INFINITY x"
- SELECT ' INFINITY x'::float8
- query T
- SELECT ('Infinity'::float8 + 100.0)::text
- ----
- Infinity
- query T
- SELECT ('Infinity'::float8 / 'Infinity'::float8)::text
- ----
- NaN
- query R
- SELECT '42'::float8 / 'Infinity'::float8
- ----
- 0
- query T
- SELECT ('nan'::float8 / 'nan'::float8)::text
- ----
- NaN
- query T
- SELECT ('nan'::float8 / '0'::float8)::text
- ----
- NaN
- # TODO(benesch): re-enable when the numeric type supports NaN.
- #
- # query T
- # SELECT 'nan'::numeric::float8
- # ----
- # NaN
- query T rowsort
- SELECT f1::text FROM float8_tbl
- ----
- 0
- 1004.3
- -34.84
- 1.2345678901234e+200
- 1.2345678901234e-200
- query T rowsort
- SELECT f.f1::text FROM float8_tbl f WHERE f.f1 <> '1004.3'
- ----
- 0
- -34.84
- 1.2345678901234e+200
- 1.2345678901234e-200
- query T
- SELECT f.f1::text FROM float8_tbl f WHERE f.f1 = '1004.3'
- ----
- 1004.3
- query T rowsort
- SELECT f.f1::text FROM float8_tbl f WHERE '1004.3' > f.f1
- ----
- 0
- -34.84
- 1.2345678901234e-200
- query T rowsort
- SELECT f.f1::text FROM float8_tbl f WHERE f.f1 < '1004.3'
- ----
- 0
- -34.84
- 1.2345678901234e-200
- query T rowsort
- SELECT f.f1::text FROM float8_tbl f WHERE '1004.3' >= f.f1
- ----
- 0
- 1004.3
- -34.84
- 1.2345678901234e-200
- query T rowsort
- SELECT f.f1::text FROM float8_tbl f WHERE f.f1 <= '1004.3'
- ----
- 0
- 1004.3
- -34.84
- 1.2345678901234e-200
- query TT rowsort
- SELECT f.f1::text, (f.f1 * '-10')::text AS x FROM float8_tbl f WHERE f.f1 > '0.0'
- ----
- 1004.3 -10043
- 1.2345678901234e+200 -1.2345678901234e+201
- 1.2345678901234e-200 -1.2345678901234e-199
- query TT rowsort
- SELECT f.f1::text, (f.f1 + '-10')::text AS x FROM float8_tbl f WHERE f.f1 > '0.0'
- ----
- 1004.3 994.3
- 1.2345678901234e+200 1.2345678901234e+200
- 1.2345678901234e-200 -10
- query TT rowsort
- SELECT f.f1::text, (f.f1 / '-10')::text AS x FROM float8_tbl f WHERE f.f1 > '0.0'
- ----
- 1004.3 -100.42999999999999
- 1.2345678901234e+200 -1.2345678901234e+199
- 1.2345678901234e-200 -1.2345678901234e-201
- query TT rowsort
- SELECT f.f1::text, (f.f1 - '-10')::text AS x FROM float8_tbl f WHERE f.f1 > '0.0';
- ----
- 1004.3 1014.3
- 1.2345678901234e+200 1.2345678901234e+200
- 1.2345678901234e-200 10
- # -- round
- query TT rowsort
- SELECT f.f1::text, round(f.f1)::text AS round_f1 FROM float8_tbl f
- ----
- 0 0
- 1004.3 1004
- -34.84 -35
- 1.2345678901234e+200 1.2345678901234e+200
- 1.2345678901234e-200 0
- # ceil / ceiling
- query T rowsort
- select ceil(f1)::text as ceil_f1 from float8_tbl f
- ----
- 0
- 1005
- -34
- 1.2345678901234e+200
- 1
- query T rowsort
- select ceiling(f1)::text as ceiling_f1 from float8_tbl f;
- ----
- 0
- 1005
- -34
- 1.2345678901234e+200
- 1
- # floor
- query T rowsort
- select floor(f1)::text as floor_f1 from float8_tbl f
- ----
- 0
- 1004
- -35
- 1.2345678901234e+200
- 0
- # TODO(benesch): support sign.
- #
- # -- sign
- # select sign(f1) as sign_f1 from float8_tbl f;
- # sign_f1
- # ---------
- # 0
- # 1
- # -1
- # 1
- # 1
- # (5 rows)
- # test for over- and underflow
- query error "10e400" is out of range for type double precision
- SELECT '10e400'::float8
- query error "-10e400" is out of range for type double precision
- SELECT '-10e400'::float8
- query error "10e-400" is out of range for type double precision
- SELECT '10e-400'::float8
- query error "-10e-400" is out of range for type double precision
- SELECT '-10e-400'::float8
- # test edge-case coercions to integer
- query I
- SELECT '32767.4'::float8::int2;
- ----
- 32767
- query error smallint out of range
- SELECT '32767.6'::float8::int2;
- query I
- SELECT '-32768.4'::float8::int2;
- ----
- -32768
- query error smallint out of range
- SELECT '-32768.6'::float8::int2;
- query I
- SELECT '2147483647.4'::float8::int4;
- ----
- 2147483647
- query error "2147483648" integer out of range
- SELECT '2147483647.6'::float8::int4
- query I
- SELECT '-2147483648.4'::float8::int4
- ----
- -2147483648
- query error "-2147483649" integer out of range
- SELECT '-2147483648.6'::float8::int4
- query I
- SELECT '9223372036854773760'::float8::int8
- ----
- 9223372036854773760
- query error "9223372036854776000" bigint out of range
- SELECT '9223372036854775807'::float8::int8
- query I
- SELECT '-9223372036854775808.5'::float8::int8
- ----
- -9223372036854775808
- query error "-9223372036854780000" bigint out of range
- SELECT '-9223372036854780000'::float8::int8
- query error "922337203685477600000" bigint out of range
- SELECT '922337203685477580700.0'::float8::int8
- query RI rowsort
- SELECT x, x::int4 AS int4_value
- FROM (VALUES (-2.5::float8),
- (-1.5::float8),
- (-0.5::float8),
- (0.0::float8),
- (0.5::float8),
- (1.5::float8),
- (2.5::float8)) t(x);
- ----
- -2.5 -2
- -1.5 -2
- -0.5 0
- 0 0
- 0.5 0
- 1.5 2
- 2.5 2
- query RI rowsort
- SELECT x, x::int8 AS int8_value
- FROM (VALUES (-2.5::float8),
- (-1.5::float8),
- (-0.5::float8),
- (0.0::float8),
- (0.5::float8),
- (1.5::float8),
- (2.5::float8)) t(x);
- ----
- -2.5 -2
- -1.5 -2
- -0.5 0
- 0 0
- 0.5 0
- 1.5 2
- 2.5 2
- query T
- SELECT 4567890123456789::int8::float8::text
- ----
- 4567890123456789
|