Browse Source

avoid dependency on Int implementation

speter 13 years ago
parent
commit
dfcadbd95a
2 changed files with 10 additions and 18 deletions
  1. 4 12
      dec.go
  2. 6 6
      rounder.go

+ 4 - 12
dec.go

@@ -23,6 +23,9 @@
 //
 package inf
 
+// TODO:
+//  - avoid excessive deep copying (quo and rounders)
+
 import (
 	"fmt"
 	"io"
@@ -155,17 +158,6 @@ func (z *Dec) Set(x *Dec) *Dec {
 	return z
 }
 
-// Move sets z to the value of x, and sets x to zero, unless z == x.
-// It is intended for fast assignment from temporary variables without copying
-// the underlying array.
-func (z *Dec) move(x *Dec) *Dec {
-	if z != x {
-		*z = *x
-		*x = Dec{}
-	}
-	return z
-}
-
 // Sign returns:
 //
 //	-1 if x <  0
@@ -259,7 +251,7 @@ func (z *Dec) quo(x, y *Dec, s scaler, r Rounder) *Dec {
 	if zzz == nil {
 		return nil
 	}
-	return z.move(zzz)
+	return z.Set(zzz)
 }
 
 // QuoExact sets z to the quotient x/y and returns z when x/y is a finite

+ 6 - 6
rounder.go

@@ -241,17 +241,17 @@ var roundExact = rndr{true,
 		if rA.Sign() != 0 {
 			return nil
 		}
-		return z.move(q)
+		return z.Set(q)
 	}}
 
 var roundDown = rndr{false,
 	func(z, q *Dec, rA, rB *big.Int) *Dec {
-		return z.move(q)
+		return z.Set(q)
 	}}
 
 var roundUp = rndr{true,
 	func(z, q *Dec, rA, rB *big.Int) *Dec {
-		z.move(q)
+		z.Set(q)
 		if rA.Sign() != 0 {
 			z.Unscaled().Add(z.Unscaled(), intSign[rA.Sign()*rB.Sign()+1])
 		}
@@ -260,7 +260,7 @@ var roundUp = rndr{true,
 
 func roundHalf(f func(c int, odd uint) (roundUp bool)) func(z, q *Dec, rA, rB *big.Int) *Dec {
 	return func(z, q *Dec, rA, rB *big.Int) *Dec {
-		z.move(q)
+		z.Set(q)
 		brA, brB := rA.BitLen(), rB.BitLen()
 		if brA < brB-1 {
 			// brA < brB-1 => |rA| < |rB/2|
@@ -303,7 +303,7 @@ var roundHalfEven = rndr{true, roundHalf(
 
 var roundFloor = rndr{true,
 	func(z, q *Dec, rA, rB *big.Int) *Dec {
-		z.move(q)
+		z.Set(q)
 		if rA.Sign()*rB.Sign() < 0 {
 			z.Unscaled().Add(z.Unscaled(), intSign[0])
 		}
@@ -312,7 +312,7 @@ var roundFloor = rndr{true,
 
 var roundCeil = rndr{true,
 	func(z, q *Dec, rA, rB *big.Int) *Dec {
-		z.move(q)
+		z.Set(q)
 		if rA.Sign()*rB.Sign() > 0 {
 			z.Unscaled().Add(z.Unscaled(), intSign[2])
 		}