Skip to content

Commit 27d370b

Browse files
committed
update
1 parent 5a8ebf9 commit 27d370b

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/longlonguint.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,17 @@ function Base.div(x::LongLongUInt{C}, y::LongLongUInt{C}) where {C}
191191

192192
return quotient
193193
end
194+
function Base.rem(x::LongLongUInt{C}, y::LongLongUInt{C}) where {C}
195+
y == zero(LongLongUInt{C}) && throw(DivideError())
196+
x < y && return x
197+
x == y && return zero(LongLongUInt{C})
198+
199+
# Calculate remainder using the relationship: rem(x, y) = x - div(x, y) * y
200+
quotient = div(x, y)
201+
remainder = x - quotient * y
202+
203+
return remainder
204+
end
194205

195206
Base.count_ones(x::LongLongUInt) = sum(count_ones, x.content)
196207
Base.bitstring(x::LongLongUInt) = join(bitstring.(x.content), "")

test/longlonguint.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,4 +245,11 @@ end
245245
b3 = bmask(LongLongUInt{1}, 3)
246246

247247
@test hash((b1, b2, b3)) == hash((b1, b2, b3))
248+
end
249+
250+
@testset "LongLongUInt rem and mod" begin
251+
x = LongLongUInt((1234, 213))
252+
y = LongLongUInt((0, 17))
253+
@test rem(x, y) == rem(BigInt(x), BigInt(y))
254+
@test mod(x, y) == mod(BigInt(x), BigInt(y))
248255
end

0 commit comments

Comments
 (0)