Skip to content

Commit 9949f40

Browse files
committed
Import Base at-pure to simplify FixedPointDecimals.jl file.
Use `using Base: @pure` instead of `Base.@pure` everywhere. Applies @omus's PR review suggestion.
1 parent 685b3dc commit 9949f40

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

src/FixedPointDecimals.jl

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ module FixedPointDecimals
2727

2828
export FixedDecimal, RoundThrows
2929

30-
using Base: decompose, BitInteger
30+
using Base: decompose, BitInteger, @pure
3131

3232
# floats that support fma and are roughly IEEE-like
3333
const FMAFloat = Union{Float16, Float32, Float64, BigFloat}
@@ -79,8 +79,8 @@ struct FixedDecimal{T <: Integer, f} <: Real
7979
i::T
8080

8181
# inner constructor
82-
# This function is marked as `Base.@pure`. It does not have or depend on any side-effects.
83-
Base.@pure function Base.reinterpret(::Type{FixedDecimal{T, f}}, i::Integer) where {T, f}
82+
# This function is marked as `@pure`. It does not have or depend on any side-effects.
83+
@pure function Base.reinterpret(::Type{FixedDecimal{T, f}}, i::Integer) where {T, f}
8484
n = max_exp10(T)
8585
if f >= 0 && (n < 0 || f <= n)
8686
new{T, f}(i % T)
@@ -115,15 +115,15 @@ Base.:+(x::FD{T, f}, y::FD{T, f}) where {T, f} = reinterpret(FD{T, f}, x.i+y.i)
115115
Base.:-(x::FD{T, f}, y::FD{T, f}) where {T, f} = reinterpret(FD{T, f}, x.i-y.i)
116116

117117
# wide multiplication
118-
Base.@pure function Base.widemul(x::FD{<:Any, f}, y::FD{<:Any, g}) where {f, g}
118+
@pure function Base.widemul(x::FD{<:Any, f}, y::FD{<:Any, g}) where {f, g}
119119
i = widemul(x.i, y.i)
120120
reinterpret(FD{typeof(i), f + g}, i)
121121
end
122-
Base.@pure function Base.widemul(x::FD{T, f}, y::Integer) where {T, f}
122+
@pure function Base.widemul(x::FD{T, f}, y::Integer) where {T, f}
123123
i = widemul(x.i, y)
124124
reinterpret(FD{typeof(i), f}, i)
125125
end
126-
Base.@pure Base.widemul(x::Integer, y::FD) = widemul(y, x)
126+
@pure Base.widemul(x::Integer, y::FD) = widemul(y, x)
127127

128128
"""
129129
_round_to_even(quotient, remainder, divisor)
@@ -333,7 +333,7 @@ Base.promote_rule(::Type{<:FD}, ::Type{Rational{TR}}) where {TR} = Rational{TR}
333333

334334
# TODO: decide if these are the right semantics;
335335
# right now we pick the bigger int type and the bigger decimal point
336-
Base.@pure function Base.promote_rule(::Type{FD{T, f}}, ::Type{FD{U, g}}) where {T, f, U, g}
336+
@pure function Base.promote_rule(::Type{FD{T, f}}, ::Type{FD{U, g}}) where {T, f, U, g}
337337
FD{promote_type(T, U), max(f, g)}
338338
end
339339

@@ -480,7 +480,7 @@ NOTE: This function is expensive, since it contains a while-loop, but it is actu
480480
This function does not have or depend on any side-effects.
481481
"""
482482
function max_exp10(::Type{T}) where {T <: Integer}
483-
# This function is marked as `Base.@pure`. Even though it does call some generic
483+
# This function is marked as `@pure`. Even though it does call some generic
484484
# functions, they are all simple methods that should be able to be evaluated as
485485
# constants. This function does not have or depend on any side-effects.
486486

@@ -516,8 +516,8 @@ end
516516
Compute `10^f` as an Integer without overflow. Note that overflow will not occur for any
517517
constructable `FD{T, f}`.
518518
"""
519-
Base.@pure coefficient(::Type{FD{T, f}}) where {T, f} = T(10)^f
520-
Base.@pure coefficient(fd::FD{T, f}) where {T, f} = coefficient(FD{T, f})
519+
@pure coefficient(::Type{FD{T, f}}) where {T, f} = T(10)^f
520+
@pure coefficient(fd::FD{T, f}) where {T, f} = coefficient(FD{T, f})
521521
value(fd::FD) = fd.i
522522

523523
# for generic hashing

0 commit comments

Comments
 (0)