fast_float.hpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // Copyright 2020-2023 Daniel Lemire
  2. // Copyright 2023 Matt Borland
  3. // Distributed under the Boost Software License, Version 1.0.
  4. // https://www.boost.org/LICENSE_1_0.txt
  5. //
  6. // Derivative of: https://github.com/fastfloat/fast_float
  7. #ifndef BOOST_CHARCONV_DETAIL_FASTFLOAT_FAST_FLOAT_HPP
  8. #define BOOST_CHARCONV_DETAIL_FASTFLOAT_FAST_FLOAT_HPP
  9. #include <boost/charconv/detail/fast_float/float_common.hpp>
  10. namespace boost { namespace charconv { namespace detail { namespace fast_float {
  11. /**
  12. * This function parses the character sequence [first,last) for a number. It parses floating-point numbers expecting
  13. * a locale-independent format equivalent to what is used by std::strtod in the default ("C") locale.
  14. * The resulting floating-point value is the closest floating-point values (using either float or double),
  15. * using the "round to even" convention for values that would otherwise fall right in-between two values.
  16. * That is, we provide exact parsing according to the IEEE standard.
  17. *
  18. * Given a successful parse, the pointer (`ptr`) in the returned value is set to point right after the
  19. * parsed number, and the `value` referenced is set to the parsed value. In case of error, the returned
  20. * `ec` contains a representative error, otherwise the default (`std::errc()`) value is stored.
  21. *
  22. * The implementation does not throw and does not allocate memory (e.g., with `new` or `malloc`).
  23. *
  24. * Like the C++17 standard, the `fast_float::from_chars` functions take an optional last argument of
  25. * the type `fast_float::chars_format`. It is a bitset value: we check whether
  26. * `fmt & fast_float::chars_format::fixed` and `fmt & fast_float::chars_format::scientific` are set
  27. * to determine whether we allow the fixed point and scientific notation respectively.
  28. * The default is `fast_float::chars_format::general` which allows both `fixed` and `scientific`.
  29. */
  30. template<typename T, typename UC = char>
  31. BOOST_CHARCONV_FASTFLOAT_CONSTEXPR20
  32. from_chars_result_t<UC> from_chars(UC const * first, UC const * last,
  33. T &value, chars_format fmt = chars_format::general) noexcept;
  34. /**
  35. * Like from_chars, but accepts an `options` argument to govern number parsing.
  36. */
  37. template<typename T, typename UC = char>
  38. BOOST_CHARCONV_FASTFLOAT_CONSTEXPR20
  39. from_chars_result_t<UC> from_chars_advanced(UC const * first, UC const * last,
  40. T &value, parse_options_t<UC> options) noexcept;
  41. }}}} // namespace fast_float
  42. #include <boost/charconv/detail/fast_float/parse_number.hpp>
  43. #endif // BOOST_CHARCONV_FASTFLOAT_FAST_FLOAT_H