Class implementing a High-Precision real number. More...
#include <arccore/base/HPReal.h>
Public Member Functions | |
| constexpr | HPReal () |
| Default constructor to 0.0. | |
| constexpr | HPReal (NoInitTag) |
| Constructor WITHOUT initialization. | |
| constexpr | HPReal (double avalue) |
| Creates an HP real with the value value and the correction correction. | |
| constexpr | HPReal (double avalue, double acorrection) |
| Creates an HP real with the value value and the correction correction. | |
| constexpr Real | value () const |
| Internal value. Generally, you must use toReal(). | |
| constexpr Real | correction () const |
| Internal correction. | |
| constexpr void | operator+= (Real v) |
| Adds a Real while preserving the error. | |
| constexpr void | operator+= (HPReal v) |
| Adds an HPReal v while preserving the error (reduction). | |
| constexpr Real | toReal () const |
| Converts the instance to a Real. | |
| constexpr HPReal | reduce (HPReal b) const |
| Adds an HPReal v while preserving the error (reduction). | |
| constexpr void | operator*= (Real v) |
| Multiplies a Real while preserving the error. | |
| constexpr void | operator*= (HPReal v) |
| Multiplies an HPReal v while preserving the error (reduction). | |
| constexpr void | operator/= (Real v) |
| Multiplies a Real while preserving the error. | |
| constexpr 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 constexpr HPReal | zero () |
| Zero value. | |
| static constexpr HPReal | accumulate (Real a, HPReal b) |
| static constexpr HPReal | reduce (HPReal a, HPReal b) |
| static constexpr HPReal | product (HPReal a, HPReal b) |
| static constexpr HPReal | product (Real a, HPReal b) |
| static constexpr HPReal | div2 (HPReal a, HPReal b) |
| static constexpr HPReal | div2 (Real b, HPReal a) |
Friends | |
| constexpr bool | operator< (const HPReal &a, const HPReal &b) |
| constexpr bool | operator> (const HPReal &a, const HPReal &b) |
| constexpr bool | operator== (const HPReal &a, const HPReal &b) |
| constexpr bool | operator!= (const HPReal &a, const HPReal &b) |
| constexpr HPReal | operator+ (const HPReal &a, const HPReal &b) |
| std::ostream & | operator<< (std::ostream &o, HPReal t) |
| std::istream & | operator>> (std::istream &i, HPReal &t) |
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)
Definition at line 158 of file arccore/src/base/arccore/base/HPReal.h.
|
inlineconstexpr |
Default constructor to 0.0.
Definition at line 163 of file arccore/src/base/arccore/base/HPReal.h.
Referenced by operator*=(), operator+=(), operator/=(), reduce(), and zero().
|
inlineconstexpr |
Constructor WITHOUT initialization.
Definition at line 169 of file arccore/src/base/arccore/base/HPReal.h.
|
inlineexplicitconstexpr |
Creates an HP real with the value value and the correction correction.
Definition at line 172 of file arccore/src/base/arccore/base/HPReal.h.
|
inlineconstexpr |
Creates an HP real with the value value and the correction correction.
Definition at line 178 of file arccore/src/base/arccore/base/HPReal.h.
Definition at line 254 of file arccore/src/base/arccore/base/HPReal.h.
| std::istream & Arcane::HPReal::assign | ( | std::istream & | i | ) |
|
inlineconstexpr |
Internal correction.
Definition at line 187 of file arccore/src/base/arccore/base/HPReal.h.
Referenced by toReal().
Definition at line 288 of file arccore/src/base/arccore/base/HPReal.h.
Definition at line 296 of file arccore/src/base/arccore/base/HPReal.h.
|
inlineconstexpr |
Multiplies an HPReal v while preserving the error (reduction).
Definition at line 220 of file arccore/src/base/arccore/base/HPReal.h.
References HPReal().
|
inlineconstexpr |
Multiplies a Real while preserving the error.
Definition at line 214 of file arccore/src/base/arccore/base/HPReal.h.
|
inlineconstexpr |
Adds an HPReal v while preserving the error (reduction).
Definition at line 196 of file arccore/src/base/arccore/base/HPReal.h.
|
inlineconstexpr |
Adds a Real while preserving the error.
Definition at line 190 of file arccore/src/base/arccore/base/HPReal.h.
|
inlineconstexpr |
Multiplies an HPReal v while preserving the error (reduction).
Definition at line 232 of file arccore/src/base/arccore/base/HPReal.h.
References HPReal().
|
inlineconstexpr |
Multiplies a Real while preserving the error.
Definition at line 226 of file arccore/src/base/arccore/base/HPReal.h.
| std::ostream & Arcane::HPReal::print | ( | std::ostream & | o | ) | const |
| std::ostream & Arcane::HPReal::printPretty | ( | std::ostream & | o | ) | const |
Definition at line 270 of file arccore/src/base/arccore/base/HPReal.h.
Definition at line 277 of file arccore/src/base/arccore/base/HPReal.h.
Definition at line 262 of file arccore/src/base/arccore/base/HPReal.h.
Adds an HPReal v while preserving the error (reduction).
Definition at line 208 of file arccore/src/base/arccore/base/HPReal.h.
References HPReal(), and reduce().
Referenced by operator+=(), and reduce().
|
inlineconstexpr |
Converts the instance to a Real.
Definition at line 202 of file arccore/src/base/arccore/base/HPReal.h.
References correction(), and value().
|
inlineconstexpr |
Internal value. Generally, you must use toReal().
Definition at line 184 of file arccore/src/base/arccore/base/HPReal.h.
Referenced by toReal().
|
inlinestaticconstexpr |
Zero value.
Definition at line 250 of file arccore/src/base/arccore/base/HPReal.h.
References HPReal().
Definition at line 318 of file arccore/src/base/arccore/base/HPReal.h.
Definition at line 322 of file arccore/src/base/arccore/base/HPReal.h.
Definition at line 306 of file arccore/src/base/arccore/base/HPReal.h.
|
friend |
Definition at line 327 of file arccore/src/base/arccore/base/HPReal.h.
Definition at line 314 of file arccore/src/base/arccore/base/HPReal.h.
Definition at line 310 of file arccore/src/base/arccore/base/HPReal.h.
|
friend |
Definition at line 332 of file arccore/src/base/arccore/base/HPReal.h.