Skip to content

Commit

Permalink
more fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Lemire committed Jan 28, 2024
1 parent 4dcbd30 commit a0ea962
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
15 changes: 13 additions & 2 deletions include/fast_float/float_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
#include <cstring>
#include <type_traits>
#include <system_error>

#ifdef __has_include
#if __has_include(<stdfloat>)
#include <stdfloat>
#endif
#endif
#include "constexpr_feature_detect.h"

namespace fast_float {
Expand Down Expand Up @@ -188,7 +192,14 @@ fastfloat_really_inline constexpr bool cpp20_and_in_constexpr() {

template <typename T>
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>
Expand Down
8 changes: 2 additions & 6 deletions include/fast_float/parse_number.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@
#include <cstring>
#include <limits>
#include <system_error>
#ifdef __has_include
#if __has_include(<stdfloat>)
#include <stdfloat>
#endif
#endif
namespace fast_float {


Expand Down Expand Up @@ -189,6 +184,7 @@ template<typename T, typename UC, typename>
FASTFLOAT_CONSTEXPR20
from_chars_result_t<UC> from_chars(UC const * first, UC const * last,
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));
}

Expand All @@ -197,7 +193,7 @@ FASTFLOAT_CONSTEXPR20
from_chars_result_t<UC> from_chars_advanced(UC const * first, UC const * last,
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");

from_chars_result_t<UC> answer;
Expand Down
8 changes: 4 additions & 4 deletions tests/fixedwidthtest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ int main() {
#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::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) {
const auto& f = float32_test[i];
std::float32_t result;
Expand All @@ -35,7 +35,7 @@ int main() {
// 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::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) {
const auto& f = float64_test[i];
std::float64_t result;
Expand All @@ -45,8 +45,8 @@ int main() {
std::cerr << "Failed to parse: \"" << f << "\"" << std::endl;
return EXIT_FAILURE;
}
if(result != float32_test_expected[i]) {
std::cerr << "Test failed for input: \"" << f << "\" expected " << float32_test_expected[i] << " got " << result << std::endl;
if(result != float64_test_expected[i]) {
std::cerr << "Test failed for input: \"" << f << "\" expected " << float64_test_expected[i] << " got " << result << std::endl;
return EXIT_FAILURE;
}
}
Expand Down

0 comments on commit a0ea962

Please sign in to comment.