Decimal.d.hpp (11755B)
1 #ifndef icu4x_Decimal_D_HPP 2 #define icu4x_Decimal_D_HPP 3 4 #include <stdio.h> 5 #include <stdint.h> 6 #include <stddef.h> 7 #include <stdbool.h> 8 #include <memory> 9 #include <functional> 10 #include <optional> 11 #include <cstdlib> 12 #include "../diplomat_runtime.hpp" 13 14 namespace icu4x { 15 namespace capi { struct Decimal; } 16 class Decimal; 17 struct DecimalLimitError; 18 class DecimalParseError; 19 class DecimalRoundingIncrement; 20 class DecimalSign; 21 class DecimalSignDisplay; 22 class DecimalSignedRoundingMode; 23 } 24 25 26 namespace icu4x { 27 namespace capi { 28 struct Decimal; 29 } // namespace capi 30 } // namespace 31 32 namespace icu4x { 33 /** 34 * See the [Rust documentation for `Decimal`](https://docs.rs/fixed_decimal/latest/fixed_decimal/type.Decimal.html) for more information. 35 */ 36 class Decimal { 37 public: 38 39 /** 40 * Construct an [`Decimal`] from an integer. 41 * 42 * See the [Rust documentation for `Decimal`](https://docs.rs/fixed_decimal/latest/fixed_decimal/struct.Decimal.html) for more information. 43 */ 44 inline static std::unique_ptr<icu4x::Decimal> from(int32_t v); 45 46 /** 47 * Construct an [`Decimal`] from an integer. 48 * 49 * See the [Rust documentation for `Decimal`](https://docs.rs/fixed_decimal/latest/fixed_decimal/struct.Decimal.html) for more information. 50 */ 51 inline static std::unique_ptr<icu4x::Decimal> from(uint32_t v); 52 53 /** 54 * Construct an [`Decimal`] from an integer. 55 * 56 * See the [Rust documentation for `Decimal`](https://docs.rs/fixed_decimal/latest/fixed_decimal/struct.Decimal.html) for more information. 57 */ 58 inline static std::unique_ptr<icu4x::Decimal> from(int64_t v); 59 60 /** 61 * Construct an [`Decimal`] from an integer. 62 * 63 * See the [Rust documentation for `Decimal`](https://docs.rs/fixed_decimal/latest/fixed_decimal/struct.Decimal.html) for more information. 64 */ 65 inline static std::unique_ptr<icu4x::Decimal> from(uint64_t v); 66 67 /** 68 * Construct an [`Decimal`] from an integer-valued float 69 * 70 * See the [Rust documentation for `try_from_f64`](https://docs.rs/fixed_decimal/latest/fixed_decimal/type.Decimal.html#method.try_from_f64) for more information. 71 * 72 * See the [Rust documentation for `FloatPrecision`](https://docs.rs/fixed_decimal/latest/fixed_decimal/enum.FloatPrecision.html) for more information. 73 */ 74 inline static diplomat::result<std::unique_ptr<icu4x::Decimal>, icu4x::DecimalLimitError> from_double_with_integer_precision(double f); 75 76 /** 77 * Construct an [`Decimal`] from an float, with a given power of 10 for the lower magnitude 78 * 79 * See the [Rust documentation for `try_from_f64`](https://docs.rs/fixed_decimal/latest/fixed_decimal/type.Decimal.html#method.try_from_f64) for more information. 80 * 81 * See the [Rust documentation for `FloatPrecision`](https://docs.rs/fixed_decimal/latest/fixed_decimal/enum.FloatPrecision.html) for more information. 82 */ 83 inline static diplomat::result<std::unique_ptr<icu4x::Decimal>, icu4x::DecimalLimitError> from_double_with_lower_magnitude(double f, int16_t magnitude); 84 85 /** 86 * Construct an [`Decimal`] from an float, for a given number of significant digits 87 * 88 * See the [Rust documentation for `try_from_f64`](https://docs.rs/fixed_decimal/latest/fixed_decimal/type.Decimal.html#method.try_from_f64) for more information. 89 * 90 * See the [Rust documentation for `FloatPrecision`](https://docs.rs/fixed_decimal/latest/fixed_decimal/enum.FloatPrecision.html) for more information. 91 */ 92 inline static diplomat::result<std::unique_ptr<icu4x::Decimal>, icu4x::DecimalLimitError> from_double_with_significant_digits(double f, uint8_t digits); 93 94 /** 95 * Construct an [`Decimal`] from an float, with enough digits to recover 96 * the original floating point in IEEE 754 without needing trailing zeros 97 * 98 * See the [Rust documentation for `try_from_f64`](https://docs.rs/fixed_decimal/latest/fixed_decimal/type.Decimal.html#method.try_from_f64) for more information. 99 * 100 * See the [Rust documentation for `FloatPrecision`](https://docs.rs/fixed_decimal/latest/fixed_decimal/enum.FloatPrecision.html) for more information. 101 */ 102 inline static diplomat::result<std::unique_ptr<icu4x::Decimal>, icu4x::DecimalLimitError> from_double_with_round_trip_precision(double f); 103 104 /** 105 * Construct an [`Decimal`] from a string. 106 * 107 * See the [Rust documentation for `try_from_str`](https://docs.rs/fixed_decimal/latest/fixed_decimal/type.Decimal.html#method.try_from_str) for more information. 108 */ 109 inline static diplomat::result<std::unique_ptr<icu4x::Decimal>, icu4x::DecimalParseError> from_string(std::string_view v); 110 111 /** 112 * See the [Rust documentation for `digit_at`](https://docs.rs/fixed_decimal/latest/fixed_decimal/type.Decimal.html#method.digit_at) for more information. 113 */ 114 inline uint8_t digit_at(int16_t magnitude) const; 115 116 /** 117 * See the [Rust documentation for `magnitude_range`](https://docs.rs/fixed_decimal/latest/fixed_decimal/type.Decimal.html#method.magnitude_range) for more information. 118 */ 119 inline int16_t magnitude_start() const; 120 121 /** 122 * See the [Rust documentation for `magnitude_range`](https://docs.rs/fixed_decimal/latest/fixed_decimal/type.Decimal.html#method.magnitude_range) for more information. 123 */ 124 inline int16_t magnitude_end() const; 125 126 /** 127 * See the [Rust documentation for `nonzero_magnitude_start`](https://docs.rs/fixed_decimal/latest/fixed_decimal/type.Decimal.html#method.nonzero_magnitude_start) for more information. 128 */ 129 inline int16_t nonzero_magnitude_start() const; 130 131 /** 132 * See the [Rust documentation for `nonzero_magnitude_end`](https://docs.rs/fixed_decimal/latest/fixed_decimal/type.Decimal.html#method.nonzero_magnitude_end) for more information. 133 */ 134 inline int16_t nonzero_magnitude_end() const; 135 136 /** 137 * See the [Rust documentation for `is_zero`](https://docs.rs/fixed_decimal/latest/fixed_decimal/type.Decimal.html#method.is_zero) for more information. 138 */ 139 inline bool is_zero() const; 140 141 /** 142 * Multiply the [`Decimal`] by a given power of ten. 143 * 144 * See the [Rust documentation for `multiply_pow10`](https://docs.rs/fixed_decimal/latest/fixed_decimal/type.Decimal.html#method.multiply_pow10) for more information. 145 */ 146 inline void multiply_pow10(int16_t power); 147 148 /** 149 * See the [Rust documentation for `sign`](https://docs.rs/fixed_decimal/latest/fixed_decimal/type.Decimal.html#method.sign) for more information. 150 */ 151 inline icu4x::DecimalSign sign() const; 152 153 /** 154 * Set the sign of the [`Decimal`]. 155 * 156 * See the [Rust documentation for `set_sign`](https://docs.rs/fixed_decimal/latest/fixed_decimal/type.Decimal.html#method.set_sign) for more information. 157 */ 158 inline void set_sign(icu4x::DecimalSign sign); 159 160 /** 161 * See the [Rust documentation for `apply_sign_display`](https://docs.rs/fixed_decimal/latest/fixed_decimal/type.Decimal.html#method.apply_sign_display) for more information. 162 */ 163 inline void apply_sign_display(icu4x::DecimalSignDisplay sign_display); 164 165 /** 166 * See the [Rust documentation for `trim_start`](https://docs.rs/fixed_decimal/latest/fixed_decimal/type.Decimal.html#method.trim_start) for more information. 167 */ 168 inline void trim_start(); 169 170 /** 171 * See the [Rust documentation for `trim_end`](https://docs.rs/fixed_decimal/latest/fixed_decimal/type.Decimal.html#method.trim_end) for more information. 172 */ 173 inline void trim_end(); 174 175 /** 176 * See the [Rust documentation for `trim_end_if_integer`](https://docs.rs/fixed_decimal/latest/fixed_decimal/type.Decimal.html#method.trim_end_if_integer) for more information. 177 */ 178 inline void trim_end_if_integer(); 179 180 /** 181 * Zero-pad the [`Decimal`] on the left to a particular position 182 * 183 * See the [Rust documentation for `pad_start`](https://docs.rs/fixed_decimal/latest/fixed_decimal/type.Decimal.html#method.pad_start) for more information. 184 */ 185 inline void pad_start(int16_t position); 186 187 /** 188 * Zero-pad the [`Decimal`] on the right to a particular position 189 * 190 * See the [Rust documentation for `pad_end`](https://docs.rs/fixed_decimal/latest/fixed_decimal/type.Decimal.html#method.pad_end) for more information. 191 */ 192 inline void pad_end(int16_t position); 193 194 /** 195 * Truncate the [`Decimal`] on the left to a particular position, deleting digits if necessary. This is useful for, e.g. abbreviating years 196 * ("2022" -> "22") 197 * 198 * See the [Rust documentation for `set_max_position`](https://docs.rs/fixed_decimal/latest/fixed_decimal/type.Decimal.html#method.set_max_position) for more information. 199 */ 200 inline void set_max_position(int16_t position); 201 202 /** 203 * Round the number at a particular digit position. 204 * 205 * This uses half to even rounding, which resolves ties by selecting the nearest 206 * even integer to the original value. 207 * 208 * See the [Rust documentation for `round`](https://docs.rs/fixed_decimal/latest/fixed_decimal/type.Decimal.html#method.round) for more information. 209 */ 210 inline void round(int16_t position); 211 212 /** 213 * See the [Rust documentation for `ceil`](https://docs.rs/fixed_decimal/latest/fixed_decimal/type.Decimal.html#method.ceil) for more information. 214 */ 215 inline void ceil(int16_t position); 216 217 /** 218 * See the [Rust documentation for `expand`](https://docs.rs/fixed_decimal/latest/fixed_decimal/type.Decimal.html#method.expand) for more information. 219 */ 220 inline void expand(int16_t position); 221 222 /** 223 * See the [Rust documentation for `floor`](https://docs.rs/fixed_decimal/latest/fixed_decimal/type.Decimal.html#method.floor) for more information. 224 */ 225 inline void floor(int16_t position); 226 227 /** 228 * See the [Rust documentation for `trunc`](https://docs.rs/fixed_decimal/latest/fixed_decimal/type.Decimal.html#method.trunc) for more information. 229 */ 230 inline void trunc(int16_t position); 231 232 /** 233 * See the [Rust documentation for `round_with_mode`](https://docs.rs/fixed_decimal/latest/fixed_decimal/type.Decimal.html#method.round_with_mode) for more information. 234 */ 235 inline void round_with_mode(int16_t position, icu4x::DecimalSignedRoundingMode mode); 236 237 /** 238 * See the [Rust documentation for `round_with_mode_and_increment`](https://docs.rs/fixed_decimal/latest/fixed_decimal/type.Decimal.html#method.round_with_mode_and_increment) for more information. 239 */ 240 inline void round_with_mode_and_increment(int16_t position, icu4x::DecimalSignedRoundingMode mode, icu4x::DecimalRoundingIncrement increment); 241 242 /** 243 * Concatenates `other` to the end of `self`. 244 * 245 * If successful, `other` will be set to 0 and a successful status is returned. 246 * 247 * If not successful, `other` will be unchanged and an error is returned. 248 * 249 * See the [Rust documentation for `concatenate_end`](https://docs.rs/fixed_decimal/latest/fixed_decimal/type.Decimal.html#method.concatenate_end) for more information. 250 */ 251 inline diplomat::result<std::monostate, std::monostate> concatenate_end(icu4x::Decimal& other); 252 253 /** 254 * Format the [`Decimal`] as a string. 255 * 256 * See the [Rust documentation for `write_to`](https://docs.rs/fixed_decimal/latest/fixed_decimal/type.Decimal.html#method.write_to) for more information. 257 */ 258 inline std::string to_string() const; 259 260 inline const icu4x::capi::Decimal* AsFFI() const; 261 inline icu4x::capi::Decimal* AsFFI(); 262 inline static const icu4x::Decimal* FromFFI(const icu4x::capi::Decimal* ptr); 263 inline static icu4x::Decimal* FromFFI(icu4x::capi::Decimal* ptr); 264 inline static void operator delete(void* ptr); 265 private: 266 Decimal() = delete; 267 Decimal(const icu4x::Decimal&) = delete; 268 Decimal(icu4x::Decimal&&) noexcept = delete; 269 Decimal operator=(const icu4x::Decimal&) = delete; 270 Decimal operator=(icu4x::Decimal&&) noexcept = delete; 271 static void operator delete[](void*, size_t) = delete; 272 }; 273 274 } // namespace 275 #endif // icu4x_Decimal_D_HPP