2
0

shortest_dec.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*---------------------------------------------------------------------------
  2. *
  3. * Ryu floating-point output.
  4. *
  5. * Portions Copyright (c) 2018-2022, PostgreSQL Global Development Group
  6. *
  7. * IDENTIFICATION
  8. * src/include/common/shortest_dec.h
  9. *
  10. * This is a modification of code taken from github.com/ulfjack/ryu under the
  11. * terms of the Boost license (not the Apache license). The original copyright
  12. * notice follows:
  13. *
  14. * Copyright 2018 Ulf Adams
  15. *
  16. * The contents of this file may be used under the terms of the Apache
  17. * License, Version 2.0.
  18. *
  19. * (See accompanying file LICENSE-Apache or copy at
  20. * http://www.apache.org/licenses/LICENSE-2.0)
  21. *
  22. * Alternatively, the contents of this file may be used under the terms of the
  23. * Boost Software License, Version 1.0.
  24. *
  25. * (See accompanying file LICENSE-Boost or copy at
  26. * https://www.boost.org/LICENSE_1_0.txt)
  27. *
  28. * Unless required by applicable law or agreed to in writing, this software is
  29. * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  30. * KIND, either express or implied.
  31. *
  32. *---------------------------------------------------------------------------
  33. */
  34. #ifndef SHORTEST_DEC_H
  35. #define SHORTEST_DEC_H
  36. /*----
  37. * The length of 25 comes from:
  38. *
  39. * Case 1: -9.9999999999999999e-299 = 24 bytes, plus 1 for null
  40. *
  41. * Case 2: -0.00099999999999999999 = 23 bytes, plus 1 for null
  42. */
  43. #define DOUBLE_SHORTEST_DECIMAL_LEN 25
  44. int double_to_shortest_decimal_bufn(double f, char *result);
  45. int double_to_shortest_decimal_buf(double f, char *result);
  46. char *double_to_shortest_decimal(double f);
  47. /*
  48. * The length of 16 comes from:
  49. *
  50. * Case 1: -9.99999999e+29 = 15 bytes, plus 1 for null
  51. *
  52. * Case 2: -0.000999999999 = 15 bytes, plus 1 for null
  53. */
  54. #define FLOAT_SHORTEST_DECIMAL_LEN 16
  55. int float_to_shortest_decimal_bufn(float f, char *result);
  56. int float_to_shortest_decimal_buf(float f, char *result);
  57. char *float_to_shortest_decimal(float f);
  58. #endif /* SHORTEST_DEC_H */