summaryrefslogtreecommitdiff
path: root/src/pkg/big/rat.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/pkg/big/rat.go')
-rw-r--r--src/pkg/big/rat.go28
1 files changed, 0 insertions, 28 deletions
diff --git a/src/pkg/big/rat.go b/src/pkg/big/rat.go
index b61cbb966..327b9bd9c 100644
--- a/src/pkg/big/rat.go
+++ b/src/pkg/big/rat.go
@@ -20,13 +20,11 @@ type Rat struct {
b nat
}
-
// NewRat creates a new Rat with numerator a and denominator b.
func NewRat(a, b int64) *Rat {
return new(Rat).SetFrac64(a, b)
}
-
// SetFrac sets z to a/b and returns z.
func (z *Rat) SetFrac(a, b *Int) *Rat {
z.a.Set(a)
@@ -35,7 +33,6 @@ func (z *Rat) SetFrac(a, b *Int) *Rat {
return z.norm()
}
-
// SetFrac64 sets z to a/b and returns z.
func (z *Rat) SetFrac64(a, b int64) *Rat {
z.a.SetInt64(a)
@@ -47,7 +44,6 @@ func (z *Rat) SetFrac64(a, b int64) *Rat {
return z.norm()
}
-
// SetInt sets z to x (by making a copy of x) and returns z.
func (z *Rat) SetInt(x *Int) *Rat {
z.a.Set(x)
@@ -55,7 +51,6 @@ func (z *Rat) SetInt(x *Int) *Rat {
return z
}
-
// SetInt64 sets z to x and returns z.
func (z *Rat) SetInt64(x int64) *Rat {
z.a.SetInt64(x)
@@ -63,7 +58,6 @@ func (z *Rat) SetInt64(x int64) *Rat {
return z
}
-
// Sign returns:
//
// -1 if x < 0
@@ -74,13 +68,11 @@ func (x *Rat) Sign() int {
return x.a.Sign()
}
-
// IsInt returns true if the denominator of x is 1.
func (x *Rat) IsInt() bool {
return len(x.b) == 1 && x.b[0] == 1
}
-
// Num returns the numerator of z; it may be <= 0.
// The result is a reference to z's numerator; it
// may change if a new value is assigned to z.
@@ -88,7 +80,6 @@ func (z *Rat) Num() *Int {
return &z.a
}
-
// Denom returns the denominator of z; it is always > 0.
// The result is a reference to z's denominator; it
// may change if a new value is assigned to z.
@@ -96,7 +87,6 @@ func (z *Rat) Denom() *Int {
return &Int{false, z.b}
}
-
func gcd(x, y nat) nat {
// Euclidean algorithm.
var a, b nat
@@ -111,7 +101,6 @@ func gcd(x, y nat) nat {
return a
}
-
func (z *Rat) norm() *Rat {
f := gcd(z.a.abs, z.b)
if len(z.a.abs) == 0 {
@@ -127,7 +116,6 @@ func (z *Rat) norm() *Rat {
return z
}
-
func mulNat(x *Int, y nat) *Int {
var z Int
z.abs = z.abs.mul(x.abs, y)
@@ -135,7 +123,6 @@ func mulNat(x *Int, y nat) *Int {
return &z
}
-
// Cmp compares x and y and returns:
//
// -1 if x < y
@@ -146,7 +133,6 @@ func (x *Rat) Cmp(y *Rat) (r int) {
return mulNat(&x.a, y.b).Cmp(mulNat(&y.a, x.b))
}
-
// Abs sets z to |x| (the absolute value of x) and returns z.
func (z *Rat) Abs(x *Rat) *Rat {
z.a.Abs(&x.a)
@@ -154,7 +140,6 @@ func (z *Rat) Abs(x *Rat) *Rat {
return z
}
-
// Add sets z to the sum x+y and returns z.
func (z *Rat) Add(x, y *Rat) *Rat {
a1 := mulNat(&x.a, y.b)
@@ -164,7 +149,6 @@ func (z *Rat) Add(x, y *Rat) *Rat {
return z.norm()
}
-
// Sub sets z to the difference x-y and returns z.
func (z *Rat) Sub(x, y *Rat) *Rat {
a1 := mulNat(&x.a, y.b)
@@ -174,7 +158,6 @@ func (z *Rat) Sub(x, y *Rat) *Rat {
return z.norm()
}
-
// Mul sets z to the product x*y and returns z.
func (z *Rat) Mul(x, y *Rat) *Rat {
z.a.Mul(&x.a, &y.a)
@@ -182,7 +165,6 @@ func (z *Rat) Mul(x, y *Rat) *Rat {
return z.norm()
}
-
// Quo sets z to the quotient x/y and returns z.
// If y == 0, a division-by-zero run-time panic occurs.
func (z *Rat) Quo(x, y *Rat) *Rat {
@@ -197,7 +179,6 @@ func (z *Rat) Quo(x, y *Rat) *Rat {
return z.norm()
}
-
// Neg sets z to -x (by making a copy of x if necessary) and returns z.
func (z *Rat) Neg(x *Rat) *Rat {
z.a.Neg(&x.a)
@@ -205,7 +186,6 @@ func (z *Rat) Neg(x *Rat) *Rat {
return z
}
-
// Set sets z to x (by making a copy of x if necessary) and returns z.
func (z *Rat) Set(x *Rat) *Rat {
z.a.Set(&x.a)
@@ -213,12 +193,10 @@ func (z *Rat) Set(x *Rat) *Rat {
return z
}
-
func ratTok(ch int) bool {
return strings.IndexRune("+-/0123456789.eE", ch) >= 0
}
-
// Scan is a support routine for fmt.Scanner. It accepts the formats
// 'e', 'E', 'f', 'F', 'g', 'G', and 'v'. All formats are equivalent.
func (z *Rat) Scan(s fmt.ScanState, ch int) os.Error {
@@ -235,7 +213,6 @@ func (z *Rat) Scan(s fmt.ScanState, ch int) os.Error {
return nil
}
-
// SetString sets z to the value of s and returns z and a boolean indicating
// success. s can be given as a fraction "a/b" or as a floating-point number
// optionally followed by an exponent. If the operation failed, the value of z
@@ -294,13 +271,11 @@ func (z *Rat) SetString(s string) (*Rat, bool) {
return z, true
}
-
// String returns a string representation of z in the form "a/b" (even if b == 1).
func (z *Rat) String() string {
return z.a.String() + "/" + z.b.decimalString()
}
-
// RatString returns a string representation of z in the form "a/b" if b != 1,
// and in the form "a" if b == 1.
func (z *Rat) RatString() string {
@@ -310,7 +285,6 @@ func (z *Rat) RatString() string {
return z.String()
}
-
// FloatString returns a string representation of z in decimal form with prec
// digits of precision after the decimal point and the last digit rounded.
func (z *Rat) FloatString(prec int) string {
@@ -356,7 +330,6 @@ func (z *Rat) FloatString(prec int) string {
return s
}
-
// Gob codec version. Permits backward-compatible changes to the encoding.
const ratGobVersion byte = 1
@@ -380,7 +353,6 @@ func (z *Rat) GobEncode() ([]byte, os.Error) {
return buf[j:], nil
}
-
// GobDecode implements the gob.GobDecoder interface.
func (z *Rat) GobDecode(buf []byte) os.Error {
if len(buf) == 0 {