| 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | #include <charconv> |
| 10 | #include <string.h> |
| 11 | |
| 12 | #include "include/from_chars_floating_point.h" |
| 13 | #include "include/to_chars_floating_point.h" |
| 14 | |
| 15 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 16 | |
| 17 | #if _LIBCPP_AVAILABILITY_MINIMUM_HEADER_VERSION < 15 |
| 18 | |
| 19 | namespace __itoa { |
| 20 | |
| 21 | _LIBCPP_DIAGNOSTIC_PUSH |
| 22 | _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wmissing-prototypes" ) |
| 23 | // These functions exist for ABI compatibility, so we don't ever want a declaration prior to the definition. |
| 24 | _LIBCPP_EXPORTED_FROM_ABI char* __u32toa(uint32_t value, char* buffer) noexcept { return __base_10_u32(first: buffer, value: value); } |
| 25 | _LIBCPP_EXPORTED_FROM_ABI char* __u64toa(uint64_t value, char* buffer) noexcept { return __base_10_u64(buffer: buffer, value: value); } |
| 26 | _LIBCPP_DIAGNOSTIC_POP |
| 27 | |
| 28 | } // namespace __itoa |
| 29 | |
| 30 | #endif // _LIBCPP_AVAILABILITY_MINIMUM_HEADER_VERSION < 15 |
| 31 | |
| 32 | // The original version of floating-point to_chars was written by Microsoft and |
| 33 | // contributed with the following license. |
| 34 | |
| 35 | // Copyright (c) Microsoft Corporation. |
| 36 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 37 | |
| 38 | // This implementation is dedicated to the memory of Mary and Thavatchai. |
| 39 | |
| 40 | to_chars_result to_chars(char* __first, char* __last, float __value) { |
| 41 | return _Floating_to_chars<_Floating_to_chars_overload::_Plain>(First: __first, Last: __last, Value: __value, Fmt: chars_format{}, Precision: 0); |
| 42 | } |
| 43 | |
| 44 | to_chars_result to_chars(char* __first, char* __last, double __value) { |
| 45 | return _Floating_to_chars<_Floating_to_chars_overload::_Plain>(First: __first, Last: __last, Value: __value, Fmt: chars_format{}, Precision: 0); |
| 46 | } |
| 47 | |
| 48 | to_chars_result to_chars(char* __first, char* __last, long double __value) { |
| 49 | return _Floating_to_chars<_Floating_to_chars_overload::_Plain>( |
| 50 | First: __first, Last: __last, Value: static_cast<double>(__value), Fmt: chars_format{}, Precision: 0); |
| 51 | } |
| 52 | |
| 53 | to_chars_result to_chars(char* __first, char* __last, float __value, chars_format __fmt) { |
| 54 | return _Floating_to_chars<_Floating_to_chars_overload::_Format_only>(First: __first, Last: __last, Value: __value, Fmt: __fmt, Precision: 0); |
| 55 | } |
| 56 | |
| 57 | to_chars_result to_chars(char* __first, char* __last, double __value, chars_format __fmt) { |
| 58 | return _Floating_to_chars<_Floating_to_chars_overload::_Format_only>(First: __first, Last: __last, Value: __value, Fmt: __fmt, Precision: 0); |
| 59 | } |
| 60 | |
| 61 | to_chars_result to_chars(char* __first, char* __last, long double __value, chars_format __fmt) { |
| 62 | return _Floating_to_chars<_Floating_to_chars_overload::_Format_only>( |
| 63 | First: __first, Last: __last, Value: static_cast<double>(__value), Fmt: __fmt, Precision: 0); |
| 64 | } |
| 65 | |
| 66 | to_chars_result to_chars(char* __first, char* __last, float __value, chars_format __fmt, int __precision) { |
| 67 | return _Floating_to_chars<_Floating_to_chars_overload::_Format_precision>( |
| 68 | First: __first, Last: __last, Value: __value, Fmt: __fmt, Precision: __precision); |
| 69 | } |
| 70 | |
| 71 | to_chars_result to_chars(char* __first, char* __last, double __value, chars_format __fmt, int __precision) { |
| 72 | return _Floating_to_chars<_Floating_to_chars_overload::_Format_precision>( |
| 73 | First: __first, Last: __last, Value: __value, Fmt: __fmt, Precision: __precision); |
| 74 | } |
| 75 | |
| 76 | to_chars_result to_chars(char* __first, char* __last, long double __value, chars_format __fmt, int __precision) { |
| 77 | return _Floating_to_chars<_Floating_to_chars_overload::_Format_precision>( |
| 78 | First: __first, Last: __last, Value: static_cast<double>(__value), Fmt: __fmt, Precision: __precision); |
| 79 | } |
| 80 | |
| 81 | template <class _Fp> |
| 82 | __from_chars_result<_Fp> __from_chars_floating_point( |
| 83 | _LIBCPP_NOESCAPE const char* __first, _LIBCPP_NOESCAPE const char* __last, chars_format __fmt) { |
| 84 | return std::__from_chars_floating_point_impl<_Fp>(__first, __last, __fmt); |
| 85 | } |
| 86 | |
| 87 | template __from_chars_result<float> __from_chars_floating_point( |
| 88 | _LIBCPP_NOESCAPE const char* __first, _LIBCPP_NOESCAPE const char* __last, chars_format __fmt); |
| 89 | |
| 90 | template __from_chars_result<double> __from_chars_floating_point( |
| 91 | _LIBCPP_NOESCAPE const char* __first, _LIBCPP_NOESCAPE const char* __last, chars_format __fmt); |
| 92 | _LIBCPP_END_NAMESPACE_STD |
| 93 | |