Class implementing a High-Precision real number. More...
#include <arcane/utils/HPReal.h>
Public Member Functions | |
| HPReal () | |
| Default constructor without initialization. | |
| HPReal (double avalue) | |
| Creates an HP real with the value value and the correction correction. | |
| HPReal (double avalue, double acorrection) | |
| Creates an HP real with the value value and the correction correction. | |
| Real | value () const |
| Internal value. Generally, you must use toReal(). | |
| Real | correction () const |
| Internal correction. | |
| void | operator+= (Real v) |
| Adds a Real while preserving the error. | |
| void | operator+= (HPReal v) |
| Adds an HPReal v while preserving the error (reduction). | |
| Real | toReal () const |
| Converts the instance to a Real. | |
| HPReal | reduce (HPReal b) const |
| Adds an HPReal v while preserving the error (reduction). | |
| void | operator*= (Real v) |
| Multiplies a Real while preserving the error. | |
| void | operator*= (HPReal v) |
| Multiplies an HPReal v while preserving the error (reduction). | |
| void | operator/= (Real v) |
| Multiplies a Real while preserving the error. | |
| void | operator/= (HPReal v) |
| Multiplies an HPReal v while preserving the error (reduction). | |
| std::istream & | assign (std::istream &i) |
| Reads an HPReal from the stream i. The pair is read in the form of two Real type values. | |
| std::ostream & | print (std::ostream &o) const |
| Writes the instance to the stream o readable by an assign(). | |
| std::ostream & | printPretty (std::ostream &o) const |
| Writes the instance to the stream o in the form (x,y). | |
Static Public Member Functions | |
| static HPReal | zero () |
| Zero value. | |
| static HPReal | accumulate (Real a, HPReal b) |
| static HPReal | reduce (HPReal a, HPReal b) |
| static HPReal | product (HPReal a, HPReal b) |
| static HPReal | product (Real a, HPReal b) |
| static HPReal | div2 (HPReal a, HPReal b) |
| static HPReal | div2 (Real b, HPReal a) |
Static Private Member Functions | |
| static HPReal | _doTwoSum (Real a, Real b) |
| static HPReal | _doQuickTwoSum (Real a1, Real b1) |
| static HPReal | _doTwoProducts (Real a, Real b) |
| static HPReal | SPLIT (Real a) |
Private Attributes | |
| Real | m_value |
| Real | m_correction |
Class implementing a High-Precision real number.
This class is based on the article:
Obtaining identical results with double precision global accuracy on different numbers of processors in parallel particle Monte Carlo simulations (Mathew A. Cleveland, Thomas A. Brunner, Nicholas A. Gentile, jeffrey A. Keasler) in Journal Of Computational Physics 251 (2013) 223-236.
Possible operations are accumulation (operator+=()), reduction (reduce()) and conversion to a Real (toReal()). Other operations such as division or multiplication are not possible.
To conform to the classic 'Real' type, the default constructor of this class performs no initialization.
The toReal() method allows converting the HPReal into a classic Real. The typical usage is as follows:
Evolution 12/18/18:
Correction of the base algorithm error for static HPReal _doTwoSum(Real a, Real b)
Real sum_error = (a - (value-approx_b) + (b-approx_b));
became (in accordance with Ref 1)
Real sum_error = (a - (value-approx_b)) + (b-approx_b);
Correction of the error in static HPReal _doQuickTwoSum(Real a,Real b)
it is necessary to test if a>b and invert a and b if this is not the case (see Ref 2, 3, 4)
Modification of Accumulate and Reduce, Accumulate and Reduce were based on Ref 1, which is based on Ref 4
Addition of products as proposed in Ref 2 (in accordance with Ref 5) of HPReal*Real or HPReal*HPReal (we take the same value of p for the SPLIT() function as in Ref 2, 4, 5)
Note that the Real*Real product in Ref 4 (p.4) is not written in the same way as those in Ref 2 (p.2) or 5 (p.3)
+++++++++++++++++
Overall, reduction algorithms or errors accumulated only with addition are less good
Algorithm 6 of DD_TWOSUM [Ref 2] is also less good:
or
Tests on millions of positive as well as negative values have been performed for addition, multiplication, and division in different orders.
I have not managed to show a difference in results in a simple case between the proposed algorithm for the sum and the one initially coded.
Ref 1 Obtaining identical results with double precision global accuracy on different numbers of processors in parallel particle Monte Carlo simulations (Mathew A. Cleveland, Thomas A. Brunner, Nicholas A. Gentile, jeffrey A. Keasler) in Journal Of Computational Physics 251 (2013) 223-236.
Ref 2 Automatic Source-to-Source error compensation of floating-point programs L.Thevenoux, Ph langlois, Mathieu Martel HAL Id: hal-01158399
Ref 3 Numerical validation of compensated summation algorithms withs stochastic arithmetic S.Gaillat, F.Jézéquel , R.Picot Published in Electronic Notes in Theoritical Computer Science
or
Numerical validation of compensated algorithms withs stochastic arithmetic S.Gaillat, F.Jézéquel , R.Picot Published in Applied Mathematics and Computation 329 (2018)339-363
Ref 4 Library for Double-Double and Quad-Double Arithmetic December 29, 2007 Yozo Hida Xiaoye Li D.H.Bailey
Ref 5 Accurate floating point Product and exponentation S.Graillat HAL ID: hal-00164607
Ref 6 A floating point technique for extending the avaible precision T.J.Dekker Numeri.Math 18, 224-242 (1971)
|
inline |
Default constructor without initialization.
Definition at line 165 of file HPReal.h.
Referenced by operator*=(), operator+=(), operator/=(), reduce(), and zero().
|
inlineexplicit |
|
inline |
| std::istream & Arcane::HPReal::assign | ( | std::istream & | i | ) |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
| std::ostream & Arcane::HPReal::print | ( | std::ostream & | o | ) | const |
| std::ostream & Arcane::HPReal::printPretty | ( | std::ostream & | o | ) | const |
|
inline |
Converts the instance to a Real.
Definition at line 198 of file HPReal.h.
References correction(), and value().
|
inline |
|
inlinestatic |