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 9*81ad6265SDimitry 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 16*81ad6265SDimitry Andric #ifndef _LIBCPP_ABI_DO_NOT_EXPORT_TO_CHARS_BASE_10 17*81ad6265SDimitry Andric 180b57cec5SDimitry Andric namespace __itoa 190b57cec5SDimitry Andric { 200b57cec5SDimitry Andric 21*81ad6265SDimitry Andric _LIBCPP_FUNC_VIS char* 22fe6060f1SDimitry Andric __u32toa(uint32_t value, char* buffer) noexcept 230b57cec5SDimitry Andric { 24*81ad6265SDimitry Andric return __base_10_u32(buffer, value); 250b57cec5SDimitry Andric } 260b57cec5SDimitry Andric 27*81ad6265SDimitry Andric _LIBCPP_FUNC_VIS char* 28fe6060f1SDimitry Andric __u64toa(uint64_t value, char* buffer) noexcept 290b57cec5SDimitry Andric { 30*81ad6265SDimitry Andric return __base_10_u64(buffer, value); 310b57cec5SDimitry Andric } 320b57cec5SDimitry Andric 330b57cec5SDimitry Andric } // namespace __itoa 340b57cec5SDimitry Andric 35*81ad6265SDimitry Andric #endif // _LIBCPP_ABI_DO_NOT_EXPORT_TO_CHARS_BASE_10 36*81ad6265SDimitry Andric 370eae32dcSDimitry Andric // The original version of floating-point to_chars was written by Microsoft and 380eae32dcSDimitry Andric // contributed with the following license. 390eae32dcSDimitry Andric 400eae32dcSDimitry Andric // Copyright (c) Microsoft Corporation. 410eae32dcSDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 420eae32dcSDimitry Andric 430eae32dcSDimitry Andric // This implementation is dedicated to the memory of Mary and Thavatchai. 440eae32dcSDimitry Andric 450eae32dcSDimitry Andric to_chars_result to_chars(char* __first, char* __last, float __value) { 460eae32dcSDimitry Andric return _Floating_to_chars<_Floating_to_chars_overload::_Plain>(__first, __last, __value, chars_format{}, 0); 470eae32dcSDimitry Andric } 480eae32dcSDimitry Andric 490eae32dcSDimitry Andric to_chars_result to_chars(char* __first, char* __last, double __value) { 500eae32dcSDimitry Andric return _Floating_to_chars<_Floating_to_chars_overload::_Plain>(__first, __last, __value, chars_format{}, 0); 510eae32dcSDimitry Andric } 520eae32dcSDimitry Andric 530eae32dcSDimitry Andric to_chars_result to_chars(char* __first, char* __last, long double __value) { 540eae32dcSDimitry Andric return _Floating_to_chars<_Floating_to_chars_overload::_Plain>(__first, __last, static_cast<double>(__value), 550eae32dcSDimitry Andric chars_format{}, 0); 560eae32dcSDimitry Andric } 570eae32dcSDimitry Andric 580eae32dcSDimitry Andric to_chars_result to_chars(char* __first, char* __last, float __value, chars_format __fmt) { 590eae32dcSDimitry Andric return _Floating_to_chars<_Floating_to_chars_overload::_Format_only>(__first, __last, __value, __fmt, 0); 600eae32dcSDimitry Andric } 610eae32dcSDimitry Andric 620eae32dcSDimitry Andric to_chars_result to_chars(char* __first, char* __last, double __value, chars_format __fmt) { 630eae32dcSDimitry Andric return _Floating_to_chars<_Floating_to_chars_overload::_Format_only>(__first, __last, __value, __fmt, 0); 640eae32dcSDimitry Andric } 650eae32dcSDimitry Andric 660eae32dcSDimitry Andric to_chars_result to_chars(char* __first, char* __last, long double __value, chars_format __fmt) { 670eae32dcSDimitry Andric return _Floating_to_chars<_Floating_to_chars_overload::_Format_only>(__first, __last, static_cast<double>(__value), 680eae32dcSDimitry Andric __fmt, 0); 690eae32dcSDimitry Andric } 700eae32dcSDimitry Andric 710eae32dcSDimitry Andric to_chars_result to_chars(char* __first, char* __last, float __value, chars_format __fmt, int __precision) { 720eae32dcSDimitry Andric return _Floating_to_chars<_Floating_to_chars_overload::_Format_precision>(__first, __last, __value, __fmt, 730eae32dcSDimitry Andric __precision); 740eae32dcSDimitry Andric } 750eae32dcSDimitry Andric 760eae32dcSDimitry Andric to_chars_result to_chars(char* __first, char* __last, double __value, chars_format __fmt, int __precision) { 770eae32dcSDimitry Andric return _Floating_to_chars<_Floating_to_chars_overload::_Format_precision>(__first, __last, __value, __fmt, 780eae32dcSDimitry Andric __precision); 790eae32dcSDimitry Andric } 800eae32dcSDimitry Andric 810eae32dcSDimitry Andric to_chars_result to_chars(char* __first, char* __last, long double __value, chars_format __fmt, int __precision) { 820eae32dcSDimitry Andric return _Floating_to_chars<_Floating_to_chars_overload::_Format_precision>( 830eae32dcSDimitry Andric __first, __last, static_cast<double>(__value), __fmt, __precision); 840eae32dcSDimitry Andric } 850eae32dcSDimitry Andric 860b57cec5SDimitry Andric _LIBCPP_END_NAMESPACE_STD 87