mirror of
https://github.com/fastfloat/fast_float.git
synced 2025-12-06 16:56:57 +08:00
more fixes
This commit is contained in:
parent
4dcbd30d3f
commit
a0ea962bf5
@ -7,7 +7,11 @@
|
|||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
#include <system_error>
|
#include <system_error>
|
||||||
|
#ifdef __has_include
|
||||||
|
#if __has_include(<stdfloat>)
|
||||||
|
#include <stdfloat>
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
#include "constexpr_feature_detect.h"
|
#include "constexpr_feature_detect.h"
|
||||||
|
|
||||||
namespace fast_float {
|
namespace fast_float {
|
||||||
@ -188,7 +192,14 @@ fastfloat_really_inline constexpr bool cpp20_and_in_constexpr() {
|
|||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
fastfloat_really_inline constexpr bool is_supported_float_type() {
|
fastfloat_really_inline constexpr bool is_supported_float_type() {
|
||||||
return std::is_same<T, float>::value || std::is_same<T, double>::value;
|
return std::is_same<T, float>::value || std::is_same<T, double>::value
|
||||||
|
#if __STDCPP_FLOAT32_T__
|
||||||
|
|| std::is_same<T, std::float32_t>::value
|
||||||
|
#endif
|
||||||
|
#if __STDCPP_FLOAT64_T__
|
||||||
|
|| std::is_same<T, std::float64_t>::value
|
||||||
|
#endif
|
||||||
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename UC>
|
template <typename UC>
|
||||||
|
|||||||
@ -10,11 +10,6 @@
|
|||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
#include <system_error>
|
#include <system_error>
|
||||||
#ifdef __has_include
|
|
||||||
#if __has_include(<stdfloat>)
|
|
||||||
#include <stdfloat>
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
namespace fast_float {
|
namespace fast_float {
|
||||||
|
|
||||||
|
|
||||||
@ -189,6 +184,7 @@ template<typename T, typename UC, typename>
|
|||||||
FASTFLOAT_CONSTEXPR20
|
FASTFLOAT_CONSTEXPR20
|
||||||
from_chars_result_t<UC> from_chars(UC const * first, UC const * last,
|
from_chars_result_t<UC> from_chars(UC const * first, UC const * last,
|
||||||
T &value, chars_format fmt /*= chars_format::general*/) noexcept {
|
T &value, chars_format fmt /*= chars_format::general*/) noexcept {
|
||||||
|
printf("from_chars to call\n");
|
||||||
return from_chars_caller<T>::call(first, last, value, parse_options_t<UC>(fmt));
|
return from_chars_caller<T>::call(first, last, value, parse_options_t<UC>(fmt));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -197,7 +193,7 @@ FASTFLOAT_CONSTEXPR20
|
|||||||
from_chars_result_t<UC> from_chars_advanced(UC const * first, UC const * last,
|
from_chars_result_t<UC> from_chars_advanced(UC const * first, UC const * last,
|
||||||
T &value, parse_options_t<UC> options) noexcept {
|
T &value, parse_options_t<UC> options) noexcept {
|
||||||
|
|
||||||
static_assert (is_supported_float_type<T>(), "only float and double are supported");
|
static_assert (is_supported_float_type<T>(), "only some floating-point types are supported");
|
||||||
static_assert (is_supported_char_type<UC>(), "only char, wchar_t, char16_t and char32_t are supported");
|
static_assert (is_supported_char_type<UC>(), "only char, wchar_t, char16_t and char32_t are supported");
|
||||||
|
|
||||||
from_chars_result_t<UC> answer;
|
from_chars_result_t<UC> answer;
|
||||||
|
|||||||
@ -12,7 +12,7 @@ int main() {
|
|||||||
#if __STDCPP_FLOAT32_T__
|
#if __STDCPP_FLOAT32_T__
|
||||||
const std::vector<std::float32_t> float32_test_expected{123.456f, -78.9f, 0.0001f, 3.40282e+038f};
|
const std::vector<std::float32_t> float32_test_expected{123.456f, -78.9f, 0.0001f, 3.40282e+038f};
|
||||||
const std::vector<std::string_view> float32_test{"123.456", "-78.9", "0.0001", "3.40282e+038"};
|
const std::vector<std::string_view> float32_test{"123.456", "-78.9", "0.0001", "3.40282e+038"};
|
||||||
|
std::cout << "runing float32 test" << std::endl;
|
||||||
for (std::size_t i = 0; i < float32_test.size(); ++i) {
|
for (std::size_t i = 0; i < float32_test.size(); ++i) {
|
||||||
const auto& f = float32_test[i];
|
const auto& f = float32_test[i];
|
||||||
std::float32_t result;
|
std::float32_t result;
|
||||||
@ -35,7 +35,7 @@ int main() {
|
|||||||
// Test cases for std::float64_t
|
// Test cases for std::float64_t
|
||||||
const std::vector<std::float64_t> float64_test_expected{1.23e4, -5.67e-8, 1.7976931348623157e+308, -1.7976931348623157e+308};
|
const std::vector<std::float64_t> float64_test_expected{1.23e4, -5.67e-8, 1.7976931348623157e+308, -1.7976931348623157e+308};
|
||||||
const std::vector<std::string_view> float64_test{"1.23e4", "-5.67e-8", "1.7976931348623157e+308", "-1.7976931348623157e+308"};
|
const std::vector<std::string_view> float64_test{"1.23e4", "-5.67e-8", "1.7976931348623157e+308", "-1.7976931348623157e+308"};
|
||||||
|
std::cout << "runing float64 test" << std::endl;
|
||||||
for (std::size_t i = 0; i < float64_test.size(); ++i) {
|
for (std::size_t i = 0; i < float64_test.size(); ++i) {
|
||||||
const auto& f = float64_test[i];
|
const auto& f = float64_test[i];
|
||||||
std::float64_t result;
|
std::float64_t result;
|
||||||
@ -45,8 +45,8 @@ int main() {
|
|||||||
std::cerr << "Failed to parse: \"" << f << "\"" << std::endl;
|
std::cerr << "Failed to parse: \"" << f << "\"" << std::endl;
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
if(result != float32_test_expected[i]) {
|
if(result != float64_test_expected[i]) {
|
||||||
std::cerr << "Test failed for input: \"" << f << "\" expected " << float32_test_expected[i] << " got " << result << std::endl;
|
std::cerr << "Test failed for input: \"" << f << "\" expected " << float64_test_expected[i] << " got " << result << std::endl;
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user