Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make digits a keyword argument to round
In Julia 0.7, the digits positional argument to `round` was deprecated in favor of a `digits=` keyword argument. This introduces a similar change here.
- Loading branch information
Showing
5 changed files
with
17 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,13 @@ | ||
# Rounding | ||
function Base.round(x::Decimal, dpts::Int=0; normal::Bool=false) | ||
shift = BigInt(dpts) + x.q | ||
function round(x::Decimal; digits::Int=0, normal::Bool=false) | ||
shift = BigInt(digits) + x.q | ||
if shift > BigInt(0) || shift < x.q | ||
(normal) ? x : normalize(x, rounded=true) | ||
else | ||
c = Base.round(x.c / BigInt(10)^(-shift)) | ||
d = Decimal(x.s, BigInt(c), x.q - shift) | ||
(normal) ? d : normalize(d, rounded=true) | ||
c = Base.round(x.c / BigInt(10)^(-shift)) | ||
d = Decimal(x.s, BigInt(c), x.q - shift) | ||
(normal) ? d : normalize(d, rounded=true) | ||
end | ||
end | ||
|
||
@deprecate round(x::Decimal, dpts::Int; normal::Bool=false) round(x, digits=dpts, normal=normal) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters