@@ -31,7 +31,9 @@ namespace sw { namespace universal {
31
31
32
32
// fwd references to free functions used in to_digits()
33
33
dd operator *(const dd& lhs, const dd&);
34
- dd pown (dd const &, int );
34
+ std::ostream& operator <<(std::ostream&, const dd&);
35
+ dd pown (const dd&, int );
36
+ dd frexp (const dd&, int *);
35
37
36
38
// dd is an unevaluated pair of IEEE-754 doubles that provides a (1,11,106) floating-point triple
37
39
class dd {
@@ -811,6 +813,16 @@ inline std::string to_pair(const dd& v, int precision = 17) {
811
813
return s.str ();
812
814
}
813
815
816
+ inline std::string to_triple (const dd& v, int precision = 17 ) {
817
+ std::stringstream s;
818
+ bool isneg = v.isneg ();
819
+ int scale = v.scale ();
820
+ int exponent;
821
+ dd fraction = frexp (v, &exponent);
822
+ s << ' (' << (isneg ? ' 1' : ' 0' ) << " , " << scale << " , " << std::setprecision (precision) << fraction << ' )' ;
823
+ return s.str ();
824
+ }
825
+
814
826
inline std::string to_binary (const dd& number, bool bNibbleMarker = false ) {
815
827
std::stringstream s;
816
828
constexpr int nrLimbs = 2 ;
@@ -863,7 +875,7 @@ inline dd abs(dd a) {
863
875
return dd (hi, lo);
864
876
}
865
877
866
- inline dd ceil (dd const & a)
878
+ inline dd ceil (const dd & a)
867
879
{
868
880
if (a.isnan ()) return a;
869
881
@@ -878,7 +890,7 @@ inline dd ceil(dd const& a)
878
890
return dd (hi, lo);
879
891
}
880
892
881
- inline dd floor (dd const & a) {
893
+ inline dd floor (const dd & a) {
882
894
if (a.isnan ()) return a;
883
895
884
896
double hi = std::floor (a.high ());
@@ -974,7 +986,7 @@ inline dd mul_pwr2(const dd& a, double b) {
974
986
// quad-double operators
975
987
976
988
// quad-double + double-double
977
- void qd_add (double const a[4 ], dd const & b, double s[4 ]) {
989
+ void qd_add (double const a[4 ], const dd & b, double s[4 ]) {
978
990
double t[5 ];
979
991
s[0 ] = two_sum (a[0 ], b.high (), t[0 ]); // s0 - O( 1 ); t0 - O( e )
980
992
s[1 ] = two_sum (a[1 ], b.low (), t[1 ]); // s1 - O( e ); t1 - O( e^2 )
@@ -991,7 +1003,7 @@ void qd_add(double const a[4], dd const& b, double s[4]) {
991
1003
}
992
1004
993
1005
// quad-double = double-double * double-double
994
- void qd_mul (dd const & a, dd const & b, double p[4 ]) {
1006
+ void qd_mul (const dd & a, const dd & b, double p[4 ]) {
995
1007
double p4, p5, p6, p7;
996
1008
997
1009
// powers of e - 0, 1, 1, 1, 2, 2, 2, 3
@@ -1025,15 +1037,15 @@ void qd_mul(dd const& a, dd const& b, double p[4]) {
1025
1037
}
1026
1038
}
1027
1039
1028
- inline dd fma (dd const & a, dd const & b, dd const & c) {
1040
+ inline dd fma (const dd & a, const dd & b, const dd & c) {
1029
1041
double p[4 ];
1030
1042
qd_mul (a, b, p);
1031
1043
qd_add (p, c, p);
1032
1044
p[0 ] = two_sum (p[0 ], p[1 ] + p[2 ] + p[3 ], p[1 ]);
1033
1045
return dd (p[0 ], p[1 ]);
1034
1046
}
1035
1047
1036
- inline dd sqr (dd const & a) {
1048
+ inline dd sqr (const dd & a) {
1037
1049
if (a.isnan ()) return a;
1038
1050
1039
1051
double p2, p1 = two_sqr (a.high (), p2);
@@ -1044,7 +1056,7 @@ inline dd sqr(dd const& a) {
1044
1056
return dd (s1, s2);
1045
1057
}
1046
1058
1047
- inline dd reciprocal (dd const & a) {
1059
+ inline dd reciprocal (const dd & a) {
1048
1060
if (a.iszero ()) return dd (SpecificValue::infpos);
1049
1061
1050
1062
if (a.isinf ()) return dd (0.0 );
@@ -1065,7 +1077,7 @@ inline dd reciprocal(dd const& a) {
1065
1077
}
1066
1078
}
1067
1079
1068
- inline dd pown (dd const & a, int n) {
1080
+ inline dd pown (const dd & a, int n) {
1069
1081
if (a.isnan ()) return a;
1070
1082
1071
1083
int N = (n < 0 ) ? -n : n;
0 commit comments