mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 13:54:21 +00:00
See: * https://discourse.llvm.org/t/rfc-freezing-c-03-headers-in-libc/77319 * https://discourse.llvm.org/t/rfc-project-hand-in-hand-llvm-libc-libc-code-sharing/77701 We're dropping support for C++03 for Zig due to the first change; it would be insane to ship 1018 duplicate header files just for this outdated use case. As a result of the second change, I had to bring in a subset of the headers from llvm-libc since libc++ now depends on these. Hopefully we can continue to get away with not copying the entirety of llvm-libc.
89 lines
3.7 KiB
C++
Vendored
89 lines
3.7 KiB
C++
Vendored
//===----------------------------------------------------------------------===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include <charconv>
|
|
#include <string.h>
|
|
|
|
#include "include/from_chars_floating_point.h"
|
|
#include "include/to_chars_floating_point.h"
|
|
|
|
_LIBCPP_BEGIN_NAMESPACE_STD
|
|
|
|
#ifndef _LIBCPP_ABI_DO_NOT_EXPORT_TO_CHARS_BASE_10
|
|
|
|
namespace __itoa {
|
|
|
|
_LIBCPP_EXPORTED_FROM_ABI char* __u32toa(uint32_t value, char* buffer) noexcept { return __base_10_u32(buffer, value); }
|
|
|
|
_LIBCPP_EXPORTED_FROM_ABI char* __u64toa(uint64_t value, char* buffer) noexcept { return __base_10_u64(buffer, value); }
|
|
|
|
} // namespace __itoa
|
|
|
|
#endif // _LIBCPP_ABI_DO_NOT_EXPORT_TO_CHARS_BASE_10
|
|
|
|
// The original version of floating-point to_chars was written by Microsoft and
|
|
// contributed with the following license.
|
|
|
|
// Copyright (c) Microsoft Corporation.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
|
|
// This implementation is dedicated to the memory of Mary and Thavatchai.
|
|
|
|
to_chars_result to_chars(char* __first, char* __last, float __value) {
|
|
return _Floating_to_chars<_Floating_to_chars_overload::_Plain>(__first, __last, __value, chars_format{}, 0);
|
|
}
|
|
|
|
to_chars_result to_chars(char* __first, char* __last, double __value) {
|
|
return _Floating_to_chars<_Floating_to_chars_overload::_Plain>(__first, __last, __value, chars_format{}, 0);
|
|
}
|
|
|
|
to_chars_result to_chars(char* __first, char* __last, long double __value) {
|
|
return _Floating_to_chars<_Floating_to_chars_overload::_Plain>(
|
|
__first, __last, static_cast<double>(__value), chars_format{}, 0);
|
|
}
|
|
|
|
to_chars_result to_chars(char* __first, char* __last, float __value, chars_format __fmt) {
|
|
return _Floating_to_chars<_Floating_to_chars_overload::_Format_only>(__first, __last, __value, __fmt, 0);
|
|
}
|
|
|
|
to_chars_result to_chars(char* __first, char* __last, double __value, chars_format __fmt) {
|
|
return _Floating_to_chars<_Floating_to_chars_overload::_Format_only>(__first, __last, __value, __fmt, 0);
|
|
}
|
|
|
|
to_chars_result to_chars(char* __first, char* __last, long double __value, chars_format __fmt) {
|
|
return _Floating_to_chars<_Floating_to_chars_overload::_Format_only>(
|
|
__first, __last, static_cast<double>(__value), __fmt, 0);
|
|
}
|
|
|
|
to_chars_result to_chars(char* __first, char* __last, float __value, chars_format __fmt, int __precision) {
|
|
return _Floating_to_chars<_Floating_to_chars_overload::_Format_precision>(
|
|
__first, __last, __value, __fmt, __precision);
|
|
}
|
|
|
|
to_chars_result to_chars(char* __first, char* __last, double __value, chars_format __fmt, int __precision) {
|
|
return _Floating_to_chars<_Floating_to_chars_overload::_Format_precision>(
|
|
__first, __last, __value, __fmt, __precision);
|
|
}
|
|
|
|
to_chars_result to_chars(char* __first, char* __last, long double __value, chars_format __fmt, int __precision) {
|
|
return _Floating_to_chars<_Floating_to_chars_overload::_Format_precision>(
|
|
__first, __last, static_cast<double>(__value), __fmt, __precision);
|
|
}
|
|
|
|
template <class _Fp>
|
|
__from_chars_result<_Fp> __from_chars_floating_point(
|
|
_LIBCPP_NOESCAPE const char* __first, _LIBCPP_NOESCAPE const char* __last, chars_format __fmt) {
|
|
return std::__from_chars_floating_point_impl<_Fp>(__first, __last, __fmt);
|
|
}
|
|
|
|
template __from_chars_result<float> __from_chars_floating_point(
|
|
_LIBCPP_NOESCAPE const char* __first, _LIBCPP_NOESCAPE const char* __last, chars_format __fmt);
|
|
|
|
template __from_chars_result<double> __from_chars_floating_point(
|
|
_LIBCPP_NOESCAPE const char* __first, _LIBCPP_NOESCAPE const char* __last, chars_format __fmt);
|
|
_LIBCPP_END_NAMESPACE_STD
|