Debian Codegraph @

include/fast_float/fast_float.h

raw
1
2 #ifndef FASTFLOAT_FAST_FLOAT_H
3 #define FASTFLOAT_FAST_FLOAT_H
4
5 #include "float_common.h"
6
7 namespace fast_float {
8 /**
9 * This function parses the character sequence [first,last) for a number. It
10 * parses floating-point numbers expecting a locale-indepent format equivalent
11 * to what is used by std::strtod in the default ("C") locale. The resulting
12 * floating-point value is the closest floating-point values (using either float
13 * or double), using the "round to even" convention for values that would
14 * otherwise fall right in-between two values. That is, we provide exact parsing
15 * according to the IEEE standard.
16 *
17 * Given a successful parse, the pointer (`ptr`) in the returned value is set to
18 * point right after the parsed number, and the `value` referenced is set to the
19 * parsed value. In case of error, the returned `ec` contains a representative
20 * error, otherwise the default (`std::errc()`) value is stored.
21 *
22 * The implementation does not throw and does not allocate memory (e.g., with
23 * `new` or `malloc`).
24 *
25 * Like the C++17 standard, the `fast_float::from_chars` functions take an
26 * optional last argument of the type `fast_float::chars_format`. It is a bitset
27 * value: we check whether `fmt & fast_float::chars_format::fixed` and `fmt &
28 * fast_float::chars_format::scientific` are set to determine whether we allow
29 * the fixed point and scientific notation respectively. The default is
30 * `fast_float::chars_format::general` which allows both `fixed` and
31 * `scientific`.
32 */
33 template <typename T, typename UC = char,
34 typename = FASTFLOAT_ENABLE_IF(is_supported_float_type<T>::value)>
35 FASTFLOAT_CONSTEXPR20 from_chars_result_t<UC>
36 from_chars(UC const *first, UC const *last, T &value,
37 chars_format fmt = chars_format::general) noexcept;
38
39 /**
40 * Like from_chars, but accepts an `options` argument to govern number parsing.
41 * Both for floating-point types and integer types.
42 */
43 template <typename T, typename UC = char>
44 FASTFLOAT_CONSTEXPR20 from_chars_result_t<UC>
45 from_chars_advanced(UC const *first, UC const *last, T &value,
46 parse_options_t<UC> options) noexcept;
47
48 /**
49 * This function multiplies an integer number by a power of 10 and returns
50 * the result as a double precision floating-point value that is correctly
51 * rounded. The resulting floating-point value is the closest floating-point
52 * value, using the "round to nearest, tie to even" convention for values that
53 * would otherwise fall right in-between two values. That is, we provide exact
54 * conversion according to the IEEE standard.
55 *
56 * On overflow infinity is returned, on underflow 0 is returned.
57 *
58 * The implementation does not throw and does not allocate memory (e.g., with
59 * `new` or `malloc`).
60 */
61 FASTFLOAT_CONSTEXPR20 inline double
62 integer_times_pow10(uint64_t mantissa, int decimal_exponent) noexcept;
63 FASTFLOAT_CONSTEXPR20 inline double
64 integer_times_pow10(int64_t mantissa, int decimal_exponent) noexcept;
65
66 /**
67 * from_chars for integer types.
68 */
69 template <typename T, typename UC = char,
70 typename = FASTFLOAT_ENABLE_IF(is_supported_integer_type<T>::value)>
71 FASTFLOAT_CONSTEXPR20 from_chars_result_t<UC>
72 from_chars(UC const *first, UC const *last, T &value, int base = 10) noexcept;
73
74 } // namespace fast_float
75
76 #include "parse_number.h"
77 #endif // FASTFLOAT_FAST_FLOAT_H