☰
Go to the documentation of this file. 33 #ifndef _SCIP_DBLDBL_ARITH_ 34 #define _SCIP_DBLDBL_ARITH_ 39 #ifndef DISABLE_QUADPREC 42 #define QUAD_EPSILON 1e-12 45 #define QUAD_HI(x) x ## hi 46 #define QUAD_LO(x) x ## lo 47 #define QUAD(x) QUAD_HI(x), QUAD_LO(x) 48 #define QUAD_MEMBER(x) QUAD_HI(x); QUAD_LO(x) 49 #define QUAD_TO_DBL(x) ( QUAD_HI(x) + QUAD_LO(x) ) 50 #define QUAD_SCALE(x, a) do { QUAD_HI(x) *= (a); QUAD_LO(x) *= (a); } while(0) 51 #define QUAD_ASSIGN(a, constant) do { QUAD_HI(a) = (constant); QUAD_LO(a) = 0.0; } while(0) 52 #define QUAD_ASSIGN_Q(a, b) do { QUAD_HI(a) = QUAD_HI(b); QUAD_LO(a) = QUAD_LO(b); } while(0) 53 #define QUAD_ARRAY_SIZE(size) ((size)*2) 54 #define QUAD_ARRAY_LOAD(r, a, idx) do { QUAD_HI(r) = (a)[2*(idx)]; QUAD_LO(r) = (a)[2*(idx) + 1]; } while(0) 55 #define QUAD_ARRAY_STORE(a, idx, x) do { (a)[2*(idx)] = QUAD_HI(x); (a)[2*(idx) + 1] = QUAD_LO(x); } while(0) 58 #define SCIPquadprecProdDD(r, a, b) SCIPdbldblProd(QUAD_HI(r), QUAD_LO(r), a, b) 59 #define SCIPquadprecSquareD(r, a) SCIPdbldblSquare(QUAD_HI(r), QUAD_LO(r), a) 60 #define SCIPquadprecSumDD(r, a, b) SCIPdbldblSum(QUAD_HI(r), QUAD_LO(r), a, b) 61 #define SCIPquadprecDivDD(r, a, b) SCIPdbldblDiv(QUAD_HI(r), QUAD_LO(r), a, b) 62 #define SCIPquadprecSumQD(r, a, b) SCIPdbldblSum21(QUAD_HI(r), QUAD_LO(r), QUAD_HI(a), QUAD_LO(a), b) 63 #define SCIPquadprecProdQD(r, a, b) SCIPdbldblProd21(QUAD_HI(r), QUAD_LO(r), QUAD_HI(a), QUAD_LO(a), b) 64 #define SCIPquadprecDivDQ(r, a, b) SCIPdbldblDiv12(QUAD_HI(r), QUAD_LO(r), a, QUAD_HI(b), QUAD_LO(b)) 65 #define SCIPquadprecDivQD(r, a, b) SCIPdbldblDiv21(QUAD_HI(r), QUAD_LO(r), QUAD_HI(a), QUAD_LO(a), b) 66 #define SCIPquadprecProdQQ(r, a, b) SCIPdbldblProd22(QUAD_HI(r), QUAD_LO(r), QUAD_HI(a), QUAD_LO(a), QUAD_HI(b), QUAD_LO(b)) 67 #define SCIPquadprecSumQQ(r, a, b) SCIPdbldblSum22(QUAD_HI(r), QUAD_LO(r), QUAD_HI(a), QUAD_LO(a), QUAD_HI(b), QUAD_LO(b)) 68 #define SCIPquadprecSquareQ(r, a) SCIPdbldblSquare2(QUAD_HI(r), QUAD_LO(r), QUAD_HI(a), QUAD_LO(a)) 69 #define SCIPquadprecDivQQ(r, a, b) SCIPdbldblDiv22(QUAD_HI(r), QUAD_LO(r), QUAD_HI(a), QUAD_LO(a), QUAD_HI(b), QUAD_LO(b)) 70 #define SCIPquadprecSqrtD(r, a) SCIPdbldblSqrt(QUAD_HI(r), QUAD_LO(r), a) 71 #define SCIPquadprecSqrtQ(r, a) SCIPdbldblSqrt2(QUAD_HI(r), QUAD_LO(r), QUAD_HI(a), QUAD_LO(a)) 72 #define SCIPquadprecAbsQ(r, a) SCIPdbldblAbs2(QUAD_HI(r), QUAD_LO(r), QUAD_HI(a), QUAD_LO(a)) 73 #define SCIPquadprecFloorQ(r, a) SCIPdbldblFloor2(QUAD_HI(r), QUAD_LO(r), QUAD_HI(a), QUAD_LO(a)) 74 #define SCIPquadprecCeilQ(r, a) SCIPdbldblCeil2(QUAD_HI(r), QUAD_LO(r), QUAD_HI(a), QUAD_LO(a)) 75 #define SCIPquadprecEpsFloorQ(r, a, eps) SCIPdbldblEpsFloor2(QUAD_HI(r), QUAD_LO(r), QUAD_HI(a), QUAD_LO(a), eps) 76 #define SCIPquadprecEpsCeilQ(r, a, eps) SCIPdbldblEpsCeil2(QUAD_HI(r), QUAD_LO(r), QUAD_HI(a), QUAD_LO(a), eps) 81 #define QUAD_EPSILON 1e-9 85 #define QUAD_LO(x) 0.0 87 #define QUAD_MEMBER(x) x 88 #define QUAD_TO_DBL(x) (x) 89 #define QUAD_SCALE(x, a) do { (x) *= (a); } while(0) 90 #define QUAD_ASSIGN(a, constant) do { (a) = constant; } while(0) 91 #define QUAD_ASSIGN_Q(a, b) do { (a) = (b); } while(0) 92 #define QUAD_ARRAY_SIZE(size) (size) 93 #define QUAD_ARRAY_LOAD(r, a, idx) do { r = (a)[(idx)]; } while(0) 94 #define QUAD_ARRAY_STORE(a, idx, x) do { (a)[(idx)] = (x); } while(0) 96 #define SCIPquadprecProdDD(r, a, b) do { (r) = (a) * (b); } while(0) 97 #define SCIPquadprecSquareD(r, a) do { (r) = (a) * (a); } while(0) 98 #define SCIPquadprecSumDD(r, a, b) do { (r) = (a) + (b); } while(0) 99 #define SCIPquadprecDivDD(r, a, b) do { (r) = (a) / (b); } while(0) 100 #define SCIPquadprecSumQD(r, a, b) do { (r) = (a) + (b); } while(0) 101 #define SCIPquadprecProdQD(r, a, b) do { (r) = (a) * (b); } while(0) 102 #define SCIPquadprecDivDQ(r, a, b) do { (r) = (a) / (b); } while(0) 103 #define SCIPquadprecDivQD(r, a, b) do { (r) = (a) / (b); } while(0) 104 #define SCIPquadprecProdQQ(r, a, b) do { (r) = (a) * (b); } while(0) 105 #define SCIPquadprecSumQQ(r, a, b) do { (r) = (a) + (b); } while(0) 106 #define SCIPquadprecSquareQ(r, a) do { (r) = (a) * (a); } while(0) 107 #define SCIPquadprecDivQQ(r, a, b) do { (r) = (a) / (b); } while(0) 108 #define SCIPquadprecSqrtD(r, a) do { (r) = sqrt(a); } while(0) 109 #define SCIPquadprecSqrtQ(r, a) do { (r) = sqrt(a); } while(0) 110 #define SCIPquadprecAbsQ(r, a) do { (r) = fabs(a); } while(0) 111 #define SCIPquadprecFloorQ(r, a) do { (r) = floor(a); } while(0) 112 #define SCIPquadprecCeilQ(r, a) do { (r) = ceil(a); } while(0) 113 #define SCIPquadprecEpsFloorQ(r, a, eps) do { (r) = floor((a) + (eps)); } while(0) 114 #define SCIPquadprecEpsCeilQ(r, a, eps) do { (r) = ceil((a) - (eps)); } while(0) 118 #define __SCIPdbldblSplit(rhi, rlo, x) \ 120 const double __tmp_split_dbl = 134217729.0 * (x); \ 121 (rhi) = __tmp_split_dbl - (__tmp_split_dbl - (x)); \ 122 (rlo) = (x) - (rhi);\ 126 #define SCIPdbldblProd(rhi, rlo, a, b) \ 128 double __tmp_dbldbl_prod_ahi; \ 129 double __tmp_dbldbl_prod_alo; \ 130 double __tmp_dbldbl_prod_bhi; \ 131 double __tmp_dbldbl_prod_blo; \ 132 __SCIPdbldblSplit(__tmp_dbldbl_prod_ahi, __tmp_dbldbl_prod_alo, a); \ 133 __SCIPdbldblSplit(__tmp_dbldbl_prod_bhi, __tmp_dbldbl_prod_blo, b); \ 135 (rlo) = __tmp_dbldbl_prod_alo * __tmp_dbldbl_prod_blo - \ 136 ((((rhi) - __tmp_dbldbl_prod_ahi * __tmp_dbldbl_prod_bhi) \ 137 - __tmp_dbldbl_prod_alo * __tmp_dbldbl_prod_bhi) \ 138 - __tmp_dbldbl_prod_ahi * __tmp_dbldbl_prod_blo); \ 142 #define SCIPdbldblSquare(rhi, rlo, a) \ 144 double __tmp_dbldbl_square_ahi; \ 145 double __tmp_dbldbl_square_alo; \ 146 __SCIPdbldblSplit(__tmp_dbldbl_square_ahi, __tmp_dbldbl_square_alo, a); \ 148 (rlo) = __tmp_dbldbl_square_alo * __tmp_dbldbl_square_alo - \ 149 ((((rhi) - __tmp_dbldbl_square_ahi * __tmp_dbldbl_square_ahi) \ 150 - 2.0 * __tmp_dbldbl_square_alo * __tmp_dbldbl_square_ahi)); \ 154 #define SCIPdbldblSum(rhi, rlo, a, b) \ 156 double __tmp1_dbldbl_sum; \ 157 double __tmp2_dbldbl_sum; \ 158 __tmp2_dbldbl_sum = (a) + (b); \ 159 __tmp1_dbldbl_sum = __tmp2_dbldbl_sum - (a); \ 160 (rlo) = ((a) - (__tmp2_dbldbl_sum - __tmp1_dbldbl_sum)) + ((b) - __tmp1_dbldbl_sum); \ 161 (rhi) = __tmp2_dbldbl_sum; \ 165 #define SCIPdbldblDiv(rhi, rlo, a, b) \ 167 double __tmp_dbldbl_div_hi; \ 168 double __tmp_dbldbl_div_lo; \ 169 double __estim_dbldbl_div = (a)/(b); \ 170 SCIPdbldblProd(__tmp_dbldbl_div_hi, __tmp_dbldbl_div_lo, b, __estim_dbldbl_div); \ 171 SCIPdbldblSum21(__tmp_dbldbl_div_hi, __tmp_dbldbl_div_lo, __tmp_dbldbl_div_hi, __tmp_dbldbl_div_lo, -(a)); \ 172 __tmp_dbldbl_div_hi /= (b); \ 173 __tmp_dbldbl_div_lo /= (b); \ 174 SCIPdbldblSum21(rhi, rlo, -__tmp_dbldbl_div_hi, -__tmp_dbldbl_div_lo, __estim_dbldbl_div); \ 180 #define SCIPdbldblSum21(rhi, rlo, ahi, alo, b) \ 182 double __tmp_dbldbl_sum21_hi; \ 183 double __tmp_dbldbl_sum21_lo; \ 184 SCIPdbldblSum(__tmp_dbldbl_sum21_hi, __tmp_dbldbl_sum21_lo, ahi, b); \ 185 (rlo) = __tmp_dbldbl_sum21_lo + (alo); \ 186 (rhi) = __tmp_dbldbl_sum21_hi; \ 193 #define SCIPdbldblProd21(rhi, rlo, ahi, alo, b) \ 195 double __tmp_dbldbl_prod21_hi; \ 196 double __tmp_dbldbl_prod21_lo; \ 197 SCIPdbldblProd(__tmp_dbldbl_prod21_hi, __tmp_dbldbl_prod21_lo, ahi, b); \ 198 (rlo) = (alo) * (b) + __tmp_dbldbl_prod21_lo; \ 199 (rhi) = __tmp_dbldbl_prod21_hi; \ 205 #define SCIPdbldblDiv12(rhi, rlo, a, bhi, blo) \ 207 double __tmp_dbldbl_div12_hi; \ 208 double __tmp_dbldbl_div12_lo; \ 209 double __estim_dbldbl_div12 = (a)/(bhi); \ 210 SCIPdbldblProd21(__tmp_dbldbl_div12_hi, __tmp_dbldbl_div12_lo, bhi, blo, __estim_dbldbl_div12); \ 211 SCIPdbldblSum21(__tmp_dbldbl_div12_hi, __tmp_dbldbl_div12_lo, __tmp_dbldbl_div12_hi, __tmp_dbldbl_div12_lo, -(a)); \ 212 __tmp_dbldbl_div12_hi /= (bhi); \ 213 __tmp_dbldbl_div12_lo /= (bhi); \ 214 SCIPdbldblSum21(rhi, rlo, -__tmp_dbldbl_div12_hi, -__tmp_dbldbl_div12_lo, __estim_dbldbl_div12); \ 221 #define SCIPdbldblDiv21(rhi, rlo, ahi, alo, b) \ 223 double __tmp_dbldbl_div21_hi; \ 224 double __tmp_dbldbl_div21_lo; \ 225 double __estim_dbldbl_div21_hi; \ 226 double __estim_dbldbl_div21_lo; \ 227 __estim_dbldbl_div21_hi = (ahi)/(b); \ 228 __estim_dbldbl_div21_lo = (alo)/(b); \ 229 SCIPdbldblProd21(__tmp_dbldbl_div21_hi, __tmp_dbldbl_div21_lo, __estim_dbldbl_div21_hi, __estim_dbldbl_div21_lo, b); \ 230 SCIPdbldblSum22(__tmp_dbldbl_div21_hi, __tmp_dbldbl_div21_lo, __tmp_dbldbl_div21_hi, __tmp_dbldbl_div21_lo, -(ahi), -(alo)); \ 231 __tmp_dbldbl_div21_hi /= (b); \ 232 __tmp_dbldbl_div21_lo /= (b); \ 233 SCIPdbldblSum22(rhi, rlo, __estim_dbldbl_div21_hi, __estim_dbldbl_div21_lo, -__tmp_dbldbl_div21_hi, -__tmp_dbldbl_div21_lo); \ 237 #define SCIPdbldblProd22(rhi, rlo, ahi, alo, bhi, blo) \ 239 double __tmp_dbldbl_prod22_hi; \ 240 double __tmp_dbldbl_prod22_lo; \ 241 SCIPdbldblProd(__tmp_dbldbl_prod22_hi, __tmp_dbldbl_prod22_lo, ahi, bhi); \ 242 SCIPdbldblSum21(__tmp_dbldbl_prod22_hi, __tmp_dbldbl_prod22_lo, \ 243 __tmp_dbldbl_prod22_hi, __tmp_dbldbl_prod22_lo, (alo) * (bhi)); \ 244 SCIPdbldblSum21(rhi, rlo, \ 245 __tmp_dbldbl_prod22_hi, __tmp_dbldbl_prod22_lo, (ahi) * (blo)); \ 249 #define SCIPdbldblSum22(rhi, rlo, ahi, alo, bhi, blo) \ 251 double __tmp_dbldbl_sum22_hi; \ 252 double __tmp_dbldbl_sum22_lo; \ 253 SCIPdbldblSum21(__tmp_dbldbl_sum22_hi, __tmp_dbldbl_sum22_lo, ahi, alo, bhi); \ 254 SCIPdbldblSum21(rhi, rlo, __tmp_dbldbl_sum22_hi, __tmp_dbldbl_sum22_lo, blo); \ 258 #define SCIPdbldblSquare2(rhi, rlo, ahi, alo) \ 260 double __tmp_dbldbl_square2_hi; \ 261 double __tmp_dbldbl_square2_lo; \ 262 SCIPdbldblSquare(__tmp_dbldbl_square2_hi, __tmp_dbldbl_square2_lo, (ahi)); \ 263 SCIPdbldblSum21(rhi, rlo, __tmp_dbldbl_square2_hi, __tmp_dbldbl_square2_lo, 2 * (ahi) * (alo)); \ 267 #define SCIPdbldblDiv22(rhi, rlo, ahi, alo, bhi, blo) \ 269 double __tmp_dbldbl_div22_hi; \ 270 double __tmp_dbldbl_div22_lo; \ 271 double __estim_dbldbl_div22_hi = (ahi) / (bhi); \ 272 double __estim_dbldbl_div22_lo = (alo) / (bhi); \ 273 SCIPdbldblProd22(__tmp_dbldbl_div22_hi, __tmp_dbldbl_div22_lo, \ 274 bhi, blo, __estim_dbldbl_div22_hi, __estim_dbldbl_div22_lo); \ 275 SCIPdbldblSum22(__tmp_dbldbl_div22_hi, __tmp_dbldbl_div22_lo, \ 276 __tmp_dbldbl_div22_hi, __tmp_dbldbl_div22_lo, -(ahi), -(alo)); \ 277 __tmp_dbldbl_div22_hi /= (bhi); \ 278 __tmp_dbldbl_div22_lo /= (bhi); \ 279 SCIPdbldblSum22(rhi, rlo, __estim_dbldbl_div22_hi, __estim_dbldbl_div22_lo, \ 280 -__tmp_dbldbl_div22_hi, -__tmp_dbldbl_div22_lo); \ 285 #define SCIPdbldblSqrt(rhi, rlo, a) \ 287 double __estim_dbldbl_sqrt = sqrt(a); \ 288 if( __estim_dbldbl_sqrt != 0.0 ) \ 290 SCIPdbldblDiv(rhi, rlo, a, __estim_dbldbl_sqrt); \ 291 SCIPdbldblSum21(rhi, rlo, rhi, rlo, __estim_dbldbl_sqrt); \ 304 #define SCIPdbldblSqrt2(rhi, rlo, ahi, alo) \ 306 double __estim_dbldbl_sqrt2 = sqrt(ahi + alo); \ 307 if( __estim_dbldbl_sqrt2 != 0.0 ) \ 309 SCIPdbldblDiv21(rhi, rlo, ahi, alo, __estim_dbldbl_sqrt2); \ 310 SCIPdbldblSum21(rhi, rlo, rhi, rlo, __estim_dbldbl_sqrt2); \ 322 #define SCIPdbldblAbs2(rhi, rlo, ahi, alo) \ 337 #define SCIPdbldblFloor2(rhi, rlo, ahi, alo) \ 339 double __tmp_dbldbl_floor; \ 340 __tmp_dbldbl_floor = floor((ahi) + (alo)); \ 341 SCIPdbldblSum21(rhi, rlo, ahi, alo, -__tmp_dbldbl_floor); \ 342 if( ((rhi) - 1.0) + (rlo) < 0.0 && (rhi) + (rlo) >= 0.0 ) \ 345 (rhi) = __tmp_dbldbl_floor; \ 351 double __tmp2_dbldbl_floor = floor((rhi) + (rlo)); \ 352 SCIPdbldblSum(rhi, rlo, __tmp_dbldbl_floor, __tmp2_dbldbl_floor); \ 357 #define SCIPdbldblCeil2(rhi, rlo, ahi, alo) \ 359 double __tmp_dbldbl_ceil; \ 360 __tmp_dbldbl_ceil = ceil((ahi) + (alo)); \ 361 SCIPdbldblSum21(rhi, rlo, -(ahi), -(alo), __tmp_dbldbl_ceil); \ 362 if( ((rhi) - 1.0) + (rlo) < 0.0 && (rhi) + (rlo) >= 0.0 ) \ 365 (rhi) = __tmp_dbldbl_ceil; \ 371 double __tmp2_dbldbl_ceil = floor((rhi) + (rlo)); \ 372 SCIPdbldblSum(rhi, rlo, __tmp_dbldbl_ceil, -__tmp2_dbldbl_ceil); \ 377 #define SCIPdbldblEpsFloor2(rhi, rlo, ahi, alo, eps) SCIPdbldblFloor2(rhi, rlo, ahi, (alo) + (eps)) 380 #define SCIPdbldblEpsCeil2(rhi, rlo, ahi, alo, eps) SCIPdbldblCeil2(rhi, rlo, ahi, (alo) - (eps))