-
Notifications
You must be signed in to change notification settings - Fork 1
/
dd-compare.ts
31 lines (25 loc) · 868 Bytes
/
dd-compare.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/**
* Returns 0 if a === b, a +tive value if a > b or a negative value if a < b.
*
* @param x a double-double precision floating point number
* @param y another double-double precision floating point number
*/
function ddCompare(x: number[], y: number[]) {
//return ddDiffDd(x,y)[1];
const xl = x[0];
const xh = x[1];
const yl = y[0];
const yh = y[1];
//const [sl,sh] = twoSum(xh,yh);
const sh = xh - yh; const _1 = sh - xh; const sl = (xh - (sh - _1)) + (-yh - _1);
//const [tl,th] = twoSum(xl,yl);
const th = xl - yl; const _2 = th - xl; const tl = (xl - (th - _2)) + (-yl - _2);
const c = sl + th;
//const [vl,vh] = fastTwoSum(sh,c)
const vh = sh + c; const vl = c - (vh - sh);
const w = tl + vl
//const [zl,zh] = fastTwoSum(vh,w)
const zh = vh + w;
return zh;
}
export { ddCompare }