lexical_util/
not_feature_format.rs

1//! Bare bones implementation of the format packed struct without feature
2//! [`format`][crate#features].
3//!
4//! See `feature_format` for detailed documentation.
5
6#![cfg(not(feature = "format"))]
7
8use crate::error::Error;
9use crate::format_builder::NumberFormatBuilder;
10use crate::format_flags as flags;
11
12/// Helper to access features from the packed format struct.
13///
14/// Some of the core functionality includes support for:
15/// - Digit separators: ignored characters used to make numbers more readable,
16///   such as `100,000`.
17/// - Non-decimal radixes: writing or parsing numbers written in binary,
18///   hexadecimal, or other bases.
19/// - Special numbers: disabling support for special floating-point, such as
20///   [`NaN`][f64::NAN].
21/// - Number components: require signs, significant digits, and more.
22///
23/// The following values are explicitly set, and therefore not configurable:
24///
25/// 1. [`required_integer_digits`][NumberFormat::required_integer_digits]
26/// 2. [`required_fraction_digits`][NumberFormat::required_fraction_digits]
27/// 3. [`required_exponent_digits`][NumberFormat::required_exponent_digits]
28/// 4. [`required_mantissa_digits`][NumberFormat::required_mantissa_digits]
29/// 5. [`required_digits`][NumberFormat::required_digits]
30/// 6. [`no_positive_mantissa_sign`][NumberFormat::no_positive_mantissa_sign]
31/// 7. [`required_mantissa_sign`][NumberFormat::required_mantissa_sign]
32/// 8. [`no_exponent_notation`][NumberFormat::no_exponent_notation]
33/// 9. [`no_positive_exponent_sign`][NumberFormat::no_positive_exponent_sign]
34/// 10. [`required_exponent_sign`][NumberFormat::required_exponent_sign]
35/// 11. [`no_exponent_without_fraction`][NumberFormat::no_exponent_without_fraction]
36/// 12. [`no_special`][NumberFormat::no_special]
37/// 13. [`case_sensitive_special`][NumberFormat::case_sensitive_special]
38/// 14. [`no_integer_leading_zeros`][NumberFormat::no_integer_leading_zeros]
39/// 15. [`no_float_leading_zeros`][NumberFormat::no_float_leading_zeros]
40/// 16. [`required_exponent_notation`][NumberFormat::required_exponent_notation]
41/// 17. [`case_sensitive_exponent`][NumberFormat::case_sensitive_exponent]
42/// 18. [`case_sensitive_base_prefix`][NumberFormat::case_sensitive_base_prefix]
43/// 19. [`case_sensitive_base_suffix`][NumberFormat::case_sensitive_base_suffix]
44/// 20. [`integer_internal_digit_separator`][NumberFormat::integer_internal_digit_separator]
45/// 21. [`fraction_internal_digit_separator`][NumberFormat::fraction_internal_digit_separator]
46/// 22. [`exponent_internal_digit_separator`][NumberFormat::exponent_internal_digit_separator]
47/// 23. [`internal_digit_separator`][NumberFormat::internal_digit_separator]
48/// 24. [`integer_leading_digit_separator`][NumberFormat::integer_leading_digit_separator]
49/// 25. [`fraction_leading_digit_separator`][NumberFormat::fraction_leading_digit_separator]
50/// 26. [`exponent_leading_digit_separator`][NumberFormat::exponent_leading_digit_separator]
51/// 27. [`leading_digit_separator`][NumberFormat::leading_digit_separator]
52/// 28. [`integer_trailing_digit_separator`][NumberFormat::integer_trailing_digit_separator]
53/// 29. [`fraction_trailing_digit_separator`][NumberFormat::fraction_trailing_digit_separator]
54/// 30. [`exponent_trailing_digit_separator`][NumberFormat::exponent_trailing_digit_separator]
55/// 31. [`trailing_digit_separator`][NumberFormat::trailing_digit_separator]
56/// 32. [`integer_consecutive_digit_separator`][NumberFormat::integer_consecutive_digit_separator]
57/// 33. [`fraction_consecutive_digit_separator`][NumberFormat::fraction_consecutive_digit_separator]
58/// 34. [`exponent_consecutive_digit_separator`][NumberFormat::exponent_consecutive_digit_separator]
59/// 35. [`consecutive_digit_separator`][NumberFormat::consecutive_digit_separator]
60/// 36. [`special_digit_separator`][NumberFormat::special_digit_separator]
61/// 37. [`digit_separator`][NumberFormat::digit_separator]
62/// 38. [`base_prefix`][NumberFormat::base_prefix]
63/// 39. [`base_suffix`][NumberFormat::base_suffix]
64/// 40. [`exponent_base`][NumberFormat::exponent_base]
65/// 41. [`exponent_radix`][NumberFormat::exponent_radix]
66///
67/// This should always be constructed via [`NumberFormatBuilder`].
68/// See [`NumberFormatBuilder`] for the fields for the packed struct.
69pub struct NumberFormat<const FORMAT: u128>;
70
71impl<const FORMAT: u128> NumberFormat<FORMAT> {
72    // CONSTRUCTORS
73
74    /// Create new instance (for methods and validation).
75    ///
76    /// This uses the same settings as in the `FORMAT` packed struct.
77    #[inline(always)]
78    pub const fn new() -> Self {
79        Self {}
80    }
81
82    // VALIDATION
83
84    /// Determine if the number format is valid.
85    #[inline(always)]
86    pub const fn is_valid(&self) -> bool {
87        self.error().is_success()
88    }
89
90    /// Get the error type from the format.
91    #[inline(always)]
92    pub const fn error(&self) -> Error {
93        format_error_impl(FORMAT)
94    }
95
96    /// Determine if the radixes in the number format are valid.
97    #[inline(always)]
98    pub const fn is_valid_radix(&self) -> bool {
99        self.error_radix().is_success()
100    }
101
102    /// Get the error type from the radix-only for the format.
103    ///
104    /// If [`Error::Success`] is returned, then no error occurred.
105    #[inline(always)]
106    pub const fn error_radix(&self) -> Error {
107        radix_error_impl(FORMAT)
108    }
109
110    // NON-DIGIT SEPARATOR FLAGS & MASKS
111
112    /// If digits are required before the decimal point.
113    ///
114    /// See [`required_integer_digits`][Self::required_integer_digits].
115    pub const REQUIRED_INTEGER_DIGITS: bool = false;
116
117    /// Get if digits are required before the decimal point.
118    ///
119    /// Can only be modified with [`feature`][crate#features] `format`. Defaults
120    /// to [`false`].
121    ///
122    /// # Examples
123    ///
124    /// | Input | Valid? |
125    /// |:-:|:-:|
126    /// | `1.1` | ✔️ |
127    /// | `0.1` | ✔️ |
128    /// | `1` | ✔️ |
129    /// | `.1` | ❌ |
130    ///
131    /// # Used For
132    ///
133    /// - Parse Float
134    #[inline(always)]
135    pub const fn required_integer_digits(&self) -> bool {
136        Self::REQUIRED_INTEGER_DIGITS
137    }
138
139    /// If digits are required after the decimal point.
140    ///
141    /// See [`required_fraction_digits`][Self::required_fraction_digits].
142    pub const REQUIRED_FRACTION_DIGITS: bool = false;
143
144    /// Get if digits are required after the decimal point.
145    ///
146    /// Can only be modified with [`feature`][crate#features] `format`. Defaults
147    /// to [`false`].
148    ///
149    /// # Examples
150    ///
151    /// | Input | Valid? |
152    /// |:-:|:-:|
153    /// | `1.1` | ✔️ |
154    /// | `1` | ✔️ |
155    /// | `1.` | ❌ |
156    ///
157    /// # Used For
158    ///
159    /// - Parse Float
160    #[inline(always)]
161    pub const fn required_fraction_digits(&self) -> bool {
162        Self::REQUIRED_FRACTION_DIGITS
163    }
164
165    /// If digits are required after the exponent character.
166    ///
167    /// See [`required_exponent_digits`][Self::required_exponent_digits].
168    pub const REQUIRED_EXPONENT_DIGITS: bool = true;
169
170    /// Get if digits are required after the exponent character.
171    ///
172    /// Can only be modified with [`feature`][crate#features] `format`. Defaults
173    /// to [`true`].
174    ///
175    /// # Examples
176    ///
177    /// | Input | Valid? |
178    /// |:-:|:-:|
179    /// | `1.1e+3` | ✔️ |
180    /// | `1.1e3` | ✔️ |
181    /// | `1.1e+` | ❌ |
182    /// | `1.1e` | ❌ |
183    ///
184    /// # Used For
185    ///
186    /// - Parse Float
187    #[inline(always)]
188    pub const fn required_exponent_digits(&self) -> bool {
189        Self::REQUIRED_EXPONENT_DIGITS
190    }
191
192    /// If significant digits are required.
193    ///
194    /// See [`required_mantissa_digits`][Self::required_mantissa_digits].
195    pub const REQUIRED_MANTISSA_DIGITS: bool = true;
196
197    /// Get if at least 1 significant digit is required.
198    ///
199    /// If not required, then values like `.` (`0`) are valid, but empty strings
200    /// are still invalid. Can only be modified with [`feature`][crate#features]
201    /// `format`. Defaults to [`true`].
202    ///
203    /// # Examples
204    ///
205    /// | Input | Valid? |
206    /// |:-:|:-:|
207    /// | `1.1` | ✔️ |
208    /// | `.` | ✔️ |
209    /// | `e10` | ✔️ |
210    /// | `.e10` | ✔️ |
211    /// | `` | ❌ |
212    ///
213    /// # Used For
214    ///
215    /// - Parse Float
216    #[inline(always)]
217    pub const fn required_mantissa_digits(&self) -> bool {
218        Self::REQUIRED_MANTISSA_DIGITS
219    }
220
221    /// If at least 1 digit in the number is required.
222    ///
223    /// See [`required_digits`][Self::required_digits].
224    pub const REQUIRED_DIGITS: bool = true;
225
226    /// Get if at least 1 digit in the number is required.
227    ///
228    /// This requires either [`mantissa`] or [`exponent`] digits.
229    ///
230    /// [`mantissa`]: Self::required_mantissa_digits
231    /// [`exponent`]: Self::required_exponent_digits
232    #[inline(always)]
233    pub const fn required_digits(&self) -> bool {
234        Self::REQUIRED_DIGITS
235    }
236
237    /// If a positive sign before the mantissa is not allowed.
238    ///
239    /// See [`no_positive_mantissa_sign`][Self::no_positive_mantissa_sign].
240    pub const NO_POSITIVE_MANTISSA_SIGN: bool = false;
241
242    /// Get if a positive sign before the mantissa is not allowed.
243    ///
244    /// Can only be modified with [`feature`][crate#features] `format`. Defaults
245    /// to `false`.
246    ///
247    /// # Examples
248    ///
249    /// | Input | Valid? |
250    /// |:-:|:-:|
251    /// | `1.1` | ✔️ |
252    /// | `-1.1` | ✔️ |
253    /// | `+1.1` | ❌ |
254    ///
255    /// # Used For
256    ///
257    /// - Parse Float
258    /// - Parse Integer
259    /// - Write Float
260    #[inline(always)]
261    pub const fn no_positive_mantissa_sign(&self) -> bool {
262        Self::NO_POSITIVE_MANTISSA_SIGN
263    }
264
265    /// If a sign symbol before the mantissa is required.
266    ///
267    /// See [`required_mantissa_sign`][Self::required_mantissa_sign].
268    pub const REQUIRED_MANTISSA_SIGN: bool = false;
269
270    /// Get if a sign symbol before the mantissa is required.
271    ///
272    /// Can only be modified with [`feature`][crate#features] `format`. Defaults
273    /// to `false`.
274    ///
275    /// # Examples
276    ///
277    /// | Input | Valid? |
278    /// |:-:|:-:|
279    /// | `1.1` | ❌ |
280    /// | `-1.1` | ✔️ |
281    /// | `+1.1` | ✔️ |
282    ///
283    /// # Used For
284    ///
285    /// - Parse Float
286    /// - Parse Integer
287    /// - Write Float
288    #[inline(always)]
289    pub const fn required_mantissa_sign(&self) -> bool {
290        Self::REQUIRED_MANTISSA_SIGN
291    }
292
293    /// If exponent notation is not allowed.
294    ///
295    /// See [`no_exponent_notation`][Self::no_exponent_notation].
296    pub const NO_EXPONENT_NOTATION: bool = false;
297
298    /// Get if exponent notation is not allowed.
299    ///
300    /// Can only be modified with [`feature`][crate#features] `format`. Defaults
301    /// to `false`.
302    ///
303    /// # Examples
304    ///
305    /// | Input | Valid? |
306    /// |:-:|:-:|
307    /// | `1` | ✔️ |
308    /// | `1.1` | ✔️ |
309    /// | `1.1e` | ❌ |
310    /// | `1.1e5` | ❌ |
311    ///
312    /// # Used For
313    ///
314    /// - Parse Float
315    /// - Write Float
316    #[inline(always)]
317    pub const fn no_exponent_notation(&self) -> bool {
318        Self::NO_EXPONENT_NOTATION
319    }
320
321    /// If a positive sign before the exponent is not allowed.
322    ///
323    /// See [`no_positive_exponent_sign`][Self::no_positive_exponent_sign].
324    pub const NO_POSITIVE_EXPONENT_SIGN: bool = false;
325
326    /// Get if a positive sign before the exponent is not allowed.
327    ///
328    /// Can only be modified with [`feature`][crate#features] `format`. Defaults
329    /// to `false`.
330    ///
331    /// # Examples
332    ///
333    /// | Input | Valid? |
334    /// |:-:|:-:|
335    /// | `1.1e3` | ✔️ |
336    /// | `1.1e-3` | ✔️ |
337    /// | `1.1e+3` | ❌ |
338    ///
339    /// # Used For
340    ///
341    /// - Parse Float
342    /// - Write Float
343    #[inline(always)]
344    pub const fn no_positive_exponent_sign(&self) -> bool {
345        Self::NO_POSITIVE_EXPONENT_SIGN
346    }
347
348    /// If a sign symbol before the exponent is required.
349    ///
350    /// See [`required_exponent_sign`][Self::required_exponent_sign].
351    pub const REQUIRED_EXPONENT_SIGN: bool = false;
352
353    /// Get if a sign symbol before the exponent is required.
354    ///
355    /// Can only be modified with [`feature`][crate#features] `format`. Defaults
356    /// to `false`.
357    ///
358    /// # Examples
359    ///
360    /// | Input | Valid? |
361    /// |:-:|:-:|
362    /// | `1.1e3` | ❌ |
363    /// | `1.1e-3` | ✔️ |
364    /// | `1.1e+3` | ✔️ |
365    ///
366    /// # Used For
367    ///
368    /// - Parse Float
369    /// - Write Float
370    #[inline(always)]
371    pub const fn required_exponent_sign(&self) -> bool {
372        Self::REQUIRED_EXPONENT_SIGN
373    }
374
375    /// If an exponent without fraction is not allowed.
376    ///
377    /// See [`no_exponent_without_fraction`][Self::no_exponent_without_fraction].
378    pub const NO_EXPONENT_WITHOUT_FRACTION: bool = false;
379
380    /// Get if an exponent without fraction is not allowed.
381    ///
382    /// Can only be modified with [`feature`][crate#features] `format`. Defaults
383    /// to `false`.
384    ///
385    /// # Examples
386    ///
387    /// | Input | Valid? |
388    /// |:-:|:-:|
389    /// | `1e3` | ❌ |
390    /// | `1.e3` | ❌ |
391    /// | `1.1e` | ✔️ |
392    /// | `.1e3` | ✔️ |
393    ///
394    /// # Used For
395    ///
396    /// - Parse Float
397    #[inline(always)]
398    pub const fn no_exponent_without_fraction(&self) -> bool {
399        Self::NO_EXPONENT_WITHOUT_FRACTION
400    }
401
402    /// If special (non-finite) values are not allowed.
403    ///
404    /// See [`no_special`][Self::no_special].
405    pub const NO_SPECIAL: bool = false;
406
407    /// Get if special (non-finite) values are not allowed.
408    ///
409    /// Can only be modified with [`feature`][crate#features] `format`. Defaults
410    /// to `false`.
411    ///
412    /// # Examples
413    ///
414    /// | Input | Valid? |
415    /// |:-:|:-:|
416    /// | `NaN` | ❌ |
417    /// | `inf` | ❌ |
418    /// | `-Infinity` | ❌ |
419    /// | `1.1e` | ✔️ |
420    ///
421    /// # Used For
422    ///
423    /// - Parse Float
424    #[inline(always)]
425    pub const fn no_special(&self) -> bool {
426        Self::NO_SPECIAL
427    }
428
429    /// If special (non-finite) values are case-sensitive.
430    ///
431    /// See [`case_sensitive_special`][Self::case_sensitive_special].
432    pub const CASE_SENSITIVE_SPECIAL: bool = false;
433
434    /// Get if special (non-finite) values are case-sensitive.
435    ///
436    /// If set to [`true`], then `NaN` and `nan` are treated as the same value
437    /// ([Not a Number][f64::NAN]). Can only be modified with
438    /// [`feature`][crate#features] `format`. Defaults to [`false`].
439    ///
440    /// # Used For
441    ///
442    /// - Parse Float
443    #[inline(always)]
444    pub const fn case_sensitive_special(&self) -> bool {
445        Self::CASE_SENSITIVE_SPECIAL
446    }
447
448    /// If leading zeros before an integer are not allowed.
449    ///
450    /// See [`no_integer_leading_zeros`][Self::no_integer_leading_zeros].
451    pub const NO_INTEGER_LEADING_ZEROS: bool = false;
452
453    /// Get if leading zeros before an integer are not allowed.
454    ///
455    /// Can only be modified with [`feature`][crate#features] `format`. Defaults
456    /// to [`false`].
457    ///
458    /// # Examples
459    ///
460    /// | Input | Valid? |
461    /// |:-:|:-:|
462    /// | `01` | ❌ |
463    /// | `0` | ✔️ |
464    /// | `10` | ✔️ |
465    ///
466    /// # Used For
467    ///
468    /// - Parse Integer
469    #[inline(always)]
470    pub const fn no_integer_leading_zeros(&self) -> bool {
471        Self::NO_INTEGER_LEADING_ZEROS
472    }
473
474    /// If leading zeros before a float are not allowed.
475    ///
476    /// See [`no_float_leading_zeros`][Self::no_float_leading_zeros].
477    pub const NO_FLOAT_LEADING_ZEROS: bool = false;
478
479    /// Get if leading zeros before a float are not allowed.
480    ///
481    /// This is before the significant digits of the float, that is, if there is
482    /// 1 or more digits in the integral component and the leading digit is 0,
483    /// Can only be modified with [`feature`][crate#features] `format`. Defaults
484    /// to [`false`].
485    ///
486    /// # Examples
487    ///
488    /// | Input | Valid? |
489    /// |:-:|:-:|
490    /// | `01` | ❌ |
491    /// | `01.0` | ❌ |
492    /// | `0` | ✔️ |
493    /// | `10` | ✔️ |
494    /// | `0.1` | ✔️ |
495    ///
496    /// # Used For
497    ///
498    /// - Parse Float
499    #[inline(always)]
500    pub const fn no_float_leading_zeros(&self) -> bool {
501        Self::NO_FLOAT_LEADING_ZEROS
502    }
503
504    /// If exponent notation is required.
505    ///
506    /// See [`required_exponent_notation`][Self::required_exponent_notation].
507    pub const REQUIRED_EXPONENT_NOTATION: bool = false;
508
509    /// Get if exponent notation is required.
510    ///
511    /// Can only be modified with [`feature`][crate#features] `format`. Defaults
512    /// to [`false`].
513    ///
514    /// # Examples
515    ///
516    /// | Input | Valid? |
517    /// |:-:|:-:|
518    /// | `1` | ❌ |
519    /// | `1.0` | ❌ |
520    /// | `1e3` | ✔️ |
521    /// | `1.1e3` | ✔️ |
522    ///
523    /// # Used For
524    ///
525    /// - Parse Float
526    /// - Write Float
527    #[inline(always)]
528    pub const fn required_exponent_notation(&self) -> bool {
529        Self::REQUIRED_EXPONENT_NOTATION
530    }
531
532    /// If exponent characters are case-sensitive.
533    ///
534    /// See [`case_sensitive_exponent`][Self::case_sensitive_exponent].
535    pub const CASE_SENSITIVE_EXPONENT: bool = false;
536
537    /// Get if exponent characters are case-sensitive.
538    ///
539    /// If set to [`true`], then the exponent character `e` would be considered
540    /// the different from `E`. Can only be modified with
541    /// [`feature`][crate#features] `format`. Defaults to [`false`].
542    ///
543    /// # Used For
544    ///
545    /// - Parse Float
546    #[inline(always)]
547    pub const fn case_sensitive_exponent(&self) -> bool {
548        Self::CASE_SENSITIVE_EXPONENT
549    }
550
551    /// If base prefixes are case-sensitive.
552    ///
553    /// See [`case_sensitive_base_prefix`][Self::case_sensitive_base_prefix].
554    pub const CASE_SENSITIVE_BASE_PREFIX: bool = false;
555
556    /// Get if base prefixes are case-sensitive.
557    ///
558    /// If set to [`true`], then the base prefix `x` would be considered the
559    /// different from `X`. Can only be modified with
560    /// [`feature`][crate#features] `power-of-two` or `radix` along with
561    /// `format`. Defaults to [`false`].
562    ///
563    /// # Used For
564    ///
565    /// - Parse Float
566    /// - Parse Integer
567    #[inline(always)]
568    pub const fn case_sensitive_base_prefix(&self) -> bool {
569        Self::CASE_SENSITIVE_BASE_PREFIX
570    }
571
572    /// If base suffixes are case-sensitive.
573    ///
574    /// See [`case_sensitive_base_suffix`][Self::case_sensitive_base_suffix].
575    pub const CASE_SENSITIVE_BASE_SUFFIX: bool = false;
576
577    /// Get if base suffixes are case-sensitive.
578    ///
579    /// If set to [`true`], then the base suffix `x` would be considered the
580    /// different from `X`. Can only be modified with
581    /// [`feature`][crate#features] `power-of-two` or `radix` along with
582    /// `format`. Defaults to [`false`].
583    ///
584    /// # Used For
585    ///
586    /// - Parse Float
587    /// - Parse Integer
588    #[inline(always)]
589    pub const fn case_sensitive_base_suffix(&self) -> bool {
590        Self::CASE_SENSITIVE_BASE_SUFFIX
591    }
592
593    // DIGIT SEPARATOR FLAGS & MASKS
594
595    // If digit separators are allowed between integer digits.
596    ///
597    /// This will not consider an input of only the digit separator
598    /// to be a valid separator: the digit separator must be surrounded by
599    /// digits.
600    ///
601    /// See [`integer_internal_digit_separator`][Self::integer_internal_digit_separator].
602    pub const INTEGER_INTERNAL_DIGIT_SEPARATOR: bool = false;
603
604    /// Get if digit separators are allowed between integer digits.
605    ///
606    /// This will not consider an input of only the digit separator
607    /// to be a valid separator: the digit separator must be surrounded by
608    /// digits. Can only be modified with [`feature`][crate#features] `format`.
609    /// Defaults to [`false`].
610    ///
611    /// # Examples
612    ///
613    /// Using a digit separator of `_`.
614    ///
615    /// | Input | Valid? |
616    /// |:-:|:-:|
617    /// | `1` | ✔️ |
618    /// | `_` | ❌ |
619    /// | `1_1` | ✔️ |
620    /// | `1_` | ❌ |
621    /// | `_1` | ❌ |
622    ///
623    /// # Used For
624    ///
625    /// - Parse Float
626    /// - Parse Integer
627    #[inline(always)]
628    pub const fn integer_internal_digit_separator(&self) -> bool {
629        Self::INTEGER_INTERNAL_DIGIT_SEPARATOR
630    }
631
632    /// If digit separators are allowed between fraction digits.
633    ///
634    /// This will not consider an input of only the digit separator
635    /// to be a valid separator: the digit separator must be surrounded by
636    /// digits.
637    ///
638    /// See [`fraction_internal_digit_separator`][Self::fraction_internal_digit_separator].
639    pub const FRACTION_INTERNAL_DIGIT_SEPARATOR: bool = false;
640
641    /// Get if digit separators are allowed between fraction digits.
642    ///
643    /// This will not consider an input of only the digit separator
644    /// to be a valid separator: the digit separator must be surrounded by
645    /// digits. Can only be modified with [`feature`][crate#features] `format`.
646    /// Defaults to [`false`].
647    ///
648    /// # Examples
649    ///
650    /// Using a digit separator of `_`.
651    ///
652    /// | Input | Valid? |
653    /// |:-:|:-:|
654    /// | `1.1` | ✔️ |
655    /// | `1._` | ❌ |
656    /// | `1.1_1` | ✔️ |
657    /// | `1.1_` | ❌ |
658    /// | `1._1` | ❌ |
659    ///
660    /// # Used For
661    ///
662    /// - Parse Float
663    #[inline(always)]
664    pub const fn fraction_internal_digit_separator(&self) -> bool {
665        Self::FRACTION_INTERNAL_DIGIT_SEPARATOR
666    }
667
668    /// If digit separators are allowed between exponent digits.
669    ///
670    /// This will not consider an input of only the digit separator
671    /// to be a valid separator: the digit separator must be surrounded by
672    /// digits.
673    ///
674    /// See [`exponent_internal_digit_separator`][Self::exponent_internal_digit_separator].
675    pub const EXPONENT_INTERNAL_DIGIT_SEPARATOR: bool = false;
676
677    /// Get if digit separators are allowed between exponent digits.
678    ///
679    /// This will not consider an input of only the digit separator
680    /// to be a valid separator: the digit separator must be surrounded by
681    /// digits. Can only be modified with [`feature`][crate#features] `format`.
682    /// Defaults to [`false`].
683    ///
684    /// # Examples
685    ///
686    /// Using a digit separator of `_`.
687    ///
688    /// | Input | Valid? |
689    /// |:-:|:-:|
690    /// | `1.1e1` | ✔️ |
691    /// | `1.1e_` | ❌ |
692    /// | `1.1e1_1` | ✔️ |
693    /// | `1.1e1_` | ❌ |
694    /// | `1.1e_1` | ❌ |
695    ///
696    /// # Used For
697    ///
698    /// - Parse Float
699    #[inline(always)]
700    pub const fn exponent_internal_digit_separator(&self) -> bool {
701        Self::EXPONENT_INTERNAL_DIGIT_SEPARATOR
702    }
703
704    /// If digit separators are allowed between digits.
705    ///
706    /// This will not consider an input of only the digit separator
707    /// to be a valid separator: the digit separator must be surrounded by
708    /// digits.
709    ///
710    /// See [`internal_digit_separator`][Self::internal_digit_separator].
711    pub const INTERNAL_DIGIT_SEPARATOR: bool = false;
712
713    /// Get if digit separators are allowed between digits.
714    ///
715    /// This will not consider an input of only the digit separator
716    /// to be a valid separator: the digit separator must be surrounded by
717    /// digits. This is equivalent to any of
718    /// [`integer_internal_digit_separator`],
719    /// [`fraction_internal_digit_separator`], or
720    /// [`exponent_internal_digit_separator`] being set.
721    ///
722    /// [`integer_internal_digit_separator`]: Self::integer_internal_digit_separator
723    /// [`fraction_internal_digit_separator`]: Self::fraction_internal_digit_separator
724    /// [`exponent_internal_digit_separator`]: Self::exponent_internal_digit_separator
725    #[inline(always)]
726    pub const fn internal_digit_separator(&self) -> bool {
727        Self::INTERNAL_DIGIT_SEPARATOR
728    }
729
730    /// If a digit separator is allowed before any integer digits.
731    ///
732    /// This will consider an input of only the digit separator
733    /// to be a identical to empty input.
734    ///
735    /// See [`integer_leading_digit_separator`][Self::integer_leading_digit_separator].
736    pub const INTEGER_LEADING_DIGIT_SEPARATOR: bool = false;
737
738    /// Get if a digit separator is allowed before any integer digits.
739    ///
740    /// This will consider an input of only the digit separator
741    /// to be a identical to empty input. Can only be modified with
742    /// [`feature`][crate#features] `format`. Defaults to [`false`].
743    ///
744    /// # Examples
745    ///
746    /// Using a digit separator of `_`.
747    ///
748    /// | Input | Valid? |
749    /// |:-:|:-:|
750    /// | `1` | ✔️ |
751    /// | `_` | ❌ |
752    /// | `1_1` | ❌ |
753    /// | `1_` | ❌ |
754    /// | `_1` | ✔️ |
755    ///
756    /// # Used For
757    ///
758    /// - Parse Float
759    /// - Parse Integer
760    #[inline(always)]
761    pub const fn integer_leading_digit_separator(&self) -> bool {
762        Self::INTEGER_LEADING_DIGIT_SEPARATOR
763    }
764
765    /// If a digit separator is allowed before any integer digits.
766    ///
767    /// This will consider an input of only the digit separator
768    /// to be a identical to empty input.
769    ///
770    /// See [`fraction_leading_digit_separator`][Self::fraction_leading_digit_separator].
771    pub const FRACTION_LEADING_DIGIT_SEPARATOR: bool = false;
772
773    /// Get if a digit separator is allowed before any fraction digits.
774    ///
775    /// This will consider an input of only the digit separator
776    /// to be a identical to empty input. Can only be modified with
777    /// [`feature`][crate#features] `format`. Defaults to [`false`].
778    ///
779    /// # Examples
780    ///
781    /// Using a digit separator of `_`.
782    ///
783    /// | Input | Valid? |
784    /// |:-:|:-:|
785    /// | `1.1` | ✔️ |
786    /// | `1._` | ❌ |
787    /// | `1.1_1` | ❌ |
788    /// | `1.1_` | ❌ |
789    /// | `1._1` | ✔️ |
790    ///
791    /// # Used For
792    ///
793    /// - Parse Float
794    #[inline(always)]
795    pub const fn fraction_leading_digit_separator(&self) -> bool {
796        Self::FRACTION_LEADING_DIGIT_SEPARATOR
797    }
798
799    /// If a digit separator is allowed before any exponent digits.
800    ///
801    /// This will consider an input of only the digit separator
802    /// to be a identical to empty input.
803    ///
804    /// See [`exponent_leading_digit_separator`][Self::exponent_leading_digit_separator].
805    pub const EXPONENT_LEADING_DIGIT_SEPARATOR: bool = false;
806
807    /// Get if a digit separator is allowed before any exponent digits.
808    ///
809    /// This will consider an input of only the digit separator
810    /// to be a identical to empty input. Can only be modified with
811    /// [`feature`][crate#features] `format`. Defaults to [`false`].
812    ///
813    /// # Examples
814    ///
815    /// Using a digit separator of `_`.
816    ///
817    /// | Input | Valid? |
818    /// |:-:|:-:|
819    /// | `1.1e1` | ✔️ |
820    /// | `1.1e_` | ❌ |
821    /// | `1.1e1_1` | ❌ |
822    /// | `1.1e1_` | ❌ |
823    /// | `1.1e_1` | ✔️ |
824    ///
825    /// # Used For
826    ///
827    /// - Parse Float
828    #[inline(always)]
829    pub const fn exponent_leading_digit_separator(&self) -> bool {
830        Self::EXPONENT_LEADING_DIGIT_SEPARATOR
831    }
832
833    /// If a digit separator is allowed before any digits.
834    ///
835    /// This will consider an input of only the digit separator
836    /// to be a identical to empty input.
837    ///
838    /// See [`leading_digit_separator`][Self::leading_digit_separator].
839    pub const LEADING_DIGIT_SEPARATOR: bool = false;
840
841    /// Get if a digit separator is allowed before any digits.
842    ///
843    /// This will consider an input of only the digit separator
844    /// to be a identical to empty input. This is equivalent to
845    /// any of [`integer_leading_digit_separator`],
846    /// [`fraction_leading_digit_separator`], or
847    /// [`exponent_leading_digit_separator`] being set.
848    ///
849    /// [`integer_leading_digit_separator`]: Self::integer_leading_digit_separator
850    /// [`fraction_leading_digit_separator`]: Self::fraction_leading_digit_separator
851    /// [`exponent_leading_digit_separator`]: Self::exponent_leading_digit_separator
852    #[inline(always)]
853    pub const fn leading_digit_separator(&self) -> bool {
854        Self::LEADING_DIGIT_SEPARATOR
855    }
856
857    /// If a digit separator is allowed after any integer digits.
858    ///
859    /// This will consider an input of only the digit separator
860    /// to be a identical to empty input.
861    ///
862    /// See [`integer_trailing_digit_separator`][Self::integer_trailing_digit_separator].
863    pub const INTEGER_TRAILING_DIGIT_SEPARATOR: bool = false;
864
865    /// Get if a digit separator is allowed after any integer digits.
866    ///
867    /// This will consider an input of only the digit separator
868    /// to be a identical to empty input. Can only be modified with
869    /// [`feature`][crate#features] `format`. Defaults to [`false`].
870    ///
871    /// # Examples
872    ///
873    /// Using a digit separator of `_`.
874    ///
875    /// | Input | Valid? |
876    /// |:-:|:-:|
877    /// | `1` | ✔️ |
878    /// | `_` | ❌ |
879    /// | `1_1` | ❌ |
880    /// | `1_` | ✔️ |
881    /// | `_1` | ❌ |
882    ///
883    /// # Used For
884    ///
885    /// - Parse Float
886    /// - Parse Integer
887    #[inline(always)]
888    pub const fn integer_trailing_digit_separator(&self) -> bool {
889        Self::INTEGER_TRAILING_DIGIT_SEPARATOR
890    }
891
892    /// If a digit separator is allowed after any fraction digits.
893    ///
894    /// This will consider an input of only the digit separator
895    /// to be a identical to empty input.
896    ///
897    /// See [`fraction_trailing_digit_separator`][Self::fraction_trailing_digit_separator].
898    pub const FRACTION_TRAILING_DIGIT_SEPARATOR: bool = false;
899
900    /// Get if a digit separator is allowed after any fraction digits.
901    ///
902    /// This will consider an input of only the digit separator
903    /// to be a identical to empty input. Can only be modified with
904    /// [`feature`][crate#features] `format`. Defaults to [`false`]. # Examples
905    ///
906    /// Using a digit separator of `_`.
907    ///
908    /// | Input | Valid? |
909    /// |:-:|:-:|
910    /// | `1.1` | ✔️ |
911    /// | `1._` | ❌ |
912    /// | `1.1_1` | ❌ |
913    /// | `1.1_` | ✔️ |
914    /// | `1._1` | ❌ |
915    ///
916    /// # Used For
917    ///
918    /// - Parse Float
919    #[inline(always)]
920    pub const fn fraction_trailing_digit_separator(&self) -> bool {
921        Self::FRACTION_TRAILING_DIGIT_SEPARATOR
922    }
923
924    /// If a digit separator is allowed after any exponent digits.
925    ///
926    /// This will consider an input of only the digit separator
927    /// to be a identical to empty input.
928    ///
929    /// See [`exponent_trailing_digit_separator`][Self::exponent_trailing_digit_separator].
930    pub const EXPONENT_TRAILING_DIGIT_SEPARATOR: bool = false;
931
932    /// Get if a digit separator is allowed after any exponent digits.
933    ///
934    /// This will consider an input of only the digit separator
935    /// to be a identical to empty input. Can only be modified with
936    /// [`feature`][crate#features] `format`. Defaults to [`false`].
937    ///
938    /// # Examples
939    ///
940    /// Using a digit separator of `_`.
941    ///
942    /// | Input | Valid? |
943    /// |:-:|:-:|
944    /// | `1.1e1` | ✔️ |
945    /// | `1.1e_` | ❌ |
946    /// | `1.1e1_1` | ❌ |
947    /// | `1.1e1_` | ✔️ |
948    /// | `1.1e_1` | ❌ |
949    ///
950    /// # Used For
951    ///
952    /// - Parse Float
953    #[inline(always)]
954    pub const fn exponent_trailing_digit_separator(&self) -> bool {
955        Self::EXPONENT_TRAILING_DIGIT_SEPARATOR
956    }
957
958    /// If a digit separator is allowed after any digits.
959    ///
960    /// This will consider an input of only the digit separator
961    /// to be a identical to empty input.
962    ///
963    /// See [`trailing_digit_separator`][Self::trailing_digit_separator].
964    pub const TRAILING_DIGIT_SEPARATOR: bool = false;
965
966    /// Get if a digit separator is allowed after any digits.
967    ///
968    /// This will consider an input of only the digit separator
969    /// to be a identical to empty input. This is equivalent to
970    /// any of [`integer_trailing_digit_separator`],
971    /// [`fraction_trailing_digit_separator`], or
972    /// [`exponent_trailing_digit_separator`] being set.
973    ///
974    /// [`integer_trailing_digit_separator`]: Self::integer_trailing_digit_separator
975    /// [`fraction_trailing_digit_separator`]: Self::fraction_trailing_digit_separator
976    /// [`exponent_trailing_digit_separator`]: Self::exponent_trailing_digit_separator
977    #[inline(always)]
978    pub const fn trailing_digit_separator(&self) -> bool {
979        Self::TRAILING_DIGIT_SEPARATOR
980    }
981
982    /// If multiple consecutive integer digit separators are allowed.
983    ///
984    /// See [`integer_consecutive_digit_separator`][Self::integer_consecutive_digit_separator].
985    pub const INTEGER_CONSECUTIVE_DIGIT_SEPARATOR: bool = false;
986
987    /// Get if multiple consecutive integer digit separators are allowed.
988    ///
989    /// That is, using `_` as a digit separator `__` would be allowed where any
990    /// digit separators (leading, trailing, internal) are allowed in the
991    /// integer. Can only be modified with [`feature`][crate#features] `format`.
992    /// Defaults to [`false`].
993    ///
994    /// # Used For
995    ///
996    /// - Parse Float
997    /// - Parse Integer
998    #[inline(always)]
999    pub const fn integer_consecutive_digit_separator(&self) -> bool {
1000        Self::INTEGER_CONSECUTIVE_DIGIT_SEPARATOR
1001    }
1002
1003    /// If multiple consecutive fraction digit separators are allowed.
1004    ///
1005    /// See [`fraction_consecutive_digit_separator`][Self::fraction_consecutive_digit_separator].
1006    pub const FRACTION_CONSECUTIVE_DIGIT_SEPARATOR: bool = false;
1007
1008    /// Get if multiple consecutive fraction digit separators are allowed.
1009    ///
1010    /// That is, using `_` as a digit separator `__` would be allowed where any
1011    /// digit separators (leading, trailing, internal) are allowed in the
1012    /// fraction. Can only be modified with [`feature`][crate#features]
1013    /// `format`. Defaults to [`false`].
1014    ///
1015    /// # Used For
1016    ///
1017    /// - Parse Float
1018    #[inline(always)]
1019    pub const fn fraction_consecutive_digit_separator(&self) -> bool {
1020        Self::FRACTION_CONSECUTIVE_DIGIT_SEPARATOR
1021    }
1022
1023    /// If multiple consecutive exponent digit separators are allowed.
1024    ///
1025    /// See [`exponent_consecutive_digit_separator`][Self::exponent_consecutive_digit_separator].
1026    pub const EXPONENT_CONSECUTIVE_DIGIT_SEPARATOR: bool = false;
1027
1028    /// Get if multiple consecutive exponent digit separators are allowed.
1029    ///
1030    /// That is, using `_` as a digit separator `__` would be allowed where any
1031    /// digit separators (leading, trailing, internal) are allowed in the
1032    /// exponent. Can only be modified with [`feature`][crate#features]
1033    /// `format`. Defaults to [`false`].
1034    ///
1035    /// # Used For
1036    ///
1037    /// - Parse Float
1038    #[inline(always)]
1039    pub const fn exponent_consecutive_digit_separator(&self) -> bool {
1040        Self::EXPONENT_CONSECUTIVE_DIGIT_SEPARATOR
1041    }
1042
1043    /// If multiple consecutive digit separators are allowed.
1044    ///
1045    /// See [`consecutive_digit_separator`][Self::consecutive_digit_separator].
1046    pub const CONSECUTIVE_DIGIT_SEPARATOR: bool = false;
1047
1048    /// Get if multiple consecutive digit separators are allowed.
1049    ///
1050    /// This is equivalent to any of [`integer_consecutive_digit_separator`],
1051    /// [`fraction_consecutive_digit_separator`], or
1052    /// [`exponent_consecutive_digit_separator`] being set.
1053    ///
1054    /// [`integer_consecutive_digit_separator`]: Self::integer_consecutive_digit_separator
1055    /// [`fraction_consecutive_digit_separator`]: Self::fraction_consecutive_digit_separator
1056    /// [`exponent_consecutive_digit_separator`]: Self::exponent_consecutive_digit_separator
1057    #[inline(always)]
1058    pub const fn consecutive_digit_separator(&self) -> bool {
1059        Self::CONSECUTIVE_DIGIT_SEPARATOR
1060    }
1061
1062    /// If any digit separators are allowed in special (non-finite) values.
1063    ///
1064    /// See [`special_digit_separator`][Self::special_digit_separator].
1065    pub const SPECIAL_DIGIT_SEPARATOR: bool = false;
1066
1067    /// Get if any digit separators are allowed in special (non-finite) values.
1068    ///
1069    /// This enables leading, trailing, internal, and consecutive digit
1070    /// separators for any special floats: for example, `N__a_N_` is considered
1071    /// the same as `NaN`. Can only be modified with [`feature`][crate#features]
1072    /// `format`. Defaults to [`false`].
1073    ///
1074    /// # Used For
1075    ///
1076    /// - Parse Float
1077    #[inline(always)]
1078    pub const fn special_digit_separator(&self) -> bool {
1079        Self::SPECIAL_DIGIT_SEPARATOR
1080    }
1081
1082    // CHARACTERS
1083
1084    /// The digit separator character in the packed struct.
1085    ///
1086    /// See [`digit_separator`][Self::digit_separator].
1087    pub const DIGIT_SEPARATOR: u8 = 0;
1088
1089    /// Get the digit separator for the number format.
1090    ///
1091    /// Digit separators are frequently used in number literals to group
1092    /// digits: `1,000,000` is a lot more readable than `1000000`, but
1093    /// the `,` characters should be ignored in the parsing of the number.
1094    ///
1095    /// Can only be modified with [`feature`][crate#features] `format`. Defaults
1096    /// to `0`, or no digit separators allowed.
1097    ///
1098    /// # Examples
1099    ///
1100    /// Using a digit separator of `_` (note that the validity
1101    /// oh where a digit separator can appear depends on the other digit
1102    /// separator flags).
1103    ///
1104    /// | Input | Valid? |
1105    /// |:-:|:-:|
1106    /// | `1` | ✔️ |
1107    /// | `1_4` | ✔️ |
1108    /// | `+_14` | ✔️ |
1109    /// | `+14e3_5` | ✔️ |
1110    /// | `1_d` | ❌ |
1111    ///
1112    /// # Used For
1113    ///
1114    /// - Parse Float
1115    /// - Parse Integer
1116    #[inline(always)]
1117    pub const fn digit_separator(&self) -> u8 {
1118        Self::DIGIT_SEPARATOR
1119    }
1120
1121    /// Get if the format has a digit separator.
1122    #[inline(always)]
1123    pub const fn has_digit_separator(&self) -> bool {
1124        self.digit_separator() != 0
1125    }
1126
1127    /// The base prefix character in the packed struct.
1128    ///
1129    /// See [`base_prefix`][Self::base_prefix].
1130    pub const BASE_PREFIX: u8 = 0;
1131
1132    /// Get the optional character for the base prefix.
1133    ///
1134    /// This character will come after a leading zero, so for example
1135    /// setting the base prefix to `x` means that a leading `0x` will
1136    /// be ignore, if present. Can only be modified with
1137    /// [`feature`][crate#features] `power-of-two` or `radix` along with
1138    /// `format`. Defaults to `0`, or no base prefix allowed.
1139    ///
1140    /// # Examples
1141    ///
1142    /// Using a base prefix of `x`.
1143    ///
1144    /// | Input | Valid? |
1145    /// |:-:|:-:|
1146    /// | `0x1` | ✔️ |
1147    /// | `x1` | ❌ |
1148    /// | `1` | ✔️ |
1149    /// | `1x` | ❌ |
1150    /// | `1x1` | ❌ |
1151    ///
1152    /// # Used For
1153    ///
1154    /// - Parse Float
1155    /// - Parse Integer
1156    #[inline(always)]
1157    pub const fn base_prefix(&self) -> u8 {
1158        Self::BASE_PREFIX
1159    }
1160
1161    /// Get if the format has a base prefix.
1162    #[inline(always)]
1163    pub const fn has_base_prefix(&self) -> bool {
1164        false
1165    }
1166
1167    /// The base suffix character in the packed struct.
1168    ///
1169    /// See [`base_suffix`][Self::base_suffix].
1170    pub const BASE_SUFFIX: u8 = 0;
1171
1172    /// Get the optional character for the base suffix.
1173    ///
1174    /// This character will at the end of the buffer, so for example
1175    /// setting the base prefix to `x` means that a trailing `x` will
1176    /// be ignored, if present.  Can only be modified with
1177    /// [`feature`][crate#features] `power-of-two` or `radix` along with
1178    /// `format`. Defaults to `0`, or no base suffix allowed.
1179    ///
1180    /// # Examples
1181    ///
1182    /// Using a base suffix of `x`.
1183    ///
1184    /// | Input | Valid? |
1185    /// |:-:|:-:|
1186    /// | `1` | ✔️ |
1187    /// | `1x` | ✔️ |
1188    /// | `1d` | ❌ |
1189    ///
1190    /// # Used For
1191    ///
1192    /// - Parse Float
1193    /// - Parse Integer
1194    #[inline(always)]
1195    pub const fn base_suffix(&self) -> u8 {
1196        Self::BASE_SUFFIX
1197    }
1198
1199    /// Get if the format has a base suffix.
1200    #[inline(always)]
1201    pub const fn has_base_suffix(&self) -> bool {
1202        false
1203    }
1204
1205    // RADIX
1206
1207    /// The radix for the significant digits in the packed struct.
1208    ///
1209    /// See [`mantissa_radix`][Self::mantissa_radix].
1210    pub const MANTISSA_RADIX: u32 = flags::mantissa_radix(FORMAT);
1211
1212    /// Get the radix for mantissa digits.
1213    ///
1214    /// This is only used for the significant digits, that is, the integral and
1215    /// fractional components. Can only be modified with
1216    /// [`feature`][crate#features] `power-of-two` or `radix`. Defaults
1217    /// to `10`.
1218    ///
1219    /// | Radix | String | Number |
1220    /// |:-:|:-:|:-:|
1221    /// | 2 | "10011010010" | 1234 |
1222    /// | 3 | "1200201" | 1234 |
1223    /// | 8 | "2322" | 1234 |
1224    /// | 10 | "1234" | 1234 |
1225    /// | 16 | "4d2" | 1234 |
1226    /// | 31 | "18p" | 1234 |
1227    ///
1228    /// # Used For
1229    ///
1230    /// - Parse Float
1231    /// - Parse Integer
1232    /// - Write Float
1233    /// - Write Integer
1234    #[inline(always)]
1235    pub const fn mantissa_radix(&self) -> u32 {
1236        Self::MANTISSA_RADIX
1237    }
1238
1239    /// The radix for the significant digits in the packed struct.
1240    ///
1241    /// Alias for [`MANTISSA_RADIX`][Self::MANTISSA_RADIX].
1242    pub const RADIX: u32 = Self::MANTISSA_RADIX;
1243
1244    /// Get the radix for the significant digits.
1245    ///
1246    /// This is an alias for [`mantissa_radix`][Self::mantissa_radix].
1247    #[inline(always)]
1248    pub const fn radix(&self) -> u32 {
1249        Self::RADIX
1250    }
1251
1252    /// Get the `radix^2` for the significant digits.
1253    #[inline(always)]
1254    pub const fn radix2(&self) -> u32 {
1255        self.radix().wrapping_mul(self.radix())
1256    }
1257
1258    /// Get the `radix^4` for the significant digits.
1259    #[inline(always)]
1260    pub const fn radix4(&self) -> u32 {
1261        self.radix2().wrapping_mul(self.radix2())
1262    }
1263
1264    /// Get the `radix^8` for the significant digits.
1265    #[inline(always)]
1266    pub const fn radix8(&self) -> u32 {
1267        self.radix4().wrapping_mul(self.radix4())
1268    }
1269
1270    /// The base for the exponent.
1271    ///
1272    /// See [`exponent_base`][Self::exponent_base].
1273    pub const EXPONENT_BASE: u32 = flags::exponent_base(FORMAT);
1274
1275    /// Get the radix for the exponent.
1276    ///
1277    /// For example, in `1.234e3`, it means `1.234 * 10^3`, and the exponent
1278    /// base here is 10. Some programming languages, like C, support hex floats
1279    /// with an exponent base of 2, for example `0x1.8p3`, or `1.5 * 2^3`.
1280    /// Defaults to `10`. Can only be modified with [`feature`][crate#features]
1281    /// `power-of-two` or `radix`. Defaults to `10`.
1282    ///
1283    /// # Used For
1284    ///
1285    /// - Parse Float
1286    /// - Parse Integer
1287    #[inline(always)]
1288    pub const fn exponent_base(&self) -> u32 {
1289        Self::EXPONENT_BASE
1290    }
1291
1292    /// The radix for the exponent digits.
1293    ///
1294    /// See [`exponent_radix`][Self::exponent_radix].
1295    pub const EXPONENT_RADIX: u32 = flags::exponent_radix(FORMAT);
1296
1297    /// Get the radix for exponent digits.
1298    ///
1299    /// This is only used for the exponent digits. We assume the radix for the
1300    /// significant digits ([`mantissa_radix`][Self::mantissa_radix]) is
1301    /// 10 as is the exponent base. Defaults to `10`. Can only be modified with
1302    /// [`feature`][crate#features] `power-of-two` or `radix`. Defaults to `10`.
1303    ///
1304    /// | Radix | String | Number |
1305    /// |:-:|:-:|:-:|
1306    /// | 2 | "1.234^1100" | 1.234e9 |
1307    /// | 3 | "1.234^110" | 1.234e9 |
1308    /// | 8 | "1.234^14" | 1.234e9 |
1309    /// | 10 | "1.234^12" | 1.234e9 |
1310    /// | 16 | "1.234^c" | 1.234e9 |
1311    /// | 31 | "1.234^c" | 1.234e9 |
1312    ///
1313    /// # Used For
1314    ///
1315    /// - Parse Float
1316    /// - Parse Integer
1317    #[inline(always)]
1318    pub const fn exponent_radix(&self) -> u32 {
1319        Self::EXPONENT_RADIX
1320    }
1321
1322    // FLAGS
1323
1324    /// Get the flags from the number format.
1325    ///
1326    /// This contains all the non-character and non-radix values
1327    /// in the packed struct.
1328    #[inline(always)]
1329    pub const fn flags(&self) -> u128 {
1330        FORMAT & flags::FLAG_MASK
1331    }
1332
1333    /// Get the interface flags from the number format.
1334    ///
1335    /// This contains all the flags that dictate code flows, and
1336    /// therefore excludes logic like case-sensitive characters.
1337    #[inline(always)]
1338    pub const fn interface_flags(&self) -> u128 {
1339        FORMAT & flags::INTERFACE_FLAG_MASK
1340    }
1341
1342    /// Get the digit separator flags from the number format.
1343    #[inline(always)]
1344    pub const fn digit_separator_flags(&self) -> u128 {
1345        FORMAT & flags::DIGIT_SEPARATOR_FLAG_MASK
1346    }
1347
1348    /// Get the exponent flags from the number format.
1349    ///
1350    /// This contains all the flags pertaining to exponent
1351    /// formats, including digit separators.
1352    #[inline(always)]
1353    pub const fn exponent_flags(&self) -> u128 {
1354        FORMAT & flags::EXPONENT_FLAG_MASK
1355    }
1356
1357    /// Get the integer digit separator flags from the number format.
1358    #[inline(always)]
1359    pub const fn integer_digit_separator_flags(&self) -> u128 {
1360        FORMAT & flags::INTEGER_DIGIT_SEPARATOR_FLAG_MASK
1361    }
1362
1363    /// Get the fraction digit separator flags from the number format.
1364    #[inline(always)]
1365    pub const fn fraction_digit_separator_flags(&self) -> u128 {
1366        FORMAT & flags::FRACTION_DIGIT_SEPARATOR_FLAG_MASK
1367    }
1368
1369    /// Get the exponent digit separator flags from the number format.
1370    #[inline(always)]
1371    pub const fn exponent_digit_separator_flags(&self) -> u128 {
1372        FORMAT & flags::EXPONENT_DIGIT_SEPARATOR_FLAG_MASK
1373    }
1374
1375    // BUILDER
1376
1377    /// Get the number format builder from the format.
1378    #[inline]
1379    pub const fn builder() -> NumberFormatBuilder {
1380        NumberFormatBuilder::new()
1381    }
1382
1383    /// Get the number format builder from the format.
1384    #[inline]
1385    pub const fn rebuild() -> NumberFormatBuilder {
1386        NumberFormatBuilder::rebuild(FORMAT)
1387    }
1388}
1389
1390impl<const FORMAT: u128> Default for NumberFormat<FORMAT> {
1391    fn default() -> Self {
1392        Self::new()
1393    }
1394}
1395
1396/// Get if the radix is valid.
1397#[inline(always)]
1398pub(crate) const fn radix_error_impl(format: u128) -> Error {
1399    if !flags::is_valid_radix(flags::mantissa_radix(format)) {
1400        Error::InvalidMantissaRadix
1401    } else if !flags::is_valid_radix(flags::exponent_base(format)) {
1402        Error::InvalidExponentBase
1403    } else if !flags::is_valid_radix(flags::exponent_radix(format)) {
1404        Error::InvalidExponentRadix
1405    } else {
1406        Error::Success
1407    }
1408}
1409
1410/// Get the error type from the format.
1411#[inline(always)]
1412pub(crate) const fn format_error_impl(format: u128) -> Error {
1413    let valid_flags = flags::REQUIRED_EXPONENT_DIGITS | flags::REQUIRED_MANTISSA_DIGITS;
1414    if !flags::is_valid_radix(flags::mantissa_radix(format)) {
1415        Error::InvalidMantissaRadix
1416    } else if !flags::is_valid_radix(flags::exponent_base(format)) {
1417        Error::InvalidExponentBase
1418    } else if !flags::is_valid_radix(flags::exponent_radix(format)) {
1419        Error::InvalidExponentRadix
1420    } else if !flags::is_valid_digit_separator(format) {
1421        Error::InvalidDigitSeparator
1422    } else if !flags::is_valid_base_prefix(format) {
1423        Error::InvalidBasePrefix
1424    } else if !flags::is_valid_base_suffix(format) {
1425        Error::InvalidBaseSuffix
1426    } else if !flags::is_valid_punctuation(format) {
1427        Error::InvalidPunctuation
1428    } else if (format & flags::FLAG_MASK) != valid_flags {
1429        Error::InvalidFlags
1430    } else {
1431        Error::Success
1432    }
1433}