cpp_bin_float fma rounds the product before the addition instead of fusing
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 35/100
Direzione di ricerca
Read the cpp_bin_float backend and detail/default_ops.hpp, where the issue identifies the fallback multiply and add dispatch. Start by tracing how eval_multiply_add is selected for cpp_bin_float; verify the fused result against the provided cpp_bin_float_quad reproduction, including the expected eps * eps. Done when fma preserves the exact fused result for the reported case.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
The documentation says fma behaves like its C++11 standard-library counterpart, i.e. a * b + c is rounded once. For cpp_bin_float it is rounded twice: cpp_bin_float has no eval_multiply_add / eval_multiply_subtract of its own, so the unqualified backend dispatch resolves to the generic fallback in detail/default_ops.hpp, which does eval_multiply(t, u, v); eval_add(t, x);. The product is rounded to the working precision before c is added.
Other backends that I can see use the same fallback (cpp_dec_float, gmp_float, cpp_double_fp, mpfi_float); mpfr_float has its own overload (mpfr_fma) and float128 does too, unless BOOST_MP_USE_QUAD is defined. I have only verified the cpp_bin_float behaviour below. cpp_dec_float has guard digits and truncating arithmetic, so its behaviour is a separate question.
Repro:
#include <boost/multiprecision/cpp_bin_float.hpp>
#include <iostream>
#include <limits>
using namespace boost::multiprecision;
int main() {
using T = cpp_bin_float_quad;
T eps = std::numeric_limits<T>::epsilon(); // 2^-112
T x = 1 + eps, z = -(1 + 2 * eps);
std::cout << fma(x, x, z) << "\n"; // prints 0
std::cout << eps * eps << "\n"; // 3.70921e-68, the expected result
}
The exact product is x*x = 1 + 2 eps + eps^2, so fma(x, x, z) must be eps^2 = 2^-224, which is exactly representable. The product is first rounded to 1 + 2 eps, which then cancels with z. The same happens for cpp_bin_float_50.
This breaks error-free transformations built on fma (TwoProduct: p = a * b; e = fma(a, b, -p) returns e == 0 for ordinary finite inputs). Boost.Math (boostorg/math#1547, detail/two_product.hpp) has to work around it for these types.
- Lingua principale
- C++
- Stelle
- 268
- Fork
- 130
- Merge medio
- 1g 15h
- PR unite (30g)
- 2
Preparare l'ambiente
Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di boostorg/multiprecision
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 62/100
boostorg/multiprecision#779 · 1 commento ·
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 55/100
boostorg/multiprecision#775 ·
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 72/100
boostorg/multiprecision#768 · 4 commenti ·
-
Eigen NumTraits specialisation doesn't define max_digits10()Forse già presa @trestoncuzzort l’ha presa 28 giorni fa. Aperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 45/100
boostorg/multiprecision#744 ·
-
`cpp_double_fp_backend` optimized single-limb operationsForse di nuovo libera @ckormanyos l’ha presa 462 giorni fa e non c’è nessuna pull request aperta. Apertaenhancement optimization
boostorg/multiprecision#728 · 1 assegnatario ·
Tutte le issue di boostorg/multiprecision
Issue simili
-
agent:WSL code-review linux pri:medium refactoring
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
I maintainer di solito rispondono entro 1 giorno
-
kind/enhancement
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 1-3 ore Idoneità per principianti 82/100
psi29a/d2decomped#691 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
CachyOS/packageinstaller#144 ·
I maintainer di solito rispondono entro 1 giorno
-
(S1 - Need confirmation)
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
CleverRaven/Cataclysm-DDA#89715 ·
I maintainer di solito rispondono entro 1 giorno