Overview
| Artifact ID: | 17d7cb4c2996b64ad32ad10010dce15f77dc9fb0 |
|---|---|
| Ticket: | 2143217fffffffffffffffffffffffffffffffff |
| Date: | 2008-10-03 05:43:44 |
| User: | [email protected] |
| Artifact Attached: | 8d3d8a8ad54a44e87db1a901a3084c2023192825 |
| Filename: | isqrt.c |
| Description: | extract from bn_mp_isqrt.c |
Content:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23// Show effect of optimisation of fp results. // Code taken from ~/src/tcl/tcl8.6a2/libtommath/bn_mp_sqrt.c // Shows bug in 'if (d != 0.0)', with d being inexact // Compile and run with - // make CC=/usr/local/gcc-4.2.1/bin/gcc CFLAGS=-O2 LDFLAGS=-lm isqrt && ./isqrt // #include <math.h> #include <stdio.h> int main() { double d = 0.0; int i; unsigned long dig; for (i = 0; i < 2; i++) { d = ldexp(d, 28) + (double)((1<<28)-1); //printf("d=%g=%a\n", d, d); } d=sqrt(d); dig = (unsigned long) ldexp(d, -28); printf("d=%g=%a dig=%d\n", d, d, dig); d -= ldexp((double) dig, 28); printf("d=%g=%a dig=%d\n", d, d, dig); }