Skip to content

Commit e1dd56d

Browse files
committed
Rename checked_rdiv; reexport checked*
1 parent 137c8b4 commit e1dd56d

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

src/FixedPointDecimals.jl

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@ module FixedPointDecimals
2727

2828
export FixedDecimal, RoundThrows
2929

30+
# (Re)export checked_* arithmetic functions
31+
# - Defined in this package:
32+
export checked_rdiv
33+
# - Reexported from Base:
34+
export checked_abs, checked_add, checked_cld, checked_div, checked_fld,
35+
checked_mod, checked_mul, checked_neg, checked_rem, checked_sub
36+
3037
using Base: decompose, BitInteger
3138
import Parsers
3239

@@ -463,7 +470,7 @@ end
463470
# We introduce a new function for this since Base.Checked only supports integers, and ints
464471
# don't have a decimal division operation.
465472
"""
466-
FixedPointDecimals.checked_decimal_division(x::FD, y::FD) -> FD
473+
FixedPointDecimals.checked_rdiv(x::FD, y::FD) -> FD
467474
468475
Calculates `x / y`, checking for overflow errors where applicable.
469476
@@ -472,11 +479,11 @@ The overflow protection may impose a perceptible performance penalty.
472479
See also:
473480
- `Base.checked_div` for truncating division.
474481
"""
475-
checked_decimal_division(x::FD, y::FD) = checked_decimal_division(promote(x, y)...)
476-
checked_decimal_division(x, y::FD) = checked_decimal_division(promote(x, y)...)
477-
checked_decimal_division(x::FD, y) = checked_decimal_division(promote(x, y)...)
482+
checked_rdiv(x::FD, y::FD) = checked_rdiv(promote(x, y)...)
483+
checked_rdiv(x, y::FD) = checked_rdiv(promote(x, y)...)
484+
checked_rdiv(x::FD, y) = checked_rdiv(promote(x, y)...)
478485

479-
function checked_decimal_division(x::FD{T,f}, y::FD{T,f}) where {T<:Integer,f}
486+
function checked_rdiv(x::FD{T,f}, y::FD{T,f}) where {T<:Integer,f}
480487
powt = coefficient(FD{T, f})
481488
quotient, remainder = fldmod(widemul(x.i, powt), y.i)
482489
v = _round_to_nearest(quotient, remainder, y.i)

test/FixedDecimal.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -643,11 +643,11 @@ end
643643
@test_throws OverflowError Base.checked_div(1, FD{Int8,2}(0.5))
644644
@test_throws OverflowError Base.checked_div(FD{Int8,2}(1), FD{Int8,2}(0.4))
645645

646-
@testset "checked_decimal_division" begin
647-
using FixedPointDecimals: checked_decimal_division
646+
@testset "checked_rdiv" begin
647+
using FixedPointDecimals: checked_rdiv
648648

649-
@test checked_decimal_division(Int8(1), FD{Int8,2}(0.8)) == FD{Int8,2}(1.25)
650-
@test_throws OverflowError checked_decimal_division(Int8(1), FD{Int8,2}(0.7))
649+
@test checked_rdiv(Int8(1), FD{Int8,2}(0.8)) == FD{Int8,2}(1.25)
650+
@test_throws OverflowError checked_rdiv(Int8(1), FD{Int8,2}(0.7))
651651
end
652652

653653
# Rounds down to -2
@@ -722,7 +722,7 @@ end
722722
@testset for op in (
723723
Base.checked_add, Base.checked_sub, Base.checked_mul, Base.checked_div,
724724
Base.checked_cld, Base.checked_fld, Base.checked_rem, Base.checked_mod,
725-
FixedPointDecimals.checked_decimal_division,
725+
FixedPointDecimals.checked_rdiv,
726726
)
727727
@test op(x, y) === op(FD{Int64,1}(1), y)
728728
@test op(y, x) === op(y, FD{Int64,1}(1))

0 commit comments

Comments
 (0)