Commit ef4925d1 authored by Luke Champine's avatar Luke Champine

add Mul64 and Div64

parent 92dbe06e
......@@ -84,12 +84,24 @@ func (x Currency) Div(y Currency) (c Currency) {
return
}
// Div64 returns a new Currency value c = x / y.
func (x Currency) Div64(y uint64) (c Currency) {
c.i.Div(&x.i, new(big.Int).SetUint64(y))
return
}
// Mul returns a new Currency value c = x * y.
func (x Currency) Mul(y Currency) (c Currency) {
c.i.Mul(&x.i, &y.i)
return
}
// Mul64 returns a new Currency value c = x * y.
func (x Currency) Mul64(y uint64) (c Currency) {
c.i.Mul(&x.i, new(big.Int).SetUint64(y))
return
}
// COMPATv0.4.0 - until the first 10e3 blocks have been archived, MulFloat is
// needed while verifying the first set of blocks.
//
......
......@@ -58,6 +58,23 @@ func TestCurrencyDiv(t *testing.T) {
}
}
// TestCurrencyDiv64 checks that the Div64 function has been correctly implemented.
func TestCurrencyDiv64(t *testing.T) {
c9 := NewCurrency64(9)
u10 := uint64(10)
c90 := NewCurrency64(90)
c97 := NewCurrency64(97)
c90D10 := c90.Div64(u10)
if c90D10.Cmp(c9) != 0 {
t.Error("Dividing 90 by 10 should produce 9")
}
c97D10 := c97.Div64(u10)
if c97D10.Cmp(c9) != 0 {
t.Error("Dividing 97 by 10 should produce 9")
}
}
// TestCurrencyMul probes the Mul function of the currency type.
func TestCurrencyMul(t *testing.T) {
c5 := NewCurrency64(5)
......@@ -68,6 +85,16 @@ func TestCurrencyMul(t *testing.T) {
}
}
// TestCurrencyMul64 probes the Mul64 function of the currency type.
func TestCurrencyMul64(t *testing.T) {
c5 := NewCurrency64(5)
u6 := uint64(6)
c30 := NewCurrency64(30)
if c5.Mul64(u6).Cmp(c30) != 0 {
t.Error("Multiplying 5 by 6 should equal 30")
}
}
// TestCurrencyMulRat probes the MulRat function of the currency type.
func TestCurrencyMulRat(t *testing.T) {
c5 := NewCurrency64(5)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment