blob: d01ecddc466015da2a870e27445f90ac85bf2efc [file] [log] [blame]
Louis Dionne9bd93882021-11-17 16:25:01 -05001//===----------------------------------------------------------------------===//
Zhihao Yuan7bf19052018-08-01 02:38:30 +00002//
Chandler Carruthd2012102019-01-19 10:56:40 +00003// 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
Zhihao Yuan7bf19052018-08-01 02:38:30 +00006//
7//===----------------------------------------------------------------------===//
8
Arthur O'Dwyercf9bf392022-02-11 13:00:39 -05009#include <charconv>
Zhihao Yuan7bf19052018-08-01 02:38:30 +000010#include <string.h>
11
Mark de Weverfa36ec72021-02-09 17:52:41 +010012#include "include/to_chars_floating_point.h"
13
Zhihao Yuan7bf19052018-08-01 02:38:30 +000014_LIBCPP_BEGIN_NAMESPACE_STD
15
Mark de Wever35560902022-05-16 18:48:04 +020016#ifndef _LIBCPP_ABI_DO_NOT_EXPORT_TO_CHARS_BASE_10
17
Zhihao Yuan7bf19052018-08-01 02:38:30 +000018namespace __itoa
19{
20
Mark de Wevercc283772022-05-16 17:12:18 +020021_LIBCPP_FUNC_VIS char*
Louis Dionne65358e12021-03-01 12:09:45 -050022__u32toa(uint32_t value, char* buffer) noexcept
Zhihao Yuan7bf19052018-08-01 02:38:30 +000023{
Louis Dionne60c266d2022-08-18 17:41:13 -040024 return __base_10_u32(buffer, value);
Zhihao Yuan7bf19052018-08-01 02:38:30 +000025}
26
Mark de Wevercc283772022-05-16 17:12:18 +020027_LIBCPP_FUNC_VIS char*
Louis Dionne65358e12021-03-01 12:09:45 -050028__u64toa(uint64_t value, char* buffer) noexcept
Zhihao Yuan7bf19052018-08-01 02:38:30 +000029{
Louis Dionne60c266d2022-08-18 17:41:13 -040030 return __base_10_u64(buffer, value);
Zhihao Yuan7bf19052018-08-01 02:38:30 +000031}
32
33} // namespace __itoa
34
Mark de Wever35560902022-05-16 18:48:04 +020035#endif // _LIBCPP_ABI_DO_NOT_EXPORT_TO_CHARS_BASE_10
36
Mark de Weverfa36ec72021-02-09 17:52:41 +010037// The original version of floating-point to_chars was written by Microsoft and
38// contributed with the following license.
39
40// Copyright (c) Microsoft Corporation.
41// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
42
43// This implementation is dedicated to the memory of Mary and Thavatchai.
44
45to_chars_result to_chars(char* __first, char* __last, float __value) {
46 return _Floating_to_chars<_Floating_to_chars_overload::_Plain>(__first, __last, __value, chars_format{}, 0);
47}
48
49to_chars_result to_chars(char* __first, char* __last, double __value) {
50 return _Floating_to_chars<_Floating_to_chars_overload::_Plain>(__first, __last, __value, chars_format{}, 0);
51}
52
53to_chars_result to_chars(char* __first, char* __last, long double __value) {
54 return _Floating_to_chars<_Floating_to_chars_overload::_Plain>(__first, __last, static_cast<double>(__value),
55 chars_format{}, 0);
56}
57
58to_chars_result to_chars(char* __first, char* __last, float __value, chars_format __fmt) {
59 return _Floating_to_chars<_Floating_to_chars_overload::_Format_only>(__first, __last, __value, __fmt, 0);
60}
61
62to_chars_result to_chars(char* __first, char* __last, double __value, chars_format __fmt) {
63 return _Floating_to_chars<_Floating_to_chars_overload::_Format_only>(__first, __last, __value, __fmt, 0);
64}
65
66to_chars_result to_chars(char* __first, char* __last, long double __value, chars_format __fmt) {
67 return _Floating_to_chars<_Floating_to_chars_overload::_Format_only>(__first, __last, static_cast<double>(__value),
68 __fmt, 0);
69}
70
71to_chars_result to_chars(char* __first, char* __last, float __value, chars_format __fmt, int __precision) {
72 return _Floating_to_chars<_Floating_to_chars_overload::_Format_precision>(__first, __last, __value, __fmt,
73 __precision);
74}
75
76to_chars_result to_chars(char* __first, char* __last, double __value, chars_format __fmt, int __precision) {
77 return _Floating_to_chars<_Floating_to_chars_overload::_Format_precision>(__first, __last, __value, __fmt,
78 __precision);
79}
80
81to_chars_result to_chars(char* __first, char* __last, long double __value, chars_format __fmt, int __precision) {
82 return _Floating_to_chars<_Floating_to_chars_overload::_Format_precision>(
83 __first, __last, static_cast<double>(__value), __fmt, __precision);
84}
85
Zhihao Yuan7bf19052018-08-01 02:38:30 +000086_LIBCPP_END_NAMESPACE_STD