decimal-zero.td 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. #
  10. # This test checks that the various decimal representations of zero and numbers very close to zero behave as expected
  11. #
  12. > CREATE TABLE decimal_zero (f1 DECIMAL);
  13. > INSERT INTO decimal_zero VALUES (0), (-0), ('0.0'::decimal), ('00000000000000000.0'::decimal), ('-0.000000000000000000000'::decimal);
  14. > SELECT DISTINCT f1, f1::decimal(5,2)::text FROM decimal_zero;
  15. 0 0.00
  16. > SELECT MIN(f1)::text, MAX(f1)::text FROM decimal_zero;
  17. 0 0
  18. > SELECT COUNT(DISTINCT f1)::text, SUM(DISTINCT f1)::text FROM decimal_zero;
  19. 1 0
  20. > SELECT f1::text FROM decimal_zero ORDER BY f1;
  21. 0
  22. 0
  23. 0
  24. 0
  25. 0
  26. > SELECT COUNT(*) FROM decimal_zero AS a1, decimal_zero AS a2 WHERE a1.f1 = a2.f1;
  27. 25
  28. ! SELECT 123 / '-0'::decimal;
  29. contains:division by zero
  30. > SELECT '0.000000000000000000000000000000000000001'::decimal - '0.000000000000000000000000000000000000001'::decimal = 0;
  31. true
  32. > SELECT '-0.000000000000000000000000000000000000001'::decimal + '0.000000000000000000000000000000000000001'::decimal = 0;
  33. true
  34. > SELECT '0.000000000000000000000000000000000000001'::decimal + '-0.000000000000000000000000000000000000001'::decimal = 0;
  35. true
  36. > SELECT '1'::decimal - '1'::decimal UNION DISTINCT SELECT '1.1'::decimal - '1.10'::decimal;
  37. 0
  38. ! SELECT '0.000000000000000000000000000000000000001'::decimal * '-0.000000000000000000000000000000000000001'::decimal;
  39. contains:value out of range: underflow
  40. ! SELECT '0.1'::decimal / 999999999999999999999999999999999999999::decimal;
  41. contains:value out of range: underflow