#include #ifdef __NetBSD__ #include #else #include #define FP_PS 0 #define FP_PRS 1 #define FP_PD 2 #define FP_PE 3 int fpsetprec(int nprec) { uint32_t ocw, ncw; int oprec; asm volatile("fnstcw %0" : "=m"(ocw)); oprec = (ocw >> 8) & 3; ncw = (ocw & ~(uint32_t)(3 << 8)) | (uint32_t)((nprec & 3) << 8); asm volatile("fldcw %0" : : "m"(ncw)); return oprec; } #endif int main(void) { volatile double lo = 2.4608250784829636e-20; volatile double hi = 3.0026742508190853e+20; volatile double w, d; volatile size_t n = 100; fpsetprec(FP_PE); w = (hi - lo)/(n - 2); d = (n - 2)*w; printf("bad %.17e\n", hi - (n - 2)*w); printf("good %.17e\n", hi - d); fflush(stdout); return ferror(stdout); }