From: Ken Thompson Date: Sat, 17 Jul 2010 23:32:40 +0000 (-0700) Subject: 1. got 29 (Mpscale) more bits of precision X-Git-Tag: weekly.2010-07-29~81 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=95b93c28e395e4ea88ad831e87736c7ef75eb734;p=gostls13.git 1. got 29 (Mpscale) more bits of precision out of floating constant multiply 2. added rounding code to "const fix=float" to allow up to 29 (Mpscale) bits of slop and still get an exact fixed constant. fixes #931 R=rsc CC=golang-dev https://golang.org/cl/1692055 --- diff --git a/src/cmd/gc/mparith1.c b/src/cmd/gc/mparith1.c index 8110e77b98..14226d6a9a 100644 --- a/src/cmd/gc/mparith1.c +++ b/src/cmd/gc/mparith1.c @@ -156,10 +156,11 @@ mpmovefixflt(Mpflt *a, Mpint *b) // convert (truncate) b to a. // return -1 (but still convert) if b was non-integer. -int -mpmovefltfix(Mpint *a, Mpflt *b) +static int +mpexactfltfix(Mpint *a, Mpflt *b) { Mpflt f; + *a = b->val; mpshiftfix(a, b->exp); if(b->exp < 0) { @@ -172,6 +173,35 @@ mpmovefltfix(Mpint *a, Mpflt *b) return 0; } +int +mpmovefltfix(Mpint *a, Mpflt *b) +{ + Mpflt f; + int i; + + if(mpexactfltfix(a, b) == 0) + return 0; + + // try rounding down a little + f = *b; + f.val.a[0] = 0; + if(mpexactfltfix(a, &f) == 0) + return 0; + + // try rounding up a little + for(i=1; ival, &b->val); - a->exp = (a->exp + b->exp) + Mpscale*Mpprec - 1; + a->exp = (a->exp + b->exp) + Mpscale*Mpprec - Mpscale - 1; mpnorm(a); if(Mpdebug)