Improve fread for very small or very large fp numbers.#4165
Improve fread for very small or very large fp numbers.#4165mattdowle merged 2 commits intoRdatatable:masterfrom
fread for very small or very large fp numbers.#4165Conversation
On non-x86 architectures (armv7hl and ppc64le), test 1018 fails with a
slightly differently parsed number. In base R, `R_strtod` handles small
numbers by pre-dividing numerator and divisor before applying the
exponent part (instead of dividing all together.) However, it does not
use a lookup table.
For `fread`, trim the exponent lookup table from ±350 to ±300, and if
anything is in that removed range, do two multiplications instead. This
results in approximately the same effect as in base R.
Removing some of the range from the lookup table also fixes several
warnings such as:
```
freadLookups.h:57:1: warning: floating constant truncated to zero [-Woverflow]
57 | 1.0E-324L,
| ^~~~~~~~~
freadLookups.h:690:1: warning: floating constant exceeds range of 'long double' [-Woverflow]
690 | 1.0E309L,
| ^~~~~~~~
```
See Rdatatable#3492 and Rdatatable#4032.
Codecov Report
@@ Coverage Diff @@
## master #4165 +/- ##
==========================================
+ Coverage 99.54% 99.61% +0.07%
==========================================
Files 72 72
Lines 13937 13901 -36
==========================================
- Hits 13873 13847 -26
+ Misses 64 54 -10
Continue to review full report at Codecov.
|
|
no need to update manual? I see one example there related to precision |
|
Which do you mean? Note this doesn't really change actual precision, just intermediary precision, so that final results are consistent. |
|
The section in examples I meant |
|
Ah, I don't believe that section requires any changes. The only effect here is if the |
| // and then remove extra from e. | ||
| // This avoids having to store very small or very large constants that may | ||
| // fail to be encoded by the compiler, even though the values can actually | ||
| // be stored correctly. |
There was a problem hiding this comment.
Very clear comment and wording. Perfect.
I invited you to be project member in your other PR #4213, and added you to contributor list there too.
Many thanks for investigating and fixing this!
On non-x86 architectures (armv7hl and ppc64le), test 1018 fails with a slightly differently parsed number. In base R,
R_strtodhandles small numbers by pre-dividing numerator and divisor before applying the exponent part (instead of dividing all together.) However, it does not use a lookup table.For
fread, trim the exponent lookup table from ±350 to ±300, and if anything is in that removed range, do two multiplications instead. This results in approximately the same effect as in base R.Removing some of the range from the lookup table also fixes several warnings such as:
Closes #3492 now that #4213 closed the other issue in it.
The first part of #4032 is the same issue (test 1018) fixed here. A build on those architectures can be found here.
Closes #4097 too.