Skip to content

Commit

Permalink
Fix _unsafe_trunc for BigFloat on ARM (#203)
Browse files Browse the repository at this point in the history
This also moves `_unsafe_trunc` to "src/utilities.jl".
  • Loading branch information
kimikage authored Jul 21, 2020
1 parent 2776bd8 commit cab78d7
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "FixedPointNumbers"
uuid = "53c48c17-4a7d-5ca2-90c5-79b7896eea93"
version = "0.8.3"
version = "0.8.4"

[deps]
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
Expand Down
2 changes: 1 addition & 1 deletion src/fixed.jl
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ end

function _convert(::Type{F}, x::Integer) where {T, f, F <: Fixed{T,f}}
if ((typemin(T) >> f) <= x) & (x <= (typemax(T) >> f))
reinterpret(F, unsafe_trunc(T, x) << f)
reinterpret(F, _unsafe_trunc(T, x) << f)
else
throw_converterror(F, x)
end
Expand Down
9 changes: 0 additions & 9 deletions src/normed.jl
Original file line number Diff line number Diff line change
Expand Up @@ -324,12 +324,3 @@ end
end
:(Normed{$T,$f})
end

_unsafe_trunc(::Type{T}, x::Integer) where {T} = x % T
_unsafe_trunc(::Type{T}, x) where {T} = unsafe_trunc(T, x)
if !signbit(signed(unsafe_trunc(UInt, -12.345)))
# a workaround for 32-bit ARMv7 (issue #134)
function _unsafe_trunc(::Type{T}, x::AbstractFloat) where {T}
unsafe_trunc(T, unsafe_trunc(typeof(signed(zero(T))), x))
end
end
13 changes: 13 additions & 0 deletions src/utilities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ widen1(::Type{Int128}) = Int128
widen1(::Type{UInt128}) = UInt128
widen1(x::Integer) = x % widen1(typeof(x))

signedtype(::Type{T}) where {T <: Integer} = typeof(signed(zero(T)))

const ShortInts = Union{Int8, UInt8, Int16, UInt16}
const LongInts = Union{Int64, UInt64, Int128, UInt128, BigInt}

Expand All @@ -34,3 +36,14 @@ significand_bits(::Type{Float32}) = 23
significand_bits(::Type{Float64}) = 52
exponent_bias(::Type{Float32}) = 127
exponent_bias(::Type{Float64}) = 1023

_unsafe_trunc(::Type{T}, x::Integer) where {T} = x % T
_unsafe_trunc(::Type{T}, x) where {T} = unsafe_trunc(T, x)
if !signbit(signed(unsafe_trunc(UInt, -12.345)))
# a workaround for ARM (issue #134)
function _unsafe_trunc(::Type{T}, x::AbstractFloat) where {T <: Integer}
unsafe_trunc(T, unsafe_trunc(signedtype(T), x))
end
# exclude BigFloat (issue #202)
_unsafe_trunc(::Type{T}, x::BigFloat) where {T <: Integer} = unsafe_trunc(T, x)
end

2 comments on commit cab78d7

@kimikage
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/18280

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.8.4 -m "<description of version>" cab78d7c4aa31673cc6f9f7f9de8aaddef2e8854
git push origin v0.8.4

Please sign in to comment.