xref: /freebsd/contrib/llvm-project/libcxx/src/charconv.cpp (revision cb14a3fe5122c879eae1fb480ed7ce82a699ddb6)
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/to_chars_floating_point.h"
13 
14 _LIBCPP_BEGIN_NAMESPACE_STD
15 
16 #ifndef _LIBCPP_ABI_DO_NOT_EXPORT_TO_CHARS_BASE_10
17 
18 namespace __itoa {
19 
20 _LIBCPP_EXPORTED_FROM_ABI char* __u32toa(uint32_t value, char* buffer) noexcept { return __base_10_u32(buffer, value); }
21 
22 _LIBCPP_EXPORTED_FROM_ABI char* __u64toa(uint64_t value, char* buffer) noexcept { return __base_10_u64(buffer, value); }
23 
24 } // namespace __itoa
25 
26 #endif // _LIBCPP_ABI_DO_NOT_EXPORT_TO_CHARS_BASE_10
27 
28 // The original version of floating-point to_chars was written by Microsoft and
29 // contributed with the following license.
30 
31 // Copyright (c) Microsoft Corporation.
32 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
33 
34 // This implementation is dedicated to the memory of Mary and Thavatchai.
35 
36 to_chars_result to_chars(char* __first, char* __last, float __value) {
37   return _Floating_to_chars<_Floating_to_chars_overload::_Plain>(__first, __last, __value, chars_format{}, 0);
38 }
39 
40 to_chars_result to_chars(char* __first, char* __last, double __value) {
41   return _Floating_to_chars<_Floating_to_chars_overload::_Plain>(__first, __last, __value, chars_format{}, 0);
42 }
43 
44 to_chars_result to_chars(char* __first, char* __last, long double __value) {
45   return _Floating_to_chars<_Floating_to_chars_overload::_Plain>(
46       __first, __last, static_cast<double>(__value), chars_format{}, 0);
47 }
48 
49 to_chars_result to_chars(char* __first, char* __last, float __value, chars_format __fmt) {
50   return _Floating_to_chars<_Floating_to_chars_overload::_Format_only>(__first, __last, __value, __fmt, 0);
51 }
52 
53 to_chars_result to_chars(char* __first, char* __last, double __value, chars_format __fmt) {
54   return _Floating_to_chars<_Floating_to_chars_overload::_Format_only>(__first, __last, __value, __fmt, 0);
55 }
56 
57 to_chars_result to_chars(char* __first, char* __last, long double __value, chars_format __fmt) {
58   return _Floating_to_chars<_Floating_to_chars_overload::_Format_only>(
59       __first, __last, static_cast<double>(__value), __fmt, 0);
60 }
61 
62 to_chars_result to_chars(char* __first, char* __last, float __value, chars_format __fmt, int __precision) {
63   return _Floating_to_chars<_Floating_to_chars_overload::_Format_precision>(
64       __first, __last, __value, __fmt, __precision);
65 }
66 
67 to_chars_result to_chars(char* __first, char* __last, double __value, chars_format __fmt, int __precision) {
68   return _Floating_to_chars<_Floating_to_chars_overload::_Format_precision>(
69       __first, __last, __value, __fmt, __precision);
70 }
71 
72 to_chars_result to_chars(char* __first, char* __last, long double __value, chars_format __fmt, int __precision) {
73   return _Floating_to_chars<_Floating_to_chars_overload::_Format_precision>(
74       __first, __last, static_cast<double>(__value), __fmt, __precision);
75 }
76 
77 _LIBCPP_END_NAMESPACE_STD
78