float4.slt 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  1. # Copyright 1994, Regents of the University of California.
  2. # Copyright 1996-2019 PostgreSQL Global Development Group.
  3. # Copyright Materialize, Inc. and contributors. All rights reserved.
  4. #
  5. # Use of this software is governed by the Business Source License
  6. # included in the LICENSE file at the root of this repository.
  7. #
  8. # As of the Change Date specified in that file, in accordance with
  9. # the Business Source License, use of this software will be governed
  10. # by the Apache License, Version 2.0.
  11. #
  12. # This file is derived from the regression test suite in PostgreSQL.
  13. # The original file was retrieved on February 10, 2021 from:
  14. #
  15. # https://github.com/postgres/postgres/blob/64990081504661ff5c04dbf20cc4252be66ab149/src/test/regress/expected/float4.out
  16. #
  17. # The original source code is subject to the terms of the PostgreSQL
  18. # license, a copy of which can be found in the LICENSE file at the
  19. # root of this repository.
  20. mode cockroach
  21. statement ok
  22. CREATE TABLE float4_tbl (f1 float4)
  23. statement ok
  24. INSERT INTO float4_tbl (f1) VALUES (' 0.0'), ('1004.30 '), (' -34.84 '), ('1.2345678901234e+20'), ('1.2345678901234e-20')
  25. # test for over and under flow
  26. query error "10e70" is out of range for type real
  27. SELECT '10e70'::float4
  28. query error "-10e70" is out of range for type real
  29. SELECT '-10e70'::float4
  30. query error "10e-70" is out of range for type real
  31. SELECT '10e-70'::float4
  32. query error "-10e-70" is out of range for type real
  33. SELECT '-10e-70'::float4
  34. query error value out of range: overflow
  35. SELECT '10e70'::float8::float4
  36. query error value out of range: overflow
  37. SELECT '-10e70'::float8::float4
  38. query error value out of range: underflow
  39. SELECT '10e-70'::float8::float4
  40. query error value out of range: underflow
  41. SELECT '-10e-70'::float8::float4
  42. query error "10e400" is out of range for type real
  43. SELECT '10e400'::float4
  44. query error "-10e400" is out of range for type real
  45. SELECT '-10e400'::float4
  46. query error "10e-400" is out of range for type real
  47. SELECT '10e-400'::float4
  48. query error "-10e-400" is out of range for type real
  49. SELECT '-10e-400'::float4
  50. query error invalid input syntax for type real: ""
  51. SELECT ''::float4
  52. query error invalid input syntax for type real: " "
  53. SELECT ' '::float4
  54. query error invalid input syntax for type real: "xyz"
  55. SELECT 'xyz'::float4
  56. query error invalid input syntax for type real: "5.0.0"
  57. SELECT '5.0.0'::float4
  58. query error invalid input syntax for type real: "5 . 0"
  59. SELECT '5 . 0'::float4
  60. query error invalid input syntax for type real: "5. 0"
  61. SELECT '5. 0'::float4
  62. query error invalid input syntax for type real: " - 3.0"
  63. SELECT ' - 3.0'::float4
  64. query error invalid input syntax for type real: "123 5"
  65. SELECT '123 5'::float4
  66. query T
  67. SELECT 'NaN'::float4::text
  68. ----
  69. NaN
  70. query T
  71. SELECT 'nan'::float4::text
  72. ----
  73. NaN
  74. query T
  75. SELECT ' NAN '::float4::text
  76. ----
  77. NaN
  78. query T
  79. SELECT 'infinity'::float4::text
  80. ----
  81. Infinity
  82. query T
  83. SELECT ' -INFINiTY '::float4::text
  84. ----
  85. -Infinity
  86. query error invalid input syntax for type real: "N A N"
  87. SELECT 'N A N'::float4
  88. query error invalid input syntax for type real: "NaN x"
  89. SELECT 'NaN x'::float4;
  90. query error invalid input syntax for type real: " INFINITY x"
  91. SELECT ' INFINITY x'::float4
  92. query T
  93. SELECT ('Infinity'::float4 + 100.0)::text
  94. ----
  95. Infinity
  96. query T
  97. SELECT ('Infinity'::float4 / 'Infinity'::float4)::text
  98. ----
  99. NaN
  100. query T
  101. SELECT ('42'::float4 / 'Infinity'::float4)::text
  102. ----
  103. 0
  104. query T
  105. SELECT ('nan'::float4 / 'nan'::float4)::text
  106. ----
  107. NaN
  108. query T
  109. SELECT ('nan'::float4 / '0'::float4)::text
  110. ----
  111. NaN
  112. # TODO(benesch): re-enable when the numeric type supports NaN.
  113. #
  114. # query R
  115. # SELECT 'nan'::numeric::float4;
  116. # ----
  117. # NaN
  118. query T rowsort
  119. SELECT f1::text FROM float4_tbl
  120. ----
  121. 0
  122. 1004.3
  123. -34.84
  124. 1.2345679e+20
  125. 1.2345679e-20
  126. query T rowsort
  127. SELECT f1::text FROM float4_tbl WHERE f1 <> '1004.3'
  128. ----
  129. 0
  130. -34.84
  131. 1.2345679e+20
  132. 1.2345679e-20
  133. query T
  134. SELECT f1::text FROM float4_tbl WHERE f1 = '1004.3'
  135. ----
  136. 1004.3
  137. query T rowsort
  138. SELECT f1::text FROM float4_tbl WHERE '1004.3' > f1
  139. ----
  140. 0
  141. -34.84
  142. 1.2345679e-20
  143. query T rowsort
  144. SELECT f1::text FROM float4_tbl WHERE f1 < '1004.3'
  145. ----
  146. 0
  147. -34.84
  148. 1.2345679e-20
  149. query T rowsort
  150. SELECT f1::text FROM float4_tbl WHERE '1004.3' >= f1
  151. ----
  152. 0
  153. 1004.3
  154. -34.84
  155. 1.2345679e-20
  156. query T rowsort
  157. SELECT f1::text FROM float4_tbl WHERE f1 <= '1004.3'
  158. ----
  159. 0
  160. 1004.3
  161. -34.84
  162. 1.2345679e-20
  163. query TT rowsort
  164. SELECT f.f1::text, (f.f1 * '-10')::text AS x FROM float4_tbl f
  165. WHERE f.f1 > '0.0'
  166. ----
  167. 1004.3 -10043
  168. 1.2345679e+20 -1.2345678e+21
  169. 1.2345679e-20 -1.2345678e-19
  170. query TT rowsort
  171. SELECT f.f1::text, (f.f1 + '-10')::text AS x FROM float4_tbl f
  172. WHERE f.f1 > '0.0'
  173. ----
  174. 1004.3 994.3
  175. 1.2345679e+20 1.2345679e+20
  176. 1.2345679e-20 -10
  177. query TT rowsort
  178. SELECT f.f1::text, (f.f1 / '-10')::text AS x FROM float4_tbl f
  179. WHERE f.f1 > '0.0'
  180. ----
  181. 1004.3 -100.43
  182. 1.2345679e+20 -1.2345679e+19
  183. 1.2345679e-20 -1.2345679e-21
  184. query TT rowsort
  185. SELECT f.f1::text, (f.f1 - '-10')::text AS x FROM float4_tbl f
  186. WHERE f.f1 > '0.0'
  187. ----
  188. 1004.3 1014.3
  189. 1.2345679e+20 1.2345679e+20
  190. 1.2345679e-20 10
  191. # test divide by zero
  192. query error division by zero
  193. SELECT f.f1 / '0.0' from float4_tbl f;
  194. query T rowsort
  195. SELECT f1::text FROM float4_tbl
  196. ----
  197. 0
  198. 1004.3
  199. -34.84
  200. 1.2345679e+20
  201. 1.2345679e-20
  202. # -- test the unary float4abs operator
  203. # SELECT f.f1, @f.f1 AS abs_f1 FROM float4_tbl f;
  204. # f1 | abs_f1
  205. # ---------------+---------------
  206. # 0 | 0
  207. # 1004.3 | 1004.3
  208. # -34.84 | 34.84
  209. # 1.2345679e+20 | 1.2345679e+20
  210. # 1.2345679e-20 | 1.2345679e-20
  211. # (5 rows)
  212. statement ok
  213. UPDATE float4_tbl SET f1 = float4_tbl.f1 * '-1' WHERE float4_tbl.f1 > '0.0'
  214. query T rowsort
  215. SELECT f1::text FROM float4_tbl
  216. ----
  217. 0
  218. -34.84
  219. -1004.3
  220. -1.2345679e+20
  221. -1.2345679e-20
  222. # test edge-case coercions to integer
  223. query I
  224. SELECT '32767.4'::float4::int2;
  225. ----
  226. 32767
  227. query error smallint out of range
  228. SELECT '32767.6'::float4::int2;
  229. query I
  230. SELECT '-32768.4'::float4::int2;
  231. ----
  232. -32768
  233. query error smallint out of range
  234. SELECT '-32768.6'::float4::int2;
  235. query I
  236. SELECT '2147483520'::float4::int4;
  237. ----
  238. 2147483520
  239. query error "2147483600" integer out of range
  240. SELECT '2147483647'::float4::int4
  241. query I
  242. SELECT '-2147483648.5'::float4::int4
  243. ----
  244. -2147483648
  245. query error "-2147484000" integer out of range
  246. SELECT '-2147483900'::float4::int4
  247. query I
  248. SELECT '9223369837831520256'::float4::int8
  249. ----
  250. 9223369837831520256
  251. query error "9223372000000000000" bigint out of range
  252. SELECT '9223372036854775807'::float4::int8;
  253. query I
  254. SELECT '-9223372036854775808.5'::float4::int8;
  255. ----
  256. -9223372036854775808
  257. query error "-9223380000000000000" bigint out of range
  258. SELECT '-9223380000000000000'::float4::int8
  259. query T
  260. SELECT '36854775807.0'::float4::int8::text
  261. ----
  262. 36854775808
  263. query RI rowsort
  264. SELECT x, x::int4 AS int4_value
  265. FROM (VALUES (-2.5::float4),
  266. (-1.5::float4),
  267. (-0.5::float4),
  268. (0.0::float4),
  269. (0.5::float4),
  270. (1.5::float4),
  271. (2.5::float4)) t(x);
  272. ----
  273. -2.5 -2
  274. -1.5 -2
  275. -0.5 0
  276. 0 0
  277. 0.5 0
  278. 1.5 2
  279. 2.5 2
  280. query RI rowsort
  281. SELECT x, x::int8 AS int8_value
  282. FROM (VALUES (-2.5::float4),
  283. (-1.5::float4),
  284. (-0.5::float4),
  285. (0.0::float4),
  286. (0.5::float4),
  287. (1.5::float4),
  288. (2.5::float4)) t(x);
  289. ----
  290. -2.5 -2
  291. -1.5 -2
  292. -0.5 0
  293. 0 0
  294. 0.5 0
  295. 1.5 2
  296. 2.5 2