| 1 |
#ifndef _melder_ftoa_h_ |
| 2 |
#define _melder_ftoa_h_ |
| 3 |
/* melder_ftoa.h |
| 4 |
* |
| 5 |
* Copyright (C) 1992-2019,2021,2024,2026 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 3 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 |
/* |
| 22 |
The following functions return a static string, chosen from a circularly used set of 32 buffers. |
| 23 |
You can call at most 32 of them in one Melder_casual call, for instance. |
| 24 |
*/ |
| 25 |
|
| 26 |
conststring32 Melder_integer (int64 value); |
| 27 |
conststring8 Melder8_integer (int64 value); |
| 28 |
|
| 29 |
conststring32 Melder_bigInteger (int64 value); |
| 30 |
conststring8 Melder8_bigInteger (int64 value); |
| 31 |
|
| 32 |
conststring32 Melder_boolean (bool value); |
| 33 |
conststring8 Melder8_boolean (bool value); |
| 34 |
// "yes" or "no" |
| 35 |
|
| 36 |
conststring32 Melder_onoff (bool value); |
| 37 |
conststring8 Melder8_onoff (bool value); |
| 38 |
|
| 39 |
conststring32 Melder_kleenean (kleenean value); |
| 40 |
conststring8 Melder8_kleenean (kleenean value); |
| 41 |
// "unknown" (< 0), "yes" (> 0), or "no" (0) |
| 42 |
|
| 43 |
/* |
| 44 |
Format a double value as "--undefined--" or something in the "%.15g", "%.16g", or "%.17g" formats. |
| 45 |
*/ |
| 46 |
conststring32 Melder_double (double value); |
| 47 |
conststring8 Melder8_double (double value); |
| 48 |
conststring32 Melder_double_overtlyReal (double value); |
| 49 |
conststring8 Melder8_double_overtlyReal (double value); |
| 50 |
|
| 51 |
/* |
| 52 |
Format a double value as "--undefined--" or something in the "%.9g" format. |
| 53 |
*/ |
| 54 |
conststring32 Melder_single (double value); |
| 55 |
conststring8 Melder8_single (double value); |
| 56 |
|
| 57 |
/* |
| 58 |
Format a double value as "--undefined--" or something in the "%.4g" format. |
| 59 |
*/ |
| 60 |
conststring32 Melder_half (double value); |
| 61 |
conststring8 Melder8_half (double value); |
| 62 |
|
| 63 |
/* |
| 64 |
Format a double value as "--undefined--" or something in the "%.*f" format. |
| 65 |
*/ |
| 66 |
conststring32 Melder_fixed (double value, integer precision); |
| 67 |
conststring8 Melder8_fixed (double value, integer precision); |
| 68 |
|
| 69 |
/* |
| 70 |
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. |
| 71 |
*/ |
| 72 |
conststring32 Melder_fixedExponent (double value, integer exponent, integer precision); |
| 73 |
conststring8 Melder8_fixedExponent (double value, integer exponent, integer precision); |
| 74 |
|
| 75 |
/* |
| 76 |
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%". |
| 77 |
*/ |
| 78 |
conststring32 Melder_percent (double value, integer precision); |
| 79 |
conststring8 Melder8_percent (double value, integer precision); |
| 80 |
|
| 81 |
/* |
| 82 |
Format an integer as a hexadecimal number. If precision is 4, you get things like "0000" or "1A3C" or "107FFFF". |
| 83 |
*/ |
| 84 |
conststring32 Melder_hexadecimal (integer value, integer precision); |
| 85 |
conststring8 Melder8_hexadecimal (integer value, integer precision); |
| 86 |
|
| 87 |
/* |
| 88 |
Format a dcomplex value as "--undefined--" or something in the "%.15g", "%.16g", or "%.17g" formats, |
| 89 |
separated without spaces by "+" or "-" and followed by "i". |
| 90 |
*/ |
| 91 |
conststring32 Melder_dcomplex (dcomplex value); |
| 92 |
conststring8 Melder8_dcomplex (dcomplex value); |
| 93 |
|
| 94 |
/* |
| 95 |
Format a dcomplex value as "--undefined--" or something in the "%.9g" format, |
| 96 |
separated without spaces by "+" or "-" and followed by "i". |
| 97 |
*/ |
| 98 |
conststring32 Melder_scomplex (dcomplex value); |
| 99 |
conststring8 Melder8_scomplex (dcomplex value); |
| 100 |
|
| 101 |
/* |
| 102 |
Format the number that is specified by its natural logarithm. |
| 103 |
For instance, -10000 is formatted as "1.135483865315339e-4343", which is a floating-point representation of exp(-10000). |
| 104 |
*/ |
| 105 |
conststring32 Melder_naturalLogarithm (double lnNumber); |
| 106 |
conststring8 Melder8_naturalLogarithm (double lnNumber); |
| 107 |
|
| 108 |
/* |
| 109 |
Convert a formatted floating-point string to something suitable for visualization with the Graphics library. |
| 110 |
For instance, "1e+4" is turned into "10^^4^", and "-1.23456e-78" is turned into "-1.23456\.c10^^-78^". |
| 111 |
*/ |
| 112 |
conststring32 Melder_graphicalHalf (double number); |
| 113 |
conststring8 Melder8_graphicalHalf (double number); |
| 114 |
conststring32 Melder_graphicalSingle (double number); |
| 115 |
conststring8 Melder8_graphicalSingle (double number); |
| 116 |
conststring32 Melder_graphicalDouble (double number); |
| 117 |
conststring8 Melder8_graphicalDouble (double number); |
| 118 |
conststring32 Melder_graphicalPercent (double number, integer precision); |
| 119 |
conststring8 Melder8_graphicalPercent (double number, integer precision); |
| 120 |
conststring32 Melder_graphicalNaturalLogarithm (double number); |
| 121 |
conststring8 Melder8_graphicalNaturalLogarithm (double number); |
| 122 |
|
| 123 |
conststring32 Melder_pointer (const void *pointer); |
| 124 |
conststring8 Melder8_pointer (const void *pointer); |
| 125 |
|
| 126 |
conststring32 Melder_character (char32 kar); |
| 127 |
conststring8 Melder8_character (char32 kar); |
| 128 |
|
| 129 |
conststring32 Melder_colour (MelderColour colour); |
| 130 |
conststring8 Melder8_colour (MelderColour colour); |
| 131 |
|
| 132 |
/* |
| 133 |
Append padding to the left of `string` until the result is at least as long as `width`. |
| 134 |
No truncation takes place, so the resulting string may be longer than `width`. |
| 135 |
The left edge of `pad` is left-aligned to the resulting string, |
| 136 |
so that the result will look good if padding is used for visualizing columns. |
| 137 |
*/ |
| 138 |
conststring32 Melder_padLeft (conststring32 string, integer width, conststring32 pad = U" "); |
| 139 |
|
| 140 |
/* |
| 141 |
Append padding to the right of `string` until the result is at least as long as `width`. |
| 142 |
No truncation takes place, so the resulting string may be longer than `width`. |
| 143 |
The right edge of `pad` is right-aligned to the resulting string, |
| 144 |
so that the result will look good if padding is used for visualizing columns. |
| 145 |
*/ |
| 146 |
conststring32 Melder_padRight (conststring32 string, integer width, conststring32 pad = U" "); |
| 147 |
|
| 148 |
/* |
| 149 |
Cut away the left of `string` until the result is at least as short as `width` (which must be non-negative). |
| 150 |
No padding takes place, so the resulting string may be shorter than `width`. |
| 151 |
*/ |
| 152 |
conststring32 Melder_truncateLeft (conststring32 string, integer width); |
| 153 |
|
| 154 |
/* |
| 155 |
Cut away the right of `string` until the result is at least as short as `width` (which must be non-negative). |
| 156 |
No padding takes place, so the resulting string may be shorter than `width`. |
| 157 |
*/ |
| 158 |
conststring32 Melder_truncateRight (conststring32 string, integer width); |
| 159 |
|
| 160 |
/* |
| 161 |
Cut away, or prepend padding to, the left of 'string' until the length of the result is 'width' (which must be non-negative). |
| 162 |
The resulting string will always have `width` characters. |
| 163 |
The left edge of `pad` is left-aligned to the resulting string, |
| 164 |
so that the result will look good if padding is used for visualizing columns. |
| 165 |
*/ |
| 166 |
conststring32 Melder_padOrTruncateLeft (conststring32 string, integer width, conststring32 pad = U" "); |
| 167 |
|
| 168 |
/* |
| 169 |
Cut away, or append padding to, the right of 'string' until the length of the result is 'width' (which must be non-negative). |
| 170 |
The resulting string will always have `width` characters. |
| 171 |
The right edge of `pad` is right-aligned to the resulting string, |
| 172 |
so that the result will look good if padding is used for visualizing columns. |
| 173 |
*/ |
| 174 |
conststring32 Melder_padOrTruncateRight (conststring32 string, integer width, conststring32 pad = U" "); |
| 175 |
|
| 176 |
/* End of file melder_ftoa.h */ |
| 177 |
#endif |