Path: blob/main/system/lib/libcxx/src/charconv.cpp
6175 views
//===----------------------------------------------------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#include <charconv>9#include <string.h>1011#include "include/from_chars_floating_point.h"12#include "include/to_chars_floating_point.h"1314_LIBCPP_BEGIN_NAMESPACE_STD1516#ifndef _LIBCPP_ABI_DO_NOT_EXPORT_TO_CHARS_BASE_101718namespace __itoa {1920_LIBCPP_EXPORTED_FROM_ABI char* __u32toa(uint32_t value, char* buffer) noexcept { return __base_10_u32(buffer, value); }2122_LIBCPP_EXPORTED_FROM_ABI char* __u64toa(uint64_t value, char* buffer) noexcept { return __base_10_u64(buffer, value); }2324} // namespace __itoa2526#endif // _LIBCPP_ABI_DO_NOT_EXPORT_TO_CHARS_BASE_102728// The original version of floating-point to_chars was written by Microsoft and29// contributed with the following license.3031// Copyright (c) Microsoft Corporation.32// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception3334// This implementation is dedicated to the memory of Mary and Thavatchai.3536to_chars_result to_chars(char* __first, char* __last, float __value) {37return _Floating_to_chars<_Floating_to_chars_overload::_Plain>(__first, __last, __value, chars_format{}, 0);38}3940to_chars_result to_chars(char* __first, char* __last, double __value) {41return _Floating_to_chars<_Floating_to_chars_overload::_Plain>(__first, __last, __value, chars_format{}, 0);42}4344to_chars_result to_chars(char* __first, char* __last, long double __value) {45return _Floating_to_chars<_Floating_to_chars_overload::_Plain>(46__first, __last, static_cast<double>(__value), chars_format{}, 0);47}4849to_chars_result to_chars(char* __first, char* __last, float __value, chars_format __fmt) {50return _Floating_to_chars<_Floating_to_chars_overload::_Format_only>(__first, __last, __value, __fmt, 0);51}5253to_chars_result to_chars(char* __first, char* __last, double __value, chars_format __fmt) {54return _Floating_to_chars<_Floating_to_chars_overload::_Format_only>(__first, __last, __value, __fmt, 0);55}5657to_chars_result to_chars(char* __first, char* __last, long double __value, chars_format __fmt) {58return _Floating_to_chars<_Floating_to_chars_overload::_Format_only>(59__first, __last, static_cast<double>(__value), __fmt, 0);60}6162to_chars_result to_chars(char* __first, char* __last, float __value, chars_format __fmt, int __precision) {63return _Floating_to_chars<_Floating_to_chars_overload::_Format_precision>(64__first, __last, __value, __fmt, __precision);65}6667to_chars_result to_chars(char* __first, char* __last, double __value, chars_format __fmt, int __precision) {68return _Floating_to_chars<_Floating_to_chars_overload::_Format_precision>(69__first, __last, __value, __fmt, __precision);70}7172to_chars_result to_chars(char* __first, char* __last, long double __value, chars_format __fmt, int __precision) {73return _Floating_to_chars<_Floating_to_chars_overload::_Format_precision>(74__first, __last, static_cast<double>(__value), __fmt, __precision);75}7677template <class _Fp>78__from_chars_result<_Fp> __from_chars_floating_point(79_LIBCPP_NOESCAPE const char* __first, _LIBCPP_NOESCAPE const char* __last, chars_format __fmt) {80return std::__from_chars_floating_point_impl<_Fp>(__first, __last, __fmt);81}8283template __from_chars_result<float> __from_chars_floating_point(84_LIBCPP_NOESCAPE const char* __first, _LIBCPP_NOESCAPE const char* __last, chars_format __fmt);8586template __from_chars_result<double> __from_chars_floating_point(87_LIBCPP_NOESCAPE const char* __first, _LIBCPP_NOESCAPE const char* __last, chars_format __fmt);88_LIBCPP_END_NAMESPACE_STD899091