melder_ftoa.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. #ifndef _melder_ftoa_h_
  2. #define _melder_ftoa_h_
  3. /* melder_ftoa.h
  4. *
  5. * Copyright (C) 1992-2018 Paul Boersma
  6. *
  7. * This code is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or (at
  10. * your option) any later version.
  11. *
  12. * This code is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  15. * See the GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this work. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. /*
  21. The following functions return a static string, chosen from a circularly used set of 32 buffers.
  22. You can call at most 32 of them in one Melder_casual call, for instance.
  23. */
  24. conststring32 Melder_integer (int64 value) noexcept;
  25. conststring8 Melder8_integer (int64 value) noexcept;
  26. conststring32 Melder_bigInteger (int64 value) noexcept;
  27. conststring8 Melder8_bigInteger (int64 value) noexcept;
  28. conststring32 Melder_boolean (bool value) noexcept;
  29. conststring8 Melder8_boolean (bool value) noexcept;
  30. // "yes" or "no"
  31. /**
  32. Format a double value as "--undefined--" or something in the "%.15g", "%.16g", or "%.17g" formats.
  33. */
  34. conststring32 Melder_double (double value) noexcept;
  35. conststring8 Melder8_double (double value) noexcept;
  36. /**
  37. Format a double value as "--undefined--" or something in the "%.9g" format.
  38. */
  39. conststring32 Melder_single (double value) noexcept;
  40. conststring8 Melder8_single (double value) noexcept;
  41. /**
  42. Format a double value as "--undefined--" or something in the "%.4g" format.
  43. */
  44. conststring32 Melder_half (double value) noexcept;
  45. conststring8 Melder8_half (double value) noexcept;
  46. /**
  47. Format a double value as "--undefined--" or something in the "%.*f" format.
  48. */
  49. conststring32 Melder_fixed (double value, integer precision) noexcept;
  50. conststring8 Melder8_fixed (double value, integer precision) noexcept;
  51. /**
  52. Format a double value with a specified precision. If exponent is -2 and precision is 2, you get things like 67E-2 or 0.00024E-2.
  53. */
  54. conststring32 Melder_fixedExponent (double value, integer exponent, integer precision) noexcept;
  55. conststring8 Melder8_fixedExponent (double value, integer exponent, integer precision) noexcept;
  56. /**
  57. Format a double value as a percentage. If precision is 3, you get things like "0" or "34.400%" or "0.014%" or "0.001%" or "0.0000007%".
  58. */
  59. conststring32 Melder_percent (double value, integer precision) noexcept;
  60. conststring8 Melder8_percent (double value, integer precision) noexcept;
  61. /**
  62. Format an integer as a hexadecimal number. If precision is 4, you get things like "0000" or "1A3C" or "107FFFF".
  63. */
  64. conststring8 Melder8_hexadecimal (integer value, integer precision) noexcept;
  65. conststring32 Melder_hexadecimal (integer value, integer precision) noexcept;
  66. /**
  67. Format a dcomplex value as "--undefined--" or something in the "%.15g", "%.16g", or "%.17g" formats,
  68. separated without spaces by "+" or "-" and followed by "i".
  69. */
  70. conststring32 Melder_dcomplex (dcomplex value) noexcept;
  71. conststring8 Melder8_dcomplex (dcomplex value) noexcept;
  72. /**
  73. Format a dcomplex value as "--undefined--" or something in the "%.9g" format,
  74. separated without spaces by "+" or "-" and followed by "i".
  75. */
  76. conststring32 Melder_scomplex (dcomplex value) noexcept;
  77. conststring8 Melder8_scomplex (dcomplex value) noexcept;
  78. /**
  79. Convert a formatted floating-point string to something suitable for visualization with the Graphics library.
  80. For instance, "1e+4" is turned into "10^^4", and "-1.23456e-78" is turned into "-1.23456\.c10^^-78".
  81. */
  82. conststring32 Melder_float (conststring32 number) noexcept;
  83. /**
  84. Format the number that is specified by its natural logarithm.
  85. For instance, -10000 is formatted as "1.135483865315339e-4343", which is a floating-point representation of exp(-10000).
  86. */
  87. conststring32 Melder_naturalLogarithm (double lnNumber) noexcept;
  88. conststring8 Melder8_naturalLogarithm (double lnNumber) noexcept;
  89. conststring32 Melder_pointer (void *pointer) noexcept;
  90. conststring8 Melder8_pointer (void *pointer) noexcept;
  91. conststring32 Melder_character (char32 kar) noexcept;
  92. conststring8 Melder8_character (char32 kar) noexcept;
  93. conststring32 Melder_pad (int64 width, conststring32 string); // will append spaces to the left of 'string' until 'width' is reached; no truncation
  94. conststring32 Melder_pad (conststring32 string, int64 width); // will append spaces to the right of 'string' until 'width' is reached; no truncation
  95. conststring32 Melder_truncate (int64 width, conststring32 string); // will cut away the left of 'string' until 'width' is reached; no padding
  96. conststring32 Melder_truncate (conststring32 string, int64 width); // will cut away the right of 'string' until 'width' is reached; no padding
  97. conststring32 Melder_padOrTruncate (int64 width, conststring32 string); // will cut away, or append spaces to, the left of 'string' until 'width' is reached
  98. conststring32 Melder_padOrTruncate (conststring32 string, int64 width); // will cut away, or append spaces to, the right of 'string' until 'width' is reached
  99. /* End of file melder_ftoa.h */
  100. #endif