Skip to content

Commit 0bfde60

Browse files
committed
Cleanup bigint
1 parent 21757de commit 0bfde60

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

src/FixedPointDecimals.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -308,17 +308,17 @@ function Base.convert(::Type{FD{T, f}}, x::Integer) where {T, f}
308308
end
309309
reinterpret(FD{T, f}, v)
310310
end
311-
function Base.convert(::Type{FD{BigT, f}}, x::Integer) where {BigT<:Union{BigFloat,BigInt}, f}
311+
function Base.convert(::Type{FD{BigInt, f}}, x::Integer) where {f}
312312
# We specialize on f==1, since julia can't eliminate BigInt multiplication.
313313
if f == 1
314314
# If x is already a BigInt, this is a no-op, otherwise we alloc a new BigInt.
315-
return reinterpret(FD{BigT, f}, BigT(x))
315+
return reinterpret(FD{BigInt, f}, BigInt(x))
316316
end
317317
# For the normal case, we multiply by C, which produces a BigInt value.
318-
C = coefficient(FD{BigT, f})
318+
C = coefficient(FD{BigInt, f})
319319
# This can't throw since BigInt and BigFloat can hold any number.
320320
v = x * C
321-
reinterpret(FD{BigT, f}, v)
321+
reinterpret(FD{BigInt, f}, v)
322322
end
323323

324324
Base.convert(::Type{T}, x::AbstractFloat) where {T <: FD} = round(T, x)

test/FixedDecimal.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,12 @@ end
317317
@test convert(FixedDecimal{BigInt,2}, Int128(-1)).i == BigInt(-100)
318318
@test convert(FixedDecimal{BigInt,2}, typemax(UInt128)).i == BigInt(typemax(UInt128))*100
319319
end
320+
321+
@testset "Convert from Big* to BigInt" begin
322+
@test convert(FixedDecimal{BigInt,2}, BigInt(1)).i == BigInt(100)
323+
@test convert(FixedDecimal{BigInt,2}, BigFloat(1)).i == BigInt(100)
324+
@test convert(FixedDecimal{BigInt,2}, BigFloat(1.5)).i == BigInt(150)
325+
end
320326
end
321327

322328
module PerfTests

0 commit comments

Comments
 (0)