Skip to content

Commit 0b7c3c0

Browse files
authored
Fix type promotion (#58)
1 parent 7380c63 commit 0b7c3c0

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

src/longlonguint.jl

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ Base.zero(::Type{LongLongUInt{C}}) where {C} = LongLongUInt{C}(ntuple(_->UInt(0)
2323
Base.zero(::LongLongUInt{C}) where {C} = zero(LongLongUInt{C})
2424
# convert from integers
2525
LongLongUInt{C}(x::T) where {C, T<:Integer} = LongLongUInt{C}(ntuple(i->i==C ? UInt(x) : zero(UInt), Val{C}()))
26-
Base.promote_type(::Type{LongLongUInt{C}}, ::Type{Int}) where {C} = LongLongUInt{C}
27-
Base.promote_type(::Type{LongLongUInt{C}}, ::Type{UInt}) where {C} = LongLongUInt{C}
26+
Base.promote_rule(::Type{LongLongUInt{C}}, ::Type{Int}) where {C} = LongLongUInt{C}
27+
Base.promote_rule(::Type{LongLongUInt{C}}, ::Type{UInt}) where {C} = LongLongUInt{C}
2828
function Base.mod(x::LongLongUInt{C}, D::Int) where {C}
2929
D == 2 ? mod(x.content[end], 2) : error("mod only supports 2")
3030
end
@@ -134,4 +134,4 @@ function longinttype(n::Int, D::Int)
134134
end
135135

136136
Base.hash(x::LongLongUInt{1}) = hash(x.content[1])
137-
Base.hash(x::LongLongUInt{C}) where{C} = hash(x.content)
137+
Base.hash(x::LongLongUInt{C}) where{C} = hash(x.content)

test/longlonguint.jl

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ using Test, BitBasis
1414
@test x >> 1 == LongLongUInt((UInt(1), UInt(3) + UInt(1)<<63))
1515
@test count_ones(x) == 4
1616
@test ~x == LongLongUInt((~UInt(3), ~UInt(6)))
17+
@test promote(UInt(1), LongLongUInt((3, 4))) == (LongLongUInt((0, 1)), LongLongUInt((3, 4)))
1718

1819
y = LongLongUInt((5, 7))
1920
@test one(y) == LongLongUInt((0, 1))
@@ -120,4 +121,4 @@ end
120121
xs = [LongLongUInt((3, 6)), LongLongUInt((3, 7)), LongLongUInt((2, 4))]
121122
sorted_xs = sort(xs)
122123
@test sorted_xs == [LongLongUInt((2, 4)), LongLongUInt((3, 6)), LongLongUInt((3, 7))]
123-
end
124+
end

0 commit comments

Comments
 (0)