From 95b93c28e395e4ea88ad831e87736c7ef75eb734 Mon Sep 17 00:00:00 2001 From: Ken Thompson Date: Sat, 17 Jul 2010 16:32:40 -0700 Subject: [PATCH] 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 --- src/cmd/gc/mparith1.c | 34 ++++++++++++++++++++++++++++++++-- src/cmd/gc/mparith2.c | 6 +++++- src/cmd/gc/mparith3.c | 2 +- 3 files changed, 38 insertions(+), 4 deletions(-) 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) -- 2.48.1