326 Commits

Author SHA1 Message Date
Daniel Lemire
7a17c54269 Dropping it. 2022-03-19 00:29:57 -04:00
Daniel Lemire
708224bc3e Dropping Windows 2016. 2022-03-19 00:28:06 -04:00
Daniel Lemire
b467215b4d
Update README.md 2022-03-19 00:14:13 -04:00
Daniel Lemire
090e500618
Merge pull request #129 from xvitaly/fix-arch
Export CMake targets as architecture independent
2022-03-09 17:40:20 -05:00
Vitaly Zaitsev
5738f18952
Export CMake targets as architecture independent.
Signed-off-by: Vitaly Zaitsev <vitaly@easycoding.org>
2022-03-05 16:05:28 +01:00
Daniel Lemire
ebfbea4f07
Merge pull request #127 from xvitaly/fix-installation
Fixed installation on other than Ubuntu GNU/Linux distributions
2022-03-03 09:41:18 -05:00
Vitaly Zaitsev
17bcdcef02
Fixed installation on other than Ubuntu GNU/Linux distributions.
Signed-off-by: Vitaly Zaitsev <vitaly@easycoding.org>
2022-03-03 10:12:55 +01:00
Daniel Lemire
632cf9b8c8
Merge pull request #128 from fastfloat/dlemire/upgradevs17
Trying to upgrade to vs17
2022-03-02 22:46:07 -05:00
Daniel Lemire
ca9be545c3 Trying to upgrade to vs17 2022-03-02 22:39:54 -05:00
Daniel Lemire
32d21dcecb
Merge pull request #122 from jwakely/patch-1
Fix deduction failure for std::min call
2022-01-18 14:30:38 -05:00
Daniel Lemire
d3b164eb52
Merge pull request #123 from jwakely/endian
Make endianness detection more portable
2022-01-18 14:29:42 -05:00
Jonathan Wakely
61f4840188 Make endianness detection more portable
The current check for endianness fails on platforms using newlib as the
C library, because it provides <machine/endian.h> not <endian.h>. This
could be fixed by adding `|| defined(__NEWLIB__)` to the check for
targets that provide <machine/endian.h> (i.e. BSD-like targets).

A more portable solution is to just check if the compiler has already
defined the necessary macros (which is true for GCC and Clang and Intel,
at least). Then no header is needed, and it works for platforms that
aren't explicitly listed in the conditionals.
2022-01-18 10:17:01 +00:00
Jonathan Wakely
1ccabed64c Fix deduction failure for std::min call
This assumes that the literal `64` of type `int` has the same type as
the `int32_t` typedef, which is never true for targets with 16-bit
`int`, and isn't guaranteed to be true even with 32-bit `int`.
2022-01-18 10:12:57 +00:00
Daniel Lemire
b15abc9238
Update README.md 2022-01-16 21:04:50 -05:00
Daniel Lemire
b7f9d6ca39 Version 3.4.0 v3.4.0 2021-11-30 15:53:33 -05:00
Daniel Lemire
62a8dba55a
Merge pull request #118 from pitrou/issue-117
Fix #117: compilation warning with gcc 6.3.0
2021-11-30 14:58:33 -05:00
Antoine Pitrou
133099ab4e Fix #117: compilation warning with gcc 6.3.0
Fix the following warning:
```
/arrow/cpp/src/arrow/vendored/fast_float/digit_comparison.h:62:50: error: right shift count >= width of type [-Werror=shift-count-overflow]
       am.power2 = int32_t((bits & exponent_mask) >> binary_format<T>::mantissa_explicit_bits());
                           ~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
```
2021-11-30 20:35:09 +01:00
Daniel Lemire
d35368cae6
Update README.md 2021-10-23 18:04:22 -04:00
Daniel Lemire
b9861e4190 Version 3.3 2021-10-19 14:45:19 -04:00
Daniel Lemire
a2fa7863fd
Merge pull request #116 from SamuelLongchamps/licenses_compliance
Added dual license option, proper copyright
2021-10-19 14:11:50 -04:00
Samuel Longchamps
38b5900fd2 Added dual license option, proper copyright
Fixed #115
2021-10-18 22:41:57 -04:00
Daniel Lemire
052975dd5f
Update README.md 2021-09-21 11:50:07 -04:00
Daniel Lemire
d35f404a15 Version bump. v3.2.0 2021-09-20 09:55:14 -04:00
Daniel Lemire
6d768256f1
Merge pull request #112 from fastfloat/dlemire/remove_cxx20
Removing CXX20 support
2021-09-20 09:54:00 -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
Daniel Lemire
1663effbcb
Merge pull request #108 from mumbleskates/cleanup-dtoa
Delete unused dtoa.c
2021-09-15 10:25:55 -04: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
af4e24a30f Bump version. v3.1.0 2021-09-14 21:32:14 -04:00
Daniel Lemire
b334317dd2 Minor fixes 2021-09-14 21:31:34 -04:00
Daniel Lemire
1b9150913e Updating. v3.0.0 2021-09-13 22:04:26 -04:00
Daniel Lemire
5c85d38eda
Merge pull request #104 from fastfloat/dlemire/bigint
Adopting Alexhuszagh's decimal comparison approach for long input strings
2021-09-13 22:03:37 -04:00
Daniel Lemire
3f0ba09a95
Merge pull request #96 from Alexhuszagh/bigint
Implement the big-integer arithmetic algorithm.
2021-09-13 21:23:14 -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
Daniel Lemire
25b240a02d
Merge pull request #102 from jrahlf/reduce_includes
Remove unneeded includes
2021-09-05 19:04:31 -04:00
Jonas Rahlf
162a37b25a remove cstdio includes, remove cassert include, add asthetic newlines 2021-09-05 23:13:41 +02:00
Daniel Lemire
8c4405e76e
Merge pull request #101 from fastfloat/dlemire/const
C++ 20 support and tests
2021-09-03 18:54:52 -04:00
Daniel Lemire
f74d505615 Adding C++20 tests. 2021-09-03 17:57:44 -04:00
Daniel Lemire
1a56fe5f64
Merge pull request #100 from jrahlf/constexpr
constexpr for c++20 compliant compilers
2021-09-03 16:36:49 -04: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
e5d5e576a6 use #if defined __has_include properly 2021-09-02 22:22:03 +02:00
Jonas Rahlf
b17eafd06f chnage compiler check for bit_cast so it compiles with older compilers 2021-09-02 22:00:57 +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
898f54f30a
Merge pull request #95 from Alexhuszagh/ptr
Fixes #94, with unspecified behavior in pointer comparisons.
2021-08-21 14:27:35 -04:00
Alex Huszagh
3e74ed313a Fixes #94, with unspecified behavior in pointer comparisons. 2021-08-21 13:07:57 -05:00
Daniel Lemire
fe1ce58053
Merge pull request #92 from fastfloat/dlemire/v2.0.0_candidate
Candidate release.
v2.0.0
2021-08-03 09:27:28 -04:00
Daniel Lemire
f70b645436 Candidate release. 2021-08-03 09:22:40 -04:00