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