Skip to content

Commit

Permalink
Merge pull request fastfloat#237 from fastfloat/release610_candidate
Browse files Browse the repository at this point in the history
preparing version 6.1.0
  • Loading branch information
lemire committed Jan 28, 2024
2 parents fade235 + 797e3e0 commit 8378916
Show file tree
Hide file tree
Showing 9 changed files with 105 additions and 77 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
cmake_minimum_required(VERSION 3.9)

project(fast_float VERSION 6.0.0 LANGUAGES CXX)
set(FASTFLOAT_CXX_STANDARD 11 CACHE STRING "the C++ standard to use for fastfloat")
set(CMAKE_CXX_STANDARD ${FASTFLOAT_CXX_STANDARD})
option(FASTFLOAT_TEST "Enable tests" OFF)
if(FASTFLOAT_TEST)
enable_testing()
Expand Down
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,16 @@ constexpr double constexptest() {
}
```
## C++23: Fixed width floating-point types
The library also supports fixed-width floating-point types such as `std::float32_t` and `std::float64_t`. E.g., you can write:
```C++
std::float32_t result;
auto answer = fast_float::from_chars(f.data(), f.data() + f.size(), result);
``````


## Non-ASCII Inputs

We also support UTF-16 and UTF-32 inputs, as well as ASCII/UTF-8, as in the following example:
Expand Down Expand Up @@ -371,7 +381,7 @@ the command line help.

You may directly download automatically generated single-header files:

https://github.com/fastfloat/fast_float/releases/download/v6.0.0/fast_float.h
https://github.com/fastfloat/fast_float/releases/download/v6.1.0/fast_float.h

## RFC 7159

Expand Down
4 changes: 2 additions & 2 deletions include/fast_float/ascii_number.h
Original file line number Diff line number Diff line change
Expand Up @@ -529,8 +529,8 @@ from_chars_result_t<UC> parse_int_string(UC const* p, UC const* pend, T& value,
// this weird workaround is required because:
// - converting unsigned to signed when its value is greater than signed max is UB pre-C++23.
// - reinterpret_casting (~i + 1) would work, but it is not constexpr
// this is always optimized into a neg instruction.
value = T(-std::numeric_limits<T>::max() - T(i - std::numeric_limits<T>::max()));
// this is always optimized into a neg instruction (note: T is an integer type)
value = T(-std::numeric_limits<T>::max() - T(i - uint64_t(std::numeric_limits<T>::max())));
#ifdef FASTFLOAT_VISUAL_STUDIO
#pragma warning(pop)
#endif
Expand Down
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 @@ -186,6 +181,7 @@ struct from_chars_caller<std::float64_t>


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 {
return from_chars_caller<T>::call(first, last, value, parse_options_t<UC>(fmt));
Expand All @@ -196,7 +192,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
9 changes: 6 additions & 3 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,14 @@ fast_float_add_cpp_test(fast_int)
target_compile_features(fast_int PRIVATE cxx_std_17)
fast_float_add_cpp_test(json_fmt)
fast_float_add_cpp_test(fortran)

option(FASTFLOAT_FIXEDWIDTH_TESTS "Require fixed width test for C++23 (build will fail if the compiler won't support it)" OFF)
if(CMAKE_CXX_STANDARD GREATER_EQUAL 23)
option(FASTFLOAT_FIXEDWIDTH_TESTS "Require fixed width test for C++23 (build will fail if the compiler won't support it)" ON)
else()
option(FASTFLOAT_FIXEDWIDTH_TESTS "Require fixed width test for C++23 (build will fail if the compiler won't support it)" OFF)
endif()
if (FASTFLOAT_FIXEDWIDTH_TESTS)
fast_float_add_cpp_test(fixedwidthtest)
target_compile_features(fixedwidthtest PRIVATE cxx_std_23)
target_compile_features(fixedwidthtest PUBLIC cxx_std_23)
endif()

option(FASTFLOAT_EXHAUSTIVE "Exhaustive tests" OFF)
Expand Down

0 comments on commit 8378916

Please sign in to comment.