195 Commits

Author SHA1 Message Date
Daniel Lemire
5334e2ba94 fix 2024-01-28 10:55:02 -05:00
Daniel Lemire
1d97749791 Verify and fix issue 235 2024-01-28 10:47:21 -05:00
Daniel Lemire
620376ad39
Merge branch 'main' into main 2024-01-28 10:09:56 -05:00
Daniel Lemire
f320619216
Merge pull request #227 from fastfloat/extra_test
adding a single test
2024-01-28 10:08:49 -05:00
StefanBruens
7f46adc19c Make tests depending on supplemental_test_files optional
As the supplemental_test_files are quite large, it is useful to make
running the tests depending on it optional.

By default, the tests are kept enabled, but can be switched of by setting
`FASTFLOAT_SUPPLEMENTAL_TEST=OFF`.

Fixes: #232
2023-12-26 02:23:30 +01:00
TheRandomGuy146275
26a5b2eb16 Added test case for ignoring leading zeros for all bases
- added: fix incorrect base for leading zeros test

---------

Co-authored-by: Marvin <marvin.wu@mail.utoronto.ca>
Co-authored-by: Maya Warrier <34803055+mayawarrier@users.noreply.github.com>
2023-12-13 17:22:51 -05:00
MTahaK
96c0059fe9 Revised implementation of float32_t and float64_t support as template specializations, added test 2023-12-13 00:33:16 -05:00
Maya Warrier
30b3165520 Fix fast_int test Werrors 2023-12-12 22:45:14 -05:00
Maya Warrier
01e8c50a33 Fix bugs in tests/fast_int.cpp 2023-12-12 22:35:34 -05:00
Maya Warrier
5fcc62a6f5 Merge contributed tests 2023-12-12 22:03:33 -05:00
Marvin
ebc15bec51 Added test case for numbers within range after converted from base 2023-12-12 20:20:05 -05:00
Marvin
0711006266 Fixed messages 2023-12-12 19:23:43 -05:00
MTahaK
ae99db48e6 Updated CMakeLists with new option for C++23 fixed width tests, added new basic fixedwidthtest file. 2023-12-12 19:19:06 -05:00
Marvin
681eb1ea38 More details to basic test error for debugging 2023-12-12 19:18:07 -05:00
Marvin
5fda2cc240 Debugging results 2023-12-12 19:07:51 -05:00
MTahaK
f330ec1e9d Reverted CMakeLists changes, modifed workflow for g++13 & C++23. 2023-12-12 18:59:59 -05:00
MTahaK
b0f4535781 Update test/CMakeLists.txt to use C++23 for fixed-width float types 2023-12-12 18:11:09 -05:00
TheRandomGuy146275
e4702e039f Fixing cmake errrors 2023-12-12 17:58:32 -05:00
Marvin
20c9375c5e Added new test cases for out of range errors that cover 8,16,32,64 bits, out of range errors for all bases (64 bit only), and fixed some test cases 2023-12-12 13:59:18 -05:00
Marvin
e60b47455b Added test cases that coverunsigned, out or range errors, char pointers, invalid bases, and out of range bases 2023-12-11 18:17:33 -05:00
Marvin
2fb59699db Added more test cases that checks for correct errors, base 2, octal, and hex 2023-12-11 01:22:48 -05:00
Marvin
a91521f5a0 Added basic tests for fast_int in fast_int.cpp 2023-12-10 23:40:27 -05:00
Daniel Lemire
604424b624 adding a test 2023-12-06 21:17:09 -05:00
Daniel Lemire
7646f819a8 Merge branch 'main' of github.com:allenbarnett5/fast_float_ftn into fortran 2023-09-15 09:43:27 -04:00
Daniel Lemire
e6b370dc2c
Merge pull request #220 from mayawarrier/main
Add support for parsing numbers according to JSON format
2023-09-15 09:18:39 -04:00
Maya Warrier
7b1fc2f95d Add an option to allow inf/nan even in json mode
- Most JSON parsers offer this option too
2023-09-14 21:07:22 -04:00
Maya Warrier
ce562d9c65 Disallow inf/nan in json mode 2023-09-14 20:51:26 -04:00
Maya Warrier
2395482ad5 Ignore FASTFLOAT_ALLOWS_LEADING_PLUS for JSON format 2023-09-14 19:50:21 -04:00
Daniel Lemire
cd5160a007 Adding more tests. 2023-09-14 10:32:59 -04:00
Daniel Lemire
a79f2d9841 More tests. 2023-09-14 10:28:08 -04:00
Daniel Lemire
2eb7b2ebda Adding a couple of tests. 2023-09-14 10:13:55 -04:00
Maya Warrier
4de8d715e6 Add json fmt test 2023-09-13 21:07:40 -04:00
allen.barnett@paperbirchsoftware.com
e22c027544 Allow fast_float to parse strings accepted by the Fortran internal read
function.
2023-08-07 08:39:06 -04:00
Daniel Lemire
6d223ab557 Adding C++20 tests in CI. 2023-05-23 09:41:23 -04:00
Daniel Lemire
545c184596 Stack!!! 2023-04-26 16:53:44 -04:00
Daniel Lemire
927eb9bcd2 Merge branch 'main' of https://github.com/Pharago/fast_float into other_chars 2023-04-26 16:40:09 -04:00
Daniel Lemire
ca43e6722e We need to update some of our exhaustive tests to the new API 2023-04-02 17:43:17 -04:00
Adam Lugowski
ca90e36413 Fix subnormal test fails on GCC 9 2023-03-31 17:09:36 -07:00
Adam Lugowski
37127b022f Add subnormal numbers to powers of ten table
On some platforms std::pow returns 0 instead of a subnormal number with `-ffast-math -O2` compiler options.
2023-03-30 13:14:35 -07:00
Adam Lugowski
bfee511d78 Set errc::result_out_of_range on over/underflow
Best-effort values are still returned, such as 0 for underflow and infinity for overflow, but now the returned ec is set to std::errc::result_out_of_range instead of std::errc().
2023-03-29 10:14:46 -07:00
Daniel Lemire
d7ba016c73 Fix. 2023-03-27 13:46:51 -04:00
Daniel Lemire
0394ea1fed Compile-time evaluation 2023-03-27 13:36:46 -04:00
Daniel Lemire
a662df817f If we detect that the compiler supports FASTFLOAT_IS_CONSTEXPR, then let us run the tests automatically. 2023-03-26 20:43:33 -04:00
Daniel Lemire
b50a729d93
Merge pull request #182 from leni536/constexpr-from_chars
Constexpr from_chars
2023-03-25 17:30:55 -04:00
Lenard Szolnoki
360977f968 Add negative zero parsing test for all rounding modes.
This fails on clang.
2023-03-25 19:28:05 +00:00
Lenard Szolnoki
a1a7c4e3e0 Extend verify_options with constexpr test 2023-03-25 18:28:00 +00:00
Lenard Szolnoki
6bd1e776b2 Constexpr isnan 2023-03-24 16:35:25 +00:00
Lenard Szolnoki
24b2fdaad0 Separate verify and verify_runtime macros, extend constexpr checks
`verify` runs both runtime and constexpr checks if the constexpr checks
are enabled in cmake.

`verify_runtime` only runs the runtime checks.
2023-03-24 16:18:00 +00:00
Lenard Szolnoki
264414c0b0 Remove default capture with init-capture in hope of fixing MSVC build. 2023-03-12 15:17:14 +00:00
Daniel Lemire
6a3fabc342 Preparing release 2023-03-06 21:02:19 -05:00
Lenard Szolnoki
6732e397d8 Add constexpr testing
When enabled, modify `verify` macro to also verify at compile time,
when the arguments are constant expressions.
2023-03-04 22:36:58 +00:00
Lenard Szolnoki
58798ee81f Fix failing test builds with -Werror=maybe-uninitialized on gcc
Apparently the added constexpr makes gcc's control flow analysis to go deeper.

If from_chars returns with error then the out parameter remains
uninitialized. As it's undefined behavior to use its value, it's better
to just skip the rest of the loop in this case.
2023-03-04 20:53:49 +00:00
Daniel Lemire
06333da7fe
Merge branch 'main' into dlemire/adding_bloat_analysis 2023-02-28 17:10:05 -05:00
Daniel Lemire
7f1c4a2f7f This adds bloat analysis to the tests. 2023-02-28 16:42:48 -05:00
Daniel Lemire
252a1c9dce Minor fix. 2023-02-06 17:22:11 -05:00
Daniel Lemire
3e2da540ef Support rccpfastfloat. 2023-01-19 20:28:10 -05:00
Daniel Lemire
09f89895f1 Adding test. 2023-01-10 10:32:59 -05:00
Daniel Lemire
e92c63295c
Update CMakeLists.txt 2023-01-04 12:54:20 -05:00
Joao Paulo Magalhaes
0ba57912ff Enable tests with cross compilation 2022-12-27 11:09:17 +00:00
Daniel Lemire
eec504ae03 Adding a fast-math test. 2022-11-21 09:53:49 -05:00
Daniel Lemire
fd9d9effda More tweaking around clangcl 2022-11-16 15:25:03 -05:00
Daniel Lemire
559b89d34d 32-bit clangcl appears to be ridiculous. 2022-11-16 14:59:03 -05:00
Daniel Lemire
d225059873 Fix for Win32+ClangCL 2022-11-16 14:35:31 -05:00
Daniel Lemire
95321767ee More verbose error report. 2022-11-16 12:29:46 -05:00
Daniel Lemire
2c8e738950 Cleaning. 2022-11-16 12:06:33 -05:00
Daniel Lemire
e958ff4269 Simplified clinger. 2022-11-03 18:51:37 -04:00
Daniel Lemire
b4d7cceb93 Added a couple of tests. 2022-10-02 11:09:08 -04:00
Dirk Stolle
3fddb89508 Fix some typos 2022-08-30 22:55:34 +02:00
Daniel Lemire
a332ec1ca7 Saving. 2022-07-29 11:54:19 -04:00
Daniel Lemire
d797a3a05d Adding example. 2022-07-29 11:42:20 -04:00
Daniel Lemire
d148241404 Removing CXX20 support 2021-09-20 09:49:23 -04:00
Daniel Lemire
dd04b5ebd7
Merge pull request #107 from mumbleskates/main
Testing changes and fixes
2021-09-15 21:26:17 -04:00
Kent Ross
1ad817ef54 Include What You Use 2021-09-15 17:38:54 -07:00
Kent Ross
99d475ba9b Delete unused dtoa.c 2021-09-14 22:33:36 -07:00
Kent Ross
6ec3ace497 Fix long_test and add it to the non-exhaustive test suite 2021-09-14 22:22:52 -07:00
Kent Ross
3219e3ce4c Move fast tests to the non-exhaustive test set 2021-09-14 22:22:52 -07:00
Daniel Lemire
b334317dd2 Minor fixes 2021-09-14 21:31:34 -04:00
Alex Huszagh
fc0c8680a5 Implement the big-integer arithmetic algorithm.
Replaces the existing decimal implementation, for substantial
performance improvements with near-halfway cases. This is especially
fast with a large number of digits.

**Big Integer Implementation**

A small subset of big-integer arithmetic has been added, with the
`bigint` struct. It uses a stack-allocated vector with enough bits to
store the float with the large number of significant digits. This is
log2(10^(769 + 342)), to account for the largest possible magnitude
exponent, and number of digits (3600 bits), and then rounded up to 4k bits.

The limb size is determined by the architecture: most 64-bit
architectures have efficient 128-bit multiplication, either by a single
hardware instruction or 2 native multiplications for the high and low
bits. This includes x86_64, mips64, s390x, aarch64, powerpc64, riscv64,
and the only known exception is sparcv8 and sparcv9. Therefore, we
define a limb size of 64-bits on 64-bit architectures except SPARC,
otherwise we fallback to 32-bit limbs.

A simple stackvector is used, which just has operations to add elements,
index, and truncate the vector.

`bigint` is then just a wrapper around this, with methods for
big-integer arithmetic. For our algorithms, we just need multiplication
by a power (x * b^N), multiplication by a bigint or scalar value, and
addition by a bigint or scalar value. Scalar addition and multiplication
uses compiler extensions when possible (__builtin_add_overflow and
__uint128_t), if not, then we implement simple logic shown to optimize
well on MSVC. Big-integer multiplication is done via grade school
multiplication, which is more efficient than any asymptotically faster
algorithms. Multiplication by a power is then done via bitshifts for
powers-of-two, and by iterative multiplications of a large and then
scalar value for powers-of-5.

**compute_float**

Compute float has been slightly modified so if the algorithm cannot
round correctly, it returns a normalized, extended-precision adjusted
mantissa with the power2 shifted by INT16_MIN so the exponent is always
negative. `compute_error` and `compute_error_scaled` have been added.

**Digit Optimiations**

To improve performance for numbers with many digits,
`parse_eight_digits_unrolled` is used for both integers and fractions,
and uses a while loop than two nested if statements. This adds no
noticeable performance cost for common floats, but dramatically improves
performance for numbers with large digits (without these optimizations,
~65% of the total runtime cost is in parse_number_string).

**Parsed Number**

Two fields have been added to `parsed_number_string`, which contains a
slice of the integer and fraction digits. This is extremely cheap, since
the work is already done, and the strings are pre-tokenized during
parsing. This allows us on overflow to re-parse these tokenized strings,
without checking if each character is an integer. Likewise, for the
big-integer algorithms, we can merely re-parse the pre-tokenized
strings.

**Slow Algorithm**

The new algorithm is `digit_comp`, which takes the parsed number string
and the `adjusted_mantissa` from `compute_float`. The significant digits
are parsed into a big integer, and the exponent relative to the
significant digits is calculated. If the exponent is >= 0, we use
`positive_digit_comp`, otherwise, we use `negative_digit_comp`.

`positive_digit_comp` is quite simple: we scale the significant digits
to the exponent, and then we get the high 64-bits for the native float,
determine if any lower bits were truncated, and use that to direct
rounding.

`negative_digit_comp` is a little more complex, but also quite trivial:
we use the parsed significant digits as the real digits, and calculate
the theoretical digits from `b+h`, the halfway point between `b` and
`b+u`, the next-positive float. To get `b`, we round the adjusted
mantissa down, create an extended-precision representation, and
calculate the halfway point. We now have a base-10 exponent for the real
digits, and a base-2 exponent for the theoretical digits. We scale these
two to the same exponent by multiplying the theoretixal digits by
`5**-real_exp`. We then get the base-2 exponent as `theor_exp -
real_exp`, and if this is positive, we multipy the theoretical digits by
it, otherwise, we multiply the real digits by it. Now, both are scaled
to the same magnitude, and we simply compare the digits in the big
integer, and use that to direct rounding.

**Rust-Isms**

A few Rust-isms have been added, since it simplifies logic assertions.
These can be trivially removed or reworked, as needed.

- a `slice` type has been added, which is a pointer and length.
- `FASTFLOAT_ASSERT`, `FASTFLOAT_DEBUG_ASSERT`, and `FASTFLOAT_TRY` have
  been added
  - `FASTFLOAT_ASSERT` aborts, even in release builds, if the condition
    fails.
  - `FASTFLOAT_DEBUG_ASSERT` defaults to `assert`, for logic errors.
  - `FASTFLOAT_TRY` is like a Rust `Option` type, which propagates
    errors.

Specifically, `FASTFLOAT_TRY` is useful in combination with
`FASTFLOAT_ASSERT` to ensure there are no memory corruption errors
possible in the big-integer arithmetic. Although the `bigint` type
ensures we have enough storage for all valid floats, memory issues are
quite a severe class of vulnerabilities, and due to the low performance
cost of checks, we abort if we would have out-of-bounds writes. This can
only occur when we are adding items to the vector, which is a very small
number of steps. Therefore, we abort if our memory safety guarantees
ever fail. lexical has never aborted, so it's unlikely we will ever fail
these guarantees.
2021-09-10 18:53:53 -05:00
Jonas Rahlf
4e13ec151b check for HAS_CXX20_CONSTEXPR before attempting to do c++20 stuff 2021-09-02 23:20:28 +02:00
Jonas Rahlf
d8ee88e7f6 initial version with working constexpr for c++20 compliant compilers 2021-09-01 00:52:25 +02:00
Daniel Lemire
f70b645436 Candidate release. 2021-08-03 09:22:40 -04:00
Antoine Pitrou
3881ea6937 Issue #90: accept custom decimal point 2021-08-03 10:44:24 +02:00
Benjamin A. Beasley
fe8e477e14 Add a SYSTEM_DOCTEST CMake option
This option is off by default, maintaining the previous behavior. When
enabled (along with FASTFLOAT_TEST), it bypasses the FetchContent
machinery for doctest so that a system-wide installation of the doctest
header can be easily used. In this case, the header doctest/doctest.h
should be available on the compiler’s include path.

This option is especially useful for Linux distributions and others that
need to run the tests in fully offline build environments.

Fixes #83.
2021-06-21 11:24:46 -04:00
Daniel Lemire
2504268bbf Being more narrow. 2021-06-07 09:59:44 -04:00
Daniel Lemire
a721b344b4 Trying. 2021-06-07 09:43:36 -04:00
Daniel Lemire
1457b5f15a Workaround for doctest. 2021-06-07 09:38:15 -04:00
Daniel Lemire
6921c8f264 Upgrading doctest. 2021-06-07 09:32:39 -04:00
Daniel Lemire
862082c468 Adding permissive- flag to VS builds. 2021-06-01 09:35:25 -04:00
Daniel Lemire
d0a84312fc Trimming. 2021-05-31 18:26:23 -04:00
Daniel Lemire
0571c35e9c Adding installation instructions. 2021-05-18 09:11:05 -04:00
Daniel Lemire
c38790bc4d Checking issue 72 2021-05-18 08:59:20 -04:00
Daniel Lemire
35db0be700 Adding test corresponding to https://github.com/wrandelshofer/FastDoubleParser/issues/7 2021-03-23 09:17:33 -04:00
Eugene Golushkov
87e5a95585 Prevent fast_float::from_chars from parsing whitespaces and leading '+' sign, similar to MSVC and integer LLVM std::from_chars behavior. See C++17 20.19.3.(7.1) and http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0067r5.html 2021-03-04 20:21:45 +02:00
Daniel Lemire
61f09fb0be Fixing syntax. 2021-03-01 13:49:52 -05:00
Daniel Lemire
e16353a057 Testing installation. 2021-03-01 13:36:09 -05:00
Daniel Lemire
36afa46f1e Trying again. 2021-01-27 21:01:47 -05:00
Daniel Lemire
00591a8652 Sane systems should have filesystem 2021-01-27 20:24:56 -05:00
Daniel Lemire
10a58cd69f Running new tests only on sane platforms. 2021-01-27 20:11:55 -05:00
Daniel Lemire
cb26cedb1c Explicit conversion to string. 2021-01-27 20:01:45 -05:00
Daniel Lemire
541e5feef1 Adding supplemental tests. 2021-01-27 19:57:00 -05:00