pub const SPLITTER: f64 = 134217729.0;
pub const RESULTERRBOUND: f64 = (3.0 + 8.0 * f64::EPSILON) * f64::EPSILON;
pub const CCWERRBOUND_A: f64 = (3.0 + 16.0 * f64::EPSILON) * f64::EPSILON;
pub const CCWERRBOUND_B: f64 = (2.0 + 12.0 * f64::EPSILON) * f64::EPSILON;
pub const CCWERRBOUND_C: f64 = (9.0 + 64.0 * f64::EPSILON) * f64::EPSILON * f64::EPSILON;
pub fn pred_sum(elen: usize, e: &[f64], flen: usize, f: &[f64], h: &mut [f64]) -> usize {
let mut q: f64;
let mut qnew: f64;
let mut hh: f64;
let mut bvirt: f64;
let mut enow = e[0];
let mut fnow = f[0];
let mut eindex = 0;
let mut findex = 0;
if (fnow > enow) == (fnow > -enow) {
q = enow;
eindex += 1;
enow = e.get(eindex).copied().unwrap_or(0.);
} else {
q = fnow;
findex += 1;
fnow = f.get(findex).copied().unwrap_or(0.);
}
let mut hindex = 0;
if eindex < elen && findex < flen {
if (fnow > enow) == (fnow > -enow) {
qnew = enow + q;
hh = q - (qnew - enow);
eindex += 1;
enow = e.get(eindex).copied().unwrap_or(0.);
} else {
qnew = fnow + q;
hh = q - (qnew - fnow);
findex += 1;
fnow = f.get(findex).copied().unwrap_or(0.);
}
q = qnew;
if hh != 0. {
h[hindex] = hh;
hindex += 1;
}
while eindex < elen && findex < flen {
if (fnow > enow) == (fnow > -enow) {
qnew = q + enow;
bvirt = qnew - q;
hh = q - (qnew - bvirt) + (enow - bvirt);
eindex += 1;
enow = e.get(eindex).copied().unwrap_or(0.);
} else {
qnew = q + fnow;
bvirt = qnew - q;
hh = q - (qnew - bvirt) + (fnow - bvirt);
findex += 1;
fnow = f.get(findex).copied().unwrap_or(0.);
}
q = qnew;
if hh != 0. {
h[hindex] = hh;
hindex += 1;
}
}
}
while eindex < elen {
qnew = q + enow;
bvirt = qnew - q;
hh = q - (qnew - bvirt) + (enow - bvirt);
eindex += 1;
enow = e.get(eindex).copied().unwrap_or(0.);
q = qnew;
if hh != 0. {
h[hindex] = hh;
hindex += 1;
}
}
while findex < flen {
qnew = q + fnow;
bvirt = qnew - q;
hh = q - (qnew - bvirt) + (fnow - bvirt);
findex += 1;
fnow = f.get(findex).copied().unwrap_or(0.);
q = qnew;
if hh != 0. {
h[hindex] = hh;
hindex += 1;
}
}
if q != 0. || hindex == 0 {
h[hindex] = q;
hindex += 1;
}
hindex
}
pub fn estimate(elen: usize, e: &[f64]) -> f64 {
e.iter().take(elen).skip(1).sum()
}