Skip to content

Commit c1732c0

Browse files
committed
Fix BigInt conversion tests for f=0 & f=1
1 parent 9c1688d commit c1732c0

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

src/FixedPointDecimals.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -303,19 +303,19 @@ function Base.convert(::Type{FD{T, f}}, x::Integer) where {T, f}
303303
# Perform x * C, and check for overflow. This is cheaper than a widemul, especially for
304304
# 128-bit T, since those widen into a BigInt.
305305
v = _mul_checked_overflow(throw_inexact, xT, C)
306-
reinterpret(FD{T, f}, v)
306+
return reinterpret(FD{T, f}, v)
307307
end
308308
function Base.convert(::Type{FD{BigInt, f}}, x::Integer) where {f}
309309
# We specialize on f==1, since julia can't eliminate BigInt multiplication.
310-
if f == 1
310+
if f == 0
311311
# If x is already a BigInt, this is a no-op, otherwise we alloc a new BigInt.
312312
return reinterpret(FD{BigInt, f}, BigInt(x))
313313
end
314314
# For the normal case, we multiply by C, which produces a BigInt value.
315315
C = coefficient(FD{BigInt, f})
316316
# This can't throw since BigInt and BigFloat can hold any number.
317317
v = x * C
318-
reinterpret(FD{BigInt, f}, v)
318+
return reinterpret(FD{BigInt, f}, v)
319319
end
320320

321321
# x * y - if overflow, report an InexactError(FDT, )

test/FixedDecimal.jl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,12 +316,18 @@ end
316316
@test convert(FixedDecimal{BigInt,2}, UInt128(1)).i == BigInt(100)
317317
@test convert(FixedDecimal{BigInt,2}, Int128(-1)).i == BigInt(-100)
318318
@test convert(FixedDecimal{BigInt,2}, typemax(UInt128)).i == BigInt(typemax(UInt128))*100
319+
320+
@test convert(FixedDecimal{BigInt, 1}, Int128(1)).i == BigInt(10)
321+
@test convert(FixedDecimal{BigInt, 0}, Int128(1)).i == BigInt(1)
319322
end
320323

321324
@testset "Convert from Big* to BigInt" begin
322325
@test convert(FixedDecimal{BigInt,2}, BigInt(1)).i == BigInt(100)
323326
@test convert(FixedDecimal{BigInt,2}, BigFloat(1)).i == BigInt(100)
324327
@test convert(FixedDecimal{BigInt,2}, BigFloat(1.5)).i == BigInt(150)
328+
329+
@test convert(FixedDecimal{BigInt, 1}, BigInt(1)).i == BigInt(10)
330+
@test convert(FixedDecimal{BigInt, 0}, BigInt(1)).i == BigInt(1)
325331
end
326332
end
327333

@@ -388,7 +394,7 @@ end # if @static Int === Int64
388394
@testset "BigInt conversion performance" begin
389395
b = BigInt(2)
390396
# Special-cased f=1 to not allocate for BigInt => FD conversion
391-
@test @allocated(convert(FixedDecimal{BigInt, 1}, b)) == 0
397+
@test @allocated(convert(FixedDecimal{BigInt, 0}, b)) == 0
392398
end
393399

394400
end # module PerfTests

0 commit comments

Comments
 (0)