Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

apd: don't strip trailing zeros in Quo and Sqrt #115

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions context.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,6 @@ func (c *Context) Quo(d, x, y *Decimal) (Condition, error) {
}

res |= d.setExponent(c, nd, res, shift, -adjCoeffs, -adjExp10)
d.Reduce(d) // remove trailing zeros
return c.goError(res)
}

Expand Down Expand Up @@ -552,7 +551,6 @@ func (c *Context) Sqrt(d, x *Decimal) (Condition, error) {
d.Exponent += int32(e / 2)
nc.Precision = c.Precision
nc.Rounding = RoundHalfEven
d.Reduce(d) // remove trailing zeros
res := nc.round(d, d)
return nc.goError(res)
}
Expand Down
19 changes: 12 additions & 7 deletions example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ func ExampleContext_overflow() {
return
}
}
// Output: d: 998, overflow: false, err: <nil>
// Output:
// d: 998, overflow: false, err: <nil>
// d: 999, overflow: false, err: <nil>
// d: Infinity, overflow: true, err: overflow
}
Expand All @@ -56,9 +57,10 @@ func ExampleContext_inexact() {
return
}
}
// Output: d: 9, inexact: false, err: <nil>
// d: 3, inexact: false, err: <nil>
// d: 1, inexact: false, err: <nil>
// Output:
// d: 9.0000, inexact: false, err: <nil>
// d: 3.0000, inexact: false, err: <nil>
// d: 1.0000, inexact: false, err: <nil>
// d: 0.33333, inexact: true, err: <nil>
}

Expand All @@ -74,7 +76,8 @@ func ExampleContext_Quantize() {
}
fmt.Println()
}
// Output: -3: 123.450
// Output:
// -3: 123.450
// -2: 123.45
// -1: 123.5 (inexact, rounded)
// 0: 123 (inexact, rounded)
Expand All @@ -95,7 +98,8 @@ func ExampleErrDecimal() {
ed.Sub(d, d, apd.New(1, 0)) // attempt to subtract 1
// The subtraction doesn't occur and doesn't change the error.
fmt.Printf("%s, err: %v\n", d, ed.Err())
// Output: 10, err: <nil>
// Output:
// 10, err: <nil>
// 30, err: <nil>
// Infinity, err: division by zero
// Infinity, err: division by zero
Expand Down Expand Up @@ -125,7 +129,8 @@ func ExampleContext_RoundToIntegralExact() {
}
fmt.Println()
}
// Output: input: 123.4, output: 123, integer: false, strict: false, res: inexact, rounded
// Output:
// input: 123.4, output: 123, integer: false, strict: false, res: inexact, rounded
// input: 123.0, output: 123, integer: true, strict: false, res: rounded
// input: 123, output: 123, integer: true, strict: true, res:
// input: 12E1, output: 120, integer: true, strict: true, res:
Expand Down