float.slt 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. # Copyright Materialize, Inc. and contributors. All rights reserved.
  2. #
  3. # Use of this software is governed by the Business Source License
  4. # included in the LICENSE file at the root of this repository.
  5. #
  6. # As of the Change Date specified in that file, in accordance with
  7. # the Business Source License, use of this software will be governed
  8. # by the Apache License, Version 2.0.
  9. mode cockroach
  10. query T
  11. SELECT '-0'::float::text
  12. ----
  13. -0
  14. query T
  15. SELECT '+0'::float::text
  16. ----
  17. 0
  18. query T
  19. SELECT '000000.00000'::float::text
  20. ----
  21. 0
  22. query T
  23. SELECT '0.0e10'::float::text
  24. ----
  25. 0
  26. query T
  27. SELECT '0.'::float::text
  28. ----
  29. 0
  30. query T
  31. SELECT '.0'::float::text
  32. ----
  33. 0
  34. query T
  35. SELECT '-.0'::float::text
  36. ----
  37. -0
  38. query T
  39. SELECT '+.0'::float::text
  40. ----
  41. 0
  42. query T
  43. SELECT '+0.'::float::text
  44. ----
  45. 0
  46. query T
  47. SELECT '-0.'::float::text
  48. ----
  49. -0
  50. query error invalid input syntax
  51. SELECT '++0'::float::text
  52. query error invalid input syntax
  53. SELECT '--0'::float::text
  54. query TTTTT
  55. SELECT 'Inf'::float::text, 'Infinity'::float::text, 'inFinIty'::float::text, '+inf'::float::text, '+infinity'::float::text
  56. ----
  57. Infinity Infinity Infinity Infinity Infinity
  58. query TTT
  59. SELECT '-Inf'::float::text, '-Infinity'::float::text, '-inFinIty'::float::text
  60. ----
  61. -Infinity -Infinity -Infinity
  62. query TTT
  63. SELECT 'NaN'::float::text, 'nan'::float::text, 'nAN'::float::text
  64. ----
  65. NaN NaN NaN
  66. query TTTTT
  67. SELECT 'Inf'::double precision::text, 'Infinity'::double precision::text, 'inFinIty'::double precision::text, '+inf'::double precision::text, '+infinity'::double precision::text
  68. ----
  69. Infinity Infinity Infinity Infinity Infinity
  70. query TTT
  71. SELECT '-Inf'::double precision::text, '-Infinity'::double precision::text, '-inFinIty'::double precision::text
  72. ----
  73. -Infinity -Infinity -Infinity
  74. query TTT
  75. SELECT 'NaN'::double precision::text, 'nan'::double precision::text, 'nAN'::double precision::text
  76. ----
  77. NaN NaN NaN
  78. query R
  79. SELECT 1.2::float8::float4
  80. ----
  81. 1.2
  82. query R
  83. SELECT '2e40'::float8
  84. ----
  85. 20000000000000000000000000000000000000000
  86. query error value out of range: overflow
  87. SELECT '2e40'::float8::float4
  88. query R
  89. SELECT '2147483583'::float4::int;
  90. ----
  91. 2147483520
  92. query error "2147483600" integer out of range
  93. SELECT '2147483648'::float4::int
  94. query R
  95. SELECT '-2147483648'::float4::int
  96. ----
  97. -2147483648
  98. query error "-2147484000" integer out of range
  99. SELECT '-2147483777'::float4::int;
  100. # Invalid type mods
  101. query error precision for type float must be within \(\[1-53\]\)
  102. SELECT 1::float(0);
  103. query error precision for type float must be within \(\[1-53\]\)
  104. SELECT 1::float(55);
  105. # Test SUM() with floats
  106. statement ok
  107. create table t1 (f1 double, f2 double)
  108. statement ok
  109. insert into t1 values (1e31, 1e31), (1e31, 1e31)
  110. query T
  111. SELECT f1+f2 FROM t1
  112. ----
  113. 19999999999999999271792589930496.000
  114. 19999999999999999271792589930496.000
  115. query T
  116. SELECT SUM(f1) FROM t1
  117. ----
  118. -282409603651671152154661355520.000
  119. # This *should* be zero, known issue https://github.com/MaterializeInc/database-issues/issues/4341
  120. query T
  121. SELECT MIN(f1+f2)-SUM(f1) FROM t1
  122. ----
  123. 20282409603651670423947251286016.000
  124. query error invalid input syntax
  125. SELECT ''::float::text
  126. query error invalid input syntax
  127. SELECT 'e'::float::text
  128. query error invalid input syntax
  129. SELECT 'e10'::float::text