xref: /freebsd/contrib/llvm-project/libcxx/src/charconv.cpp (revision cb14a3fe5122c879eae1fb480ed7ce82a699ddb6)
1349cc55cSDimitry Andric //===----------------------------------------------------------------------===//
20b57cec5SDimitry Andric //
30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric //
70b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric 
981ad6265SDimitry Andric #include <charconv>
100b57cec5SDimitry Andric #include <string.h>
110b57cec5SDimitry Andric 
120eae32dcSDimitry Andric #include "include/to_chars_floating_point.h"
130eae32dcSDimitry Andric 
140b57cec5SDimitry Andric _LIBCPP_BEGIN_NAMESPACE_STD
150b57cec5SDimitry Andric 
1681ad6265SDimitry Andric #ifndef _LIBCPP_ABI_DO_NOT_EXPORT_TO_CHARS_BASE_10
1781ad6265SDimitry Andric 
18*cb14a3feSDimitry Andric namespace __itoa {
190b57cec5SDimitry Andric 
20*cb14a3feSDimitry Andric _LIBCPP_EXPORTED_FROM_ABI char* __u32toa(uint32_t value, char* buffer) noexcept { return __base_10_u32(buffer, value); }
210b57cec5SDimitry Andric 
22*cb14a3feSDimitry Andric _LIBCPP_EXPORTED_FROM_ABI char* __u64toa(uint64_t value, char* buffer) noexcept { return __base_10_u64(buffer, value); }
230b57cec5SDimitry Andric 
240b57cec5SDimitry Andric } // namespace __itoa
250b57cec5SDimitry Andric 
2681ad6265SDimitry Andric #endif // _LIBCPP_ABI_DO_NOT_EXPORT_TO_CHARS_BASE_10
2781ad6265SDimitry Andric 
280eae32dcSDimitry Andric // The original version of floating-point to_chars was written by Microsoft and
290eae32dcSDimitry Andric // contributed with the following license.
300eae32dcSDimitry Andric 
310eae32dcSDimitry Andric // Copyright (c) Microsoft Corporation.
320eae32dcSDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
330eae32dcSDimitry Andric 
340eae32dcSDimitry Andric // This implementation is dedicated to the memory of Mary and Thavatchai.
350eae32dcSDimitry Andric 
360eae32dcSDimitry Andric to_chars_result to_chars(char* __first, char* __last, float __value) {
370eae32dcSDimitry Andric   return _Floating_to_chars<_Floating_to_chars_overload::_Plain>(__first, __last, __value, chars_format{}, 0);
380eae32dcSDimitry Andric }
390eae32dcSDimitry Andric 
400eae32dcSDimitry Andric to_chars_result to_chars(char* __first, char* __last, double __value) {
410eae32dcSDimitry Andric   return _Floating_to_chars<_Floating_to_chars_overload::_Plain>(__first, __last, __value, chars_format{}, 0);
420eae32dcSDimitry Andric }
430eae32dcSDimitry Andric 
440eae32dcSDimitry Andric to_chars_result to_chars(char* __first, char* __last, long double __value) {
45*cb14a3feSDimitry Andric   return _Floating_to_chars<_Floating_to_chars_overload::_Plain>(
46*cb14a3feSDimitry Andric       __first, __last, static_cast<double>(__value), chars_format{}, 0);
470eae32dcSDimitry Andric }
480eae32dcSDimitry Andric 
490eae32dcSDimitry Andric to_chars_result to_chars(char* __first, char* __last, float __value, chars_format __fmt) {
500eae32dcSDimitry Andric   return _Floating_to_chars<_Floating_to_chars_overload::_Format_only>(__first, __last, __value, __fmt, 0);
510eae32dcSDimitry Andric }
520eae32dcSDimitry Andric 
530eae32dcSDimitry Andric to_chars_result to_chars(char* __first, char* __last, double __value, chars_format __fmt) {
540eae32dcSDimitry Andric   return _Floating_to_chars<_Floating_to_chars_overload::_Format_only>(__first, __last, __value, __fmt, 0);
550eae32dcSDimitry Andric }
560eae32dcSDimitry Andric 
570eae32dcSDimitry Andric to_chars_result to_chars(char* __first, char* __last, long double __value, chars_format __fmt) {
58*cb14a3feSDimitry Andric   return _Floating_to_chars<_Floating_to_chars_overload::_Format_only>(
59*cb14a3feSDimitry Andric       __first, __last, static_cast<double>(__value), __fmt, 0);
600eae32dcSDimitry Andric }
610eae32dcSDimitry Andric 
620eae32dcSDimitry Andric to_chars_result to_chars(char* __first, char* __last, float __value, chars_format __fmt, int __precision) {
63*cb14a3feSDimitry Andric   return _Floating_to_chars<_Floating_to_chars_overload::_Format_precision>(
64*cb14a3feSDimitry Andric       __first, __last, __value, __fmt, __precision);
650eae32dcSDimitry Andric }
660eae32dcSDimitry Andric 
670eae32dcSDimitry Andric to_chars_result to_chars(char* __first, char* __last, double __value, chars_format __fmt, int __precision) {
68*cb14a3feSDimitry Andric   return _Floating_to_chars<_Floating_to_chars_overload::_Format_precision>(
69*cb14a3feSDimitry Andric       __first, __last, __value, __fmt, __precision);
700eae32dcSDimitry Andric }
710eae32dcSDimitry Andric 
720eae32dcSDimitry Andric to_chars_result to_chars(char* __first, char* __last, long double __value, chars_format __fmt, int __precision) {
730eae32dcSDimitry Andric   return _Floating_to_chars<_Floating_to_chars_overload::_Format_precision>(
740eae32dcSDimitry Andric       __first, __last, static_cast<double>(__value), __fmt, __precision);
750eae32dcSDimitry Andric }
760eae32dcSDimitry Andric 
770b57cec5SDimitry Andric _LIBCPP_END_NAMESPACE_STD
78