|
@@ -1,14 +1,14 @@
|
|
|
-package dec_test
|
|
|
|
|
|
|
+package inf_test
|
|
|
|
|
|
|
|
import (
|
|
import (
|
|
|
"fmt"
|
|
"fmt"
|
|
|
"log"
|
|
"log"
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
-import "code.google.com/p/godec/dec"
|
|
|
|
|
|
|
+import "speter.net/go/exp/math/dec/inf"
|
|
|
|
|
|
|
|
func ExampleDec_SetString() {
|
|
func ExampleDec_SetString() {
|
|
|
- d := new(dec.Dec)
|
|
|
|
|
|
|
+ d := new(inf.Dec)
|
|
|
d.SetString("012345.67890") // decimal; leading 0 ignored; trailing 0 kept
|
|
d.SetString("012345.67890") // decimal; leading 0 ignored; trailing 0 kept
|
|
|
fmt.Println(d)
|
|
fmt.Println(d)
|
|
|
// Output: 12345.67890
|
|
// Output: 12345.67890
|
|
@@ -17,7 +17,7 @@ func ExampleDec_SetString() {
|
|
|
func ExampleDec_Scan() {
|
|
func ExampleDec_Scan() {
|
|
|
// The Scan function is rarely used directly;
|
|
// The Scan function is rarely used directly;
|
|
|
// the fmt package recognizes it as an implementation of fmt.Scanner.
|
|
// the fmt package recognizes it as an implementation of fmt.Scanner.
|
|
|
- d := new(dec.Dec)
|
|
|
|
|
|
|
+ d := new(inf.Dec)
|
|
|
_, err := fmt.Sscan("184467440.73709551617", d)
|
|
_, err := fmt.Sscan("184467440.73709551617", d)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
log.Println("error scanning value:", err)
|
|
log.Println("error scanning value:", err)
|
|
@@ -29,34 +29,34 @@ func ExampleDec_Scan() {
|
|
|
|
|
|
|
|
func ExampleDec_Quo_scale2RoundDown() {
|
|
func ExampleDec_Quo_scale2RoundDown() {
|
|
|
// 10 / 3 is an infinite decimal; it has no exact Dec representation
|
|
// 10 / 3 is an infinite decimal; it has no exact Dec representation
|
|
|
- x, y := dec.NewDecInt64(10), dec.NewDecInt64(3)
|
|
|
|
|
|
|
+ x, y := inf.NewDecInt64(10), inf.NewDecInt64(3)
|
|
|
// use 2 digits beyond the decimal point, round towards 0
|
|
// use 2 digits beyond the decimal point, round towards 0
|
|
|
- z := new(dec.Dec).Quo(x, y, dec.Scale(2), dec.RoundDown)
|
|
|
|
|
|
|
+ z := new(inf.Dec).Quo(x, y, inf.Scale(2), inf.RoundDown)
|
|
|
fmt.Println(z)
|
|
fmt.Println(z)
|
|
|
// Output: 3.33
|
|
// Output: 3.33
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func ExampleDec_Quo_scale2RoundCeil() {
|
|
func ExampleDec_Quo_scale2RoundCeil() {
|
|
|
// -42 / 400 is an finite decimal with 3 digits beyond the decimal point
|
|
// -42 / 400 is an finite decimal with 3 digits beyond the decimal point
|
|
|
- x, y := dec.NewDecInt64(-42), dec.NewDecInt64(400)
|
|
|
|
|
|
|
+ x, y := inf.NewDecInt64(-42), inf.NewDecInt64(400)
|
|
|
// use 2 digits beyond decimal point, round towards positive infinity
|
|
// use 2 digits beyond decimal point, round towards positive infinity
|
|
|
- z := new(dec.Dec).Quo(x, y, dec.Scale(2), dec.RoundCeil)
|
|
|
|
|
|
|
+ z := new(inf.Dec).Quo(x, y, inf.Scale(2), inf.RoundCeil)
|
|
|
fmt.Println(z)
|
|
fmt.Println(z)
|
|
|
// Output: -0.10
|
|
// Output: -0.10
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func ExampleDec_QuoExact_ok() {
|
|
func ExampleDec_QuoExact_ok() {
|
|
|
// 1 / 25 is a finite decimal; it has exact Dec representation
|
|
// 1 / 25 is a finite decimal; it has exact Dec representation
|
|
|
- x, y := dec.NewDecInt64(1), dec.NewDecInt64(25)
|
|
|
|
|
- z := new(dec.Dec).QuoExact(x, y)
|
|
|
|
|
|
|
+ x, y := inf.NewDecInt64(1), inf.NewDecInt64(25)
|
|
|
|
|
+ z := new(inf.Dec).QuoExact(x, y)
|
|
|
fmt.Println(z)
|
|
fmt.Println(z)
|
|
|
// Output: 0.04
|
|
// Output: 0.04
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func ExampleDec_QuoExact_fail() {
|
|
func ExampleDec_QuoExact_fail() {
|
|
|
// 1 / 3 is an infinite decimal; it has no exact Dec representation
|
|
// 1 / 3 is an infinite decimal; it has no exact Dec representation
|
|
|
- x, y := dec.NewDecInt64(1), dec.NewDecInt64(3)
|
|
|
|
|
- z := new(dec.Dec).QuoExact(x, y)
|
|
|
|
|
|
|
+ x, y := inf.NewDecInt64(1), inf.NewDecInt64(3)
|
|
|
|
|
+ z := new(inf.Dec).QuoExact(x, y)
|
|
|
fmt.Println(z)
|
|
fmt.Println(z)
|
|
|
// Output: <nil>
|
|
// Output: <nil>
|
|
|
}
|
|
}
|