Skip to content

Commit

Permalink
fix isinteger
Browse files Browse the repository at this point in the history
fixes JuliaMath#120 : `isinteger(1N0f8)` should be true
  • Loading branch information
johnnychen94 committed May 15, 2019
1 parent 5729a89 commit 00bb122
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/FixedPointNumbers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ module FixedPointNumbers
using Base: reducedim_initarray

import Base: ==, <, <=, -, +, *, /, ~, isapprox,
convert, promote_rule, show, isinteger, abs, decompose,
isnan, isinf, isfinite,
convert, promote_rule, show, eger, abs, decompose,
isnan, isinf, isfinite, isinteger,
zero, oneunit, one, typemin, typemax, floatmin, floatmax, eps, sizeof, reinterpret,
float, trunc, round, floor, ceil, bswap,
div, fld, rem, mod, mod1, fld1, min, max, minmax,
Expand Down
3 changes: 3 additions & 0 deletions src/normed.jl
Original file line number Diff line number Diff line change
Expand Up @@ -169,3 +169,6 @@ end

_unsafe_trunc(::Type{T}, x::Integer) where {T} = x % T
_unsafe_trunc(::Type{T}, x) where {T} = unsafe_trunc(T, x)

# predicates
isinteger(x::Normed{T,f}) where {T,f} = (x.i%(1<<f-1)) == 0
8 changes: 8 additions & 0 deletions test/fixed.jl
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,14 @@ end
@test floatmin(Q11f4) == Q11f4(0.06)
end

@testset "isinteger" begin
# issue #120
for T in (Fixed{Int8,6}, Fixed{Int16,8}, Fixed{Int16,10}, Fixed{Int32,16})
a = 1
@test all(isinteger.(T.(a)))
end
end

@testset "Disambiguation constructors" begin
@test_throws ArgumentError Fixed{Int32,16}('a')
@test_throws InexactError Fixed{Int32,16}(complex(1.0, 1.0))
Expand Down
8 changes: 8 additions & 0 deletions test/normed.jl
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,14 @@ end
@test summary(view(a, 1:2)) == "2-element view(::Array{N0f8,1}, 1:2) with eltype Normed{UInt8,8}"
end

@testset "isinteger" begin
# issue #120
for T in (Normed{UInt8,6}, Normed{UInt16,8}, Normed{UInt16,10}, Normed{UInt32,16})
a = 1
@test all(isinteger.(T.(a)))
end
end

@testset "disambiguation constructors" begin
@test_throws ArgumentError Normed{UInt32,16}('a')
@test_throws InexactError Normed{UInt32,16}(complex(1.0, 1.0))
Expand Down

0 comments on commit 00bb122

Please sign in to comment.