use hexf::hexf64;
use num_traits::{Float, FloatConst};
use strafe_type::{Finite64, FloatConstraint, Real64};
use crate::{distribution::gamma::log1pmx, traits::DPQ};
pub fn bd0<F1: Into<Finite64>, F2: Into<Finite64>>(x: F1, np: F2) -> Real64 {
let mut ej = 0.0; let mut s = 0.0;
let mut s1 = 0.0;
let mut v = 0.0;
let mut j = 0;
let x = x.into().unwrap();
let np = np.into().unwrap();
if (x - np).abs() < 0.1 * (x + np) {
v = (x - np) / (x + np);
s = (x - np) * v;
if s.abs() < 2.2250738585072014e-308 {
return s.into();
}
ej = 2.0 * x * v;
v = v * v;
j = 1;
while j < 1000 {
ej *= v; s1 = s + ej / ((j << 1) + 1) as f64;
if s1 == s {
return s1.into();
}
s = s1;
j += 1
}
warn!(
"bd0({}, {}): T.series failed to converge in 1000 it.; s={}, ej/(2j+1)={}\n",
x,
np,
s,
ej / ((1000 << 1) + 1) as f64
);
}
(x * (x / np).ln() + np - x).into()
}
const BD0_SCALE: [[f64; 4]; 128 + 1] = [
[
hexf64!("+0x1.62e430p-1"),
hexf64!("-0x1.05c610p-29"),
hexf64!("-0x1.950d88p-54"),
hexf64!("+0x1.d9cc02p-79"),
],
[
hexf64!("+0x1.5ee02cp-1"),
hexf64!("-0x1.6dbe98p-25"),
hexf64!("-0x1.51e540p-50"),
hexf64!("+0x1.2bfa48p-74"),
],
[
hexf64!("+0x1.5ad404p-1"),
hexf64!("+0x1.86b3e4p-26"),
hexf64!("+0x1.9f6534p-50"),
hexf64!("+0x1.54be04p-74"),
],
[
hexf64!("+0x1.570124p-1"),
hexf64!("-0x1.9ed750p-25"),
hexf64!("-0x1.f37dd0p-51"),
hexf64!("+0x1.10b770p-77"),
],
[
hexf64!("+0x1.5326e4p-1"),
hexf64!("-0x1.9b9874p-25"),
hexf64!("-0x1.378194p-49"),
hexf64!("+0x1.56feb2p-74"),
],
[
hexf64!("+0x1.4f4528p-1"),
hexf64!("+0x1.aca70cp-28"),
hexf64!("+0x1.103e74p-53"),
hexf64!("+0x1.9c410ap-81"),
],
[
hexf64!("+0x1.4b5bd8p-1"),
hexf64!("-0x1.6a91d8p-25"),
hexf64!("-0x1.8e43d0p-50"),
hexf64!("-0x1.afba9ep-77"),
],
[
hexf64!("+0x1.47ae54p-1"),
hexf64!("-0x1.abb51cp-25"),
hexf64!("+0x1.19b798p-51"),
hexf64!("+0x1.45e09cp-76"),
],
[
hexf64!("+0x1.43fa00p-1"),
hexf64!("-0x1.d06318p-25"),
hexf64!("-0x1.8858d8p-49"),
hexf64!("-0x1.1927c4p-75"),
],
[
hexf64!("+0x1.3ffa40p-1"),
hexf64!("+0x1.1a427cp-25"),
hexf64!("+0x1.151640p-53"),
hexf64!("-0x1.4f5606p-77"),
],
[
hexf64!("+0x1.3c7c80p-1"),
hexf64!("-0x1.19bf48p-34"),
hexf64!("+0x1.05fc94p-58"),
hexf64!("-0x1.c096fcp-82"),
],
[
hexf64!("+0x1.38b320p-1"),
hexf64!("+0x1.6b5778p-25"),
hexf64!("+0x1.be38d0p-50"),
hexf64!("-0x1.075e96p-74"),
],
[
hexf64!("+0x1.34e288p-1"),
hexf64!("+0x1.d9ce1cp-25"),
hexf64!("+0x1.316eb8p-49"),
hexf64!("+0x1.2d885cp-73"),
],
[
hexf64!("+0x1.315124p-1"),
hexf64!("+0x1.c2fc60p-29"),
hexf64!("-0x1.4396fcp-53"),
hexf64!("+0x1.acf376p-78"),
],
[
hexf64!("+0x1.2db954p-1"),
hexf64!("+0x1.720de4p-25"),
hexf64!("-0x1.d39b04p-49"),
hexf64!("-0x1.f11176p-76"),
],
[
hexf64!("+0x1.2a1b08p-1"),
hexf64!("-0x1.562494p-25"),
hexf64!("+0x1.a7863cp-49"),
hexf64!("+0x1.85dd64p-73"),
],
[
hexf64!("+0x1.267620p-1"),
hexf64!("+0x1.3430e0p-29"),
hexf64!("-0x1.96a958p-56"),
hexf64!("+0x1.f8e636p-82"),
],
[
hexf64!("+0x1.23130cp-1"),
hexf64!("+0x1.7bebf4p-25"),
hexf64!("+0x1.416f1cp-52"),
hexf64!("-0x1.78dd36p-77"),
],
[
hexf64!("+0x1.1faa34p-1"),
hexf64!("+0x1.70e128p-26"),
hexf64!("+0x1.81817cp-50"),
hexf64!("-0x1.c2179cp-76"),
],
[
hexf64!("+0x1.1bf204p-1"),
hexf64!("+0x1.3a9620p-28"),
hexf64!("+0x1.2f94c0p-52"),
hexf64!("+0x1.9096c0p-76"),
],
[
hexf64!("+0x1.187ce4p-1"),
hexf64!("-0x1.077870p-27"),
hexf64!("+0x1.655a80p-51"),
hexf64!("+0x1.eaafd6p-78"),
],
[
hexf64!("+0x1.1501c0p-1"),
hexf64!("-0x1.406cacp-25"),
hexf64!("-0x1.e72290p-49"),
hexf64!("+0x1.5dd800p-73"),
],
[
hexf64!("+0x1.11cb80p-1"),
hexf64!("+0x1.787cd0p-25"),
hexf64!("-0x1.efdc78p-51"),
hexf64!("-0x1.5380cep-77"),
],
[
hexf64!("+0x1.0e4498p-1"),
hexf64!("+0x1.747324p-27"),
hexf64!("-0x1.024548p-51"),
hexf64!("+0x1.77a5a6p-75"),
],
[
hexf64!("+0x1.0b036cp-1"),
hexf64!("+0x1.690c74p-25"),
hexf64!("+0x1.5d0cc4p-50"),
hexf64!("-0x1.c0e23cp-76"),
],
[
hexf64!("+0x1.077070p-1"),
hexf64!("-0x1.a769bcp-27"),
hexf64!("+0x1.452234p-52"),
hexf64!("+0x1.6ba668p-76"),
],
[
hexf64!("+0x1.04240cp-1"),
hexf64!("-0x1.a686acp-27"),
hexf64!("-0x1.ef46b0p-52"),
hexf64!("-0x1.5ce10cp-76"),
],
[
hexf64!("+0x1.00d22cp-1"),
hexf64!("+0x1.fc0e10p-25"),
hexf64!("+0x1.6ee034p-50"),
hexf64!("-0x1.19a2ccp-74"),
],
[
hexf64!("+0x1.faf588p-2"),
hexf64!("+0x1.ef1e64p-27"),
hexf64!("-0x1.26504cp-54"),
hexf64!("-0x1.b15792p-82"),
],
[
hexf64!("+0x1.f4d87cp-2"),
hexf64!("+0x1.d7b980p-26"),
hexf64!("-0x1.a114d8p-50"),
hexf64!("+0x1.9758c6p-75"),
],
[
hexf64!("+0x1.ee1414p-2"),
hexf64!("+0x1.2ec060p-26"),
hexf64!("+0x1.dc00fcp-52"),
hexf64!("+0x1.f8833cp-76"),
],
[
hexf64!("+0x1.e7e32cp-2"),
hexf64!("-0x1.ac796cp-27"),
hexf64!("-0x1.a68818p-54"),
hexf64!("+0x1.235d02p-78"),
],
[
hexf64!("+0x1.e108a0p-2"),
hexf64!("-0x1.768ba4p-28"),
hexf64!("-0x1.f050a8p-52"),
hexf64!("+0x1.00d632p-82"),
],
[
hexf64!("+0x1.dac354p-2"),
hexf64!("-0x1.d3a6acp-30"),
hexf64!("+0x1.18734cp-57"),
hexf64!("-0x1.f97902p-83"),
],
[
hexf64!("+0x1.d47424p-2"),
hexf64!("+0x1.7dbbacp-31"),
hexf64!("-0x1.d5ada4p-56"),
hexf64!("+0x1.56fcaap-81"),
],
[
hexf64!("+0x1.ce1af0p-2"),
hexf64!("+0x1.70be7cp-27"),
hexf64!("+0x1.6f6fa4p-51"),
hexf64!("+0x1.7955a2p-75"),
],
[
hexf64!("+0x1.c7b798p-2"),
hexf64!("+0x1.ec36ecp-26"),
hexf64!("-0x1.07e294p-50"),
hexf64!("-0x1.ca183cp-75"),
],
[
hexf64!("+0x1.c1ef04p-2"),
hexf64!("+0x1.c1dfd4p-26"),
hexf64!("+0x1.888eecp-50"),
hexf64!("-0x1.fd6b86p-75"),
],
[
hexf64!("+0x1.bb7810p-2"),
hexf64!("+0x1.478bfcp-26"),
hexf64!("+0x1.245b8cp-50"),
hexf64!("+0x1.ea9d52p-74"),
],
[
hexf64!("+0x1.b59da0p-2"),
hexf64!("-0x1.882b08p-27"),
hexf64!("+0x1.31573cp-53"),
hexf64!("-0x1.8c249ap-77"),
],
[
hexf64!("+0x1.af1294p-2"),
hexf64!("-0x1.b710f4p-27"),
hexf64!("+0x1.622670p-51"),
hexf64!("+0x1.128578p-76"),
],
[
hexf64!("+0x1.a925d4p-2"),
hexf64!("-0x1.0ae750p-27"),
hexf64!("+0x1.574ed4p-51"),
hexf64!("+0x1.084996p-75"),
],
[
hexf64!("+0x1.a33040p-2"),
hexf64!("+0x1.027d30p-29"),
hexf64!("+0x1.b9a550p-53"),
hexf64!("-0x1.b2e38ap-78"),
],
[
hexf64!("+0x1.9d31c0p-2"),
hexf64!("-0x1.5ec12cp-26"),
hexf64!("-0x1.5245e0p-52"),
hexf64!("+0x1.2522d0p-79"),
],
[
hexf64!("+0x1.972a34p-2"),
hexf64!("+0x1.135158p-30"),
hexf64!("+0x1.a5c09cp-56"),
hexf64!("+0x1.24b70ep-80"),
],
[
hexf64!("+0x1.911984p-2"),
hexf64!("+0x1.0995d4p-26"),
hexf64!("+0x1.3bfb5cp-50"),
hexf64!("+0x1.2c9dd6p-75"),
],
[
hexf64!("+0x1.8bad98p-2"),
hexf64!("-0x1.1d6144p-29"),
hexf64!("+0x1.5b9208p-53"),
hexf64!("+0x1.1ec158p-77"),
],
[
hexf64!("+0x1.858b58p-2"),
hexf64!("-0x1.1b4678p-27"),
hexf64!("+0x1.56cab4p-53"),
hexf64!("-0x1.2fdc0cp-78"),
],
[
hexf64!("+0x1.7f5fa0p-2"),
hexf64!("+0x1.3aaf48p-27"),
hexf64!("+0x1.461964p-51"),
hexf64!("+0x1.4ae476p-75"),
],
[
hexf64!("+0x1.79db68p-2"),
hexf64!("-0x1.7e5054p-26"),
hexf64!("+0x1.673750p-51"),
hexf64!("-0x1.a11f7ap-76"),
],
[
hexf64!("+0x1.744f88p-2"),
hexf64!("-0x1.cc0e18p-26"),
hexf64!("-0x1.1e9d18p-50"),
hexf64!("-0x1.6c06bcp-78"),
],
[
hexf64!("+0x1.6e08ecp-2"),
hexf64!("-0x1.5d45e0p-26"),
hexf64!("-0x1.c73ec8p-50"),
hexf64!("+0x1.318d72p-74"),
],
[
hexf64!("+0x1.686c80p-2"),
hexf64!("+0x1.e9b14cp-26"),
hexf64!("-0x1.13bbd4p-50"),
hexf64!("-0x1.efeb1cp-78"),
],
[
hexf64!("+0x1.62c830p-2"),
hexf64!("-0x1.a8c70cp-27"),
hexf64!("-0x1.5a1214p-51"),
hexf64!("-0x1.bab3fcp-79"),
],
[
hexf64!("+0x1.5d1bdcp-2"),
hexf64!("-0x1.4fec6cp-31"),
hexf64!("+0x1.423638p-56"),
hexf64!("+0x1.ee3feep-83"),
],
[
hexf64!("+0x1.576770p-2"),
hexf64!("+0x1.7455a8p-26"),
hexf64!("-0x1.3ab654p-50"),
hexf64!("-0x1.26be4cp-75"),
],
[
hexf64!("+0x1.5262e0p-2"),
hexf64!("-0x1.146778p-26"),
hexf64!("-0x1.b9f708p-52"),
hexf64!("-0x1.294018p-77"),
],
[
hexf64!("+0x1.4c9f08p-2"),
hexf64!("+0x1.e152c4p-26"),
hexf64!("-0x1.dde710p-53"),
hexf64!("+0x1.fd2208p-77"),
],
[
hexf64!("+0x1.46d2d8p-2"),
hexf64!("+0x1.c28058p-26"),
hexf64!("-0x1.936284p-50"),
hexf64!("+0x1.9fdd68p-74"),
],
[
hexf64!("+0x1.41b940p-2"),
hexf64!("+0x1.cce0c0p-26"),
hexf64!("-0x1.1a4050p-50"),
hexf64!("+0x1.bc0376p-76"),
],
[
hexf64!("+0x1.3bdd24p-2"),
hexf64!("+0x1.d6296cp-27"),
hexf64!("+0x1.425b48p-51"),
hexf64!("-0x1.cddb2cp-77"),
],
[
hexf64!("+0x1.36b578p-2"),
hexf64!("-0x1.287ddcp-27"),
hexf64!("-0x1.2d0f4cp-51"),
hexf64!("+0x1.38447ep-75"),
],
[
hexf64!("+0x1.31871cp-2"),
hexf64!("+0x1.2a8830p-27"),
hexf64!("+0x1.3eae54p-52"),
hexf64!("-0x1.898136p-77"),
],
[
hexf64!("+0x1.2b9304p-2"),
hexf64!("-0x1.51d8b8p-28"),
hexf64!("+0x1.27694cp-52"),
hexf64!("-0x1.fd852ap-76"),
],
[
hexf64!("+0x1.265620p-2"),
hexf64!("-0x1.d98f3cp-27"),
hexf64!("+0x1.a44338p-51"),
hexf64!("-0x1.56e85ep-78"),
],
[
hexf64!("+0x1.211254p-2"),
hexf64!("+0x1.986160p-26"),
hexf64!("+0x1.73c5d0p-51"),
hexf64!("+0x1.4a861ep-75"),
],
[
hexf64!("+0x1.1bc794p-2"),
hexf64!("+0x1.fa3918p-27"),
hexf64!("+0x1.879c5cp-51"),
hexf64!("+0x1.16107cp-78"),
],
[
hexf64!("+0x1.1675ccp-2"),
hexf64!("-0x1.4545a0p-26"),
hexf64!("+0x1.c07398p-51"),
hexf64!("+0x1.f55c42p-76"),
],
[
hexf64!("+0x1.111ce4p-2"),
hexf64!("+0x1.f72670p-37"),
hexf64!("-0x1.b84b5cp-61"),
hexf64!("+0x1.a4a4dcp-85"),
],
[
hexf64!("+0x1.0c81d4p-2"),
hexf64!("+0x1.0c150cp-27"),
hexf64!("+0x1.218600p-51"),
hexf64!("-0x1.d17312p-76"),
],
[
hexf64!("+0x1.071b84p-2"),
hexf64!("+0x1.fcd590p-26"),
hexf64!("+0x1.a3a2e0p-51"),
hexf64!("+0x1.fe5ef8p-76"),
],
[
hexf64!("+0x1.01ade4p-2"),
hexf64!("-0x1.bb1844p-28"),
hexf64!("+0x1.db3cccp-52"),
hexf64!("+0x1.1f56fcp-77"),
],
[
hexf64!("+0x1.fa01c4p-3"),
hexf64!("-0x1.12a0d0p-29"),
hexf64!("-0x1.f71fb0p-54"),
hexf64!("+0x1.e287a4p-78"),
],
[
hexf64!("+0x1.ef0adcp-3"),
hexf64!("+0x1.7b8b28p-28"),
hexf64!("-0x1.35bce4p-52"),
hexf64!("-0x1.abc8f8p-79"),
],
[
hexf64!("+0x1.e598ecp-3"),
hexf64!("+0x1.5a87e4p-27"),
hexf64!("-0x1.134bd0p-51"),
hexf64!("+0x1.c2cebep-76"),
],
[
hexf64!("+0x1.da85d8p-3"),
hexf64!("-0x1.df31b0p-27"),
hexf64!("+0x1.94c16cp-57"),
hexf64!("+0x1.8fd7eap-82"),
],
[
hexf64!("+0x1.d0fb80p-3"),
hexf64!("-0x1.bb5434p-28"),
hexf64!("-0x1.ea5640p-52"),
hexf64!("-0x1.8ceca4p-77"),
],
[
hexf64!("+0x1.c765b8p-3"),
hexf64!("+0x1.e4d68cp-27"),
hexf64!("+0x1.5b59b4p-51"),
hexf64!("+0x1.76f6c4p-76"),
],
[
hexf64!("+0x1.bdc46cp-3"),
hexf64!("-0x1.1cbb50p-27"),
hexf64!("+0x1.2da010p-51"),
hexf64!("+0x1.eb282cp-75"),
],
[
hexf64!("+0x1.b27980p-3"),
hexf64!("-0x1.1b9ce0p-27"),
hexf64!("+0x1.7756f8p-52"),
hexf64!("+0x1.2ff572p-76"),
],
[
hexf64!("+0x1.a8bed0p-3"),
hexf64!("-0x1.bbe874p-30"),
hexf64!("+0x1.85cf20p-56"),
hexf64!("+0x1.b9cf18p-80"),
],
[
hexf64!("+0x1.9ef83cp-3"),
hexf64!("+0x1.2769a4p-27"),
hexf64!("-0x1.85bda0p-52"),
hexf64!("+0x1.8c8018p-79"),
],
[
hexf64!("+0x1.9525a8p-3"),
hexf64!("+0x1.cf456cp-27"),
hexf64!("-0x1.7137d8p-52"),
hexf64!("-0x1.f158e8p-76"),
],
[
hexf64!("+0x1.8b46f8p-3"),
hexf64!("+0x1.11b12cp-30"),
hexf64!("+0x1.9f2104p-54"),
hexf64!("-0x1.22836ep-78"),
],
[
hexf64!("+0x1.83040cp-3"),
hexf64!("+0x1.2379e4p-28"),
hexf64!("+0x1.b71c70p-52"),
hexf64!("-0x1.990cdep-76"),
],
[
hexf64!("+0x1.790ed4p-3"),
hexf64!("+0x1.dc4c68p-28"),
hexf64!("-0x1.910ac8p-52"),
hexf64!("+0x1.dd1bd6p-76"),
],
[
hexf64!("+0x1.6f0d28p-3"),
hexf64!("+0x1.5cad68p-28"),
hexf64!("+0x1.737c94p-52"),
hexf64!("-0x1.9184bap-77"),
],
[
hexf64!("+0x1.64fee8p-3"),
hexf64!("+0x1.04bf88p-28"),
hexf64!("+0x1.6fca28p-52"),
hexf64!("+0x1.8884a8p-76"),
],
[
hexf64!("+0x1.5c9400p-3"),
hexf64!("+0x1.d65cb0p-29"),
hexf64!("-0x1.b2919cp-53"),
hexf64!("+0x1.b99bcep-77"),
],
[
hexf64!("+0x1.526e60p-3"),
hexf64!("-0x1.c5e4bcp-27"),
hexf64!("-0x1.0ba380p-52"),
hexf64!("+0x1.d6e3ccp-79"),
],
[
hexf64!("+0x1.483bccp-3"),
hexf64!("+0x1.9cdc7cp-28"),
hexf64!("-0x1.5ad8dcp-54"),
hexf64!("-0x1.392d3cp-83"),
],
[
hexf64!("+0x1.3fb25cp-3"),
hexf64!("-0x1.a6ad74p-27"),
hexf64!("+0x1.5be6b4p-52"),
hexf64!("-0x1.4e0114p-77"),
],
[
hexf64!("+0x1.371fc4p-3"),
hexf64!("-0x1.fe1708p-27"),
hexf64!("-0x1.78864cp-52"),
hexf64!("-0x1.27543ap-76"),
],
[
hexf64!("+0x1.2cca10p-3"),
hexf64!("-0x1.4141b4p-28"),
hexf64!("-0x1.ef191cp-52"),
hexf64!("+0x1.00ee08p-76"),
],
[
hexf64!("+0x1.242310p-3"),
hexf64!("+0x1.3ba510p-27"),
hexf64!("-0x1.d003c8p-51"),
hexf64!("+0x1.162640p-76"),
],
[
hexf64!("+0x1.1b72acp-3"),
hexf64!("+0x1.52f67cp-27"),
hexf64!("-0x1.fd6fa0p-51"),
hexf64!("+0x1.1a3966p-77"),
],
[
hexf64!("+0x1.10f8e4p-3"),
hexf64!("+0x1.129cd8p-30"),
hexf64!("+0x1.31ef30p-55"),
hexf64!("+0x1.a73e38p-79"),
],
[
hexf64!("+0x1.08338cp-3"),
hexf64!("-0x1.005d7cp-27"),
hexf64!("-0x1.661a9cp-51"),
hexf64!("+0x1.1f138ap-79"),
],
[
hexf64!("+0x1.fec914p-4"),
hexf64!("-0x1.c482a8p-29"),
hexf64!("-0x1.55746cp-54"),
hexf64!("+0x1.99f932p-80"),
],
[
hexf64!("+0x1.ed1794p-4"),
hexf64!("+0x1.d06f00p-29"),
hexf64!("+0x1.75e45cp-53"),
hexf64!("-0x1.d0483ep-78"),
],
[
hexf64!("+0x1.db5270p-4"),
hexf64!("+0x1.87d928p-32"),
hexf64!("-0x1.0f52a4p-57"),
hexf64!("+0x1.81f4a6p-84"),
],
[
hexf64!("+0x1.c97978p-4"),
hexf64!("+0x1.af1d24p-29"),
hexf64!("-0x1.0977d0p-60"),
hexf64!("-0x1.8839d0p-84"),
],
[
hexf64!("+0x1.b78c84p-4"),
hexf64!("-0x1.44f124p-28"),
hexf64!("-0x1.ef7bc4p-52"),
hexf64!("+0x1.9e0650p-78"),
],
[
hexf64!("+0x1.a58b60p-4"),
hexf64!("+0x1.856464p-29"),
hexf64!("+0x1.c651d0p-55"),
hexf64!("+0x1.b06b0cp-79"),
],
[
hexf64!("+0x1.9375e4p-4"),
hexf64!("+0x1.5595ecp-28"),
hexf64!("+0x1.dc3738p-52"),
hexf64!("+0x1.86c89ap-81"),
],
[
hexf64!("+0x1.814be4p-4"),
hexf64!("-0x1.c073fcp-28"),
hexf64!("-0x1.371f88p-53"),
hexf64!("-0x1.5f4080p-77"),
],
[
hexf64!("+0x1.6f0d28p-4"),
hexf64!("+0x1.5cad68p-29"),
hexf64!("+0x1.737c94p-53"),
hexf64!("-0x1.9184bap-78"),
],
[
hexf64!("+0x1.60658cp-4"),
hexf64!("-0x1.6c8af4p-28"),
hexf64!("+0x1.d8ef74p-55"),
hexf64!("+0x1.c4f792p-80"),
],
[
hexf64!("+0x1.4e0110p-4"),
hexf64!("+0x1.146b5cp-29"),
hexf64!("+0x1.73f7ccp-54"),
hexf64!("-0x1.d28db8p-79"),
],
[
hexf64!("+0x1.3b8758p-4"),
hexf64!("+0x1.8b1b70p-28"),
hexf64!("-0x1.20aca4p-52"),
hexf64!("-0x1.651894p-76"),
],
[
hexf64!("+0x1.28f834p-4"),
hexf64!("+0x1.43b6a4p-30"),
hexf64!("-0x1.452af8p-55"),
hexf64!("+0x1.976892p-80"),
],
[
hexf64!("+0x1.1a0fbcp-4"),
hexf64!("-0x1.e4075cp-28"),
hexf64!("+0x1.1fe618p-52"),
hexf64!("+0x1.9d6dc2p-77"),
],
[
hexf64!("+0x1.075984p-4"),
hexf64!("-0x1.4ce370p-29"),
hexf64!("-0x1.d9fc98p-53"),
hexf64!("+0x1.4ccf12p-77"),
],
[
hexf64!("+0x1.f0a30cp-5"),
hexf64!("+0x1.162a68p-37"),
hexf64!("-0x1.e83368p-61"),
hexf64!("-0x1.d222a6p-86"),
],
[
hexf64!("+0x1.cae730p-5"),
hexf64!("-0x1.1a8f7cp-31"),
hexf64!("-0x1.5f9014p-55"),
hexf64!("+0x1.2720c0p-79"),
],
[
hexf64!("+0x1.ac9724p-5"),
hexf64!("-0x1.e8ee08p-29"),
hexf64!("+0x1.a7de04p-54"),
hexf64!("-0x1.9bba74p-78"),
],
[
hexf64!("+0x1.868a84p-5"),
hexf64!("-0x1.ef8128p-30"),
hexf64!("+0x1.dc5eccp-54"),
hexf64!("-0x1.58d250p-79"),
],
[
hexf64!("+0x1.67f950p-5"),
hexf64!("-0x1.ed684cp-30"),
hexf64!("-0x1.f060c0p-55"),
hexf64!("-0x1.b1294cp-80"),
],
[
hexf64!("+0x1.494accp-5"),
hexf64!("+0x1.a6c890p-32"),
hexf64!("-0x1.c3ad48p-56"),
hexf64!("-0x1.6dc66cp-84"),
],
[
hexf64!("+0x1.22c71cp-5"),
hexf64!("-0x1.8abe2cp-32"),
hexf64!("-0x1.7e7078p-56"),
hexf64!("-0x1.ddc3dcp-86"),
],
[
hexf64!("+0x1.03d5d8p-5"),
hexf64!("+0x1.79cfbcp-31"),
hexf64!("-0x1.da7c4cp-58"),
hexf64!("+0x1.4e7582p-83"),
],
[
hexf64!("+0x1.c98d18p-6"),
hexf64!("+0x1.a01904p-31"),
hexf64!("-0x1.854164p-55"),
hexf64!("+0x1.883c36p-79"),
],
[
hexf64!("+0x1.8b31fcp-6"),
hexf64!("-0x1.356500p-30"),
hexf64!("+0x1.c3ab48p-55"),
hexf64!("+0x1.b69bdap-80"),
],
[
hexf64!("+0x1.3cea44p-6"),
hexf64!("+0x1.a352bcp-33"),
hexf64!("-0x1.8865acp-57"),
hexf64!("-0x1.48159cp-81"),
],
[
hexf64!("+0x1.fc0a8cp-7"),
hexf64!("-0x1.e07f84p-32"),
hexf64!("+0x1.e7cf6cp-58"),
hexf64!("+0x1.3a69c0p-82"),
],
[
hexf64!("+0x1.7dc474p-7"),
hexf64!("+0x1.f810a8p-31"),
hexf64!("-0x1.245b5cp-56"),
hexf64!("-0x1.a1f4f8p-80"),
],
[
hexf64!("+0x1.fe02a8p-8"),
hexf64!("-0x1.4ef988p-32"),
hexf64!("+0x1.1f86ecp-57"),
hexf64!("+0x1.20723cp-81"),
],
[
hexf64!("+0x1.ff00acp-9"),
hexf64!("-0x1.d4ef44p-33"),
hexf64!("+0x1.2821acp-63"),
hexf64!("+0x1.5a6d32p-87"),
],
[0.0, 0.0, 0.0, 0.0],
];
fn frexp(s: f64) -> (f64, f64) {
if 0.0 == s {
(s, 0.0)
} else {
let lg = s.abs().log2();
let x = (lg - lg.floor() - 1.0).exp2();
let exp = lg.floor() + 1.0;
(s.signum() * x, exp)
}
}
pub fn ebd0(x: f64, M: f64, yh: &mut f64, yl: &mut f64) {
const Sb: i32 = 10;
const S: f64 = (1 << Sb) as f64; const N: f64 = 128.0;
*yl = 0.0;
*yh = 0.0;
if x == M {
return;
}
if x == 0.0 {
*yh = M;
return;
}
if M == 0.0 {
*yh = f64::infinity();
return;
}
if M / x == f64::infinity() {
*yh = M;
return;
}
let (r, e) = frexp(M / x);
if f64::LN_2() * (-e) > 1.0 + f64::max_value() / x {
*yh = f64::infinity();
return;
}
let i = ((r - 0.5) * (2.0 * N) + 0.5).floor();
let f = (S / (0.5 + i / (2.0 * N)) + 0.5).floor();
let fg = f.ldexp(-(e + Sb as f64));
if fg == f64::infinity() {
*yh = fg;
return;
}
let add1 = |d_: f64, yh: &mut f64, yl: &mut f64| {
let d = d_;
let d1 = (d + 0.5).floor();
let d2 = d - d1;
*yh += d1;
*yl += d2;
};
let log1__ = log1pmx((M * fg - x) / x);
let xl = -x * log1__;
add1(xl, yh, yl);
if fg == 1.0 {
return;
}
for j in 0..4 {
add1(x * BD0_SCALE[i as usize][j], yh, yl); add1(-x * BD0_SCALE[0][j] * e, yh, yl); if !yh.is_finite() {
*yh = f64::infinity();
*yl = 0.0;
return;
}
}
add1(M, yh, yl);
add1(-M * fg, yh, yl);
}