11 * This is a C version of Kahan's proposed benchmark for determining the worst accuracy of a CPU
12 * Taken from kahan1996iee754 - Lecture notes on the status of IEEE 754
17 * Quadradic of the form p*x^2 - 2 q*x + r == 0
18 * This function computes the roots x1 and x2 as accuractely as they are determined by {p, q, r}
20 void Qdrtc(Real p, Real q, Real r, Real * x1, Real * x2)
22 Real s = sqrt(q*q - p*r);
23 Real S = q + copysignf(s, q);
35 * Kahan's magic Qtrial test thing
36 * Calculate roots using Qdrtc and compare to known results
37 * Return the smallest (?) of the errors
43 Real result = Real(0);
44 Debug("Qdrtc for r = %.30lf", Float(r));
46 Fatal("Expect r > 2");
47 else if (!((r-q)== Real(1) && (q-p) == Real(1)))
48 Fatal("r too big for Qtrial %.30lf", Float(r));
51 Qdrtc(p, q, r, &x1, &x2);
52 Real e1 = -log2f(x1 - Real(1));
53 Real e2 = -log2f((x2 - Real(1)) - Real(2)/p);
56 Debug("gets %.30lf and %.30lf sig bits", Float(e1), Float(e2));
58 Debug(" and root %.30lf isn't at least 1", Float(x1));
62 int main(int argc, char ** argv)
65 Qdrtc(2,5,12,&x1,&x2);
66 if (x1 != Real(2) || x2 != Real(3))
68 Fatal("Qdrtc(2, 5, 12) failed sanity check; x1 %.30lf x2 %.30lf", Float(x1), Float(x2));
73 r[0] = (1 << 12) + 2.0;
74 r[1] = (1 << 12) + 2.25;
75 r[2] = (16 << 8) + 1.0 + 1.0/(16<<4);
79 r[6] = 94906267 + 0.25;
83 r[10] = (1<<28) + 2.25;
84 r[11] = (16<<24) + 1 + 1.0/(16<<20);
85 // r[12] = (1<<32) + 2.0;
86 // r[13] = (1<<32) + 2.25;
90 for (size_t j = 0; j < n; ++j)
93 if (t < e || t != t) e = t;
95 Debug("Worst accuracy is %.30lf sig. bits", Float(e));