Skip to content

Commit

Permalink
Remove Base.convert(::Type{Decimal}, ::Real) (#99)
Browse files Browse the repository at this point in the history
The method is unnecessary. We define constructors from `Real`s, which is
enough for the fallback `convert` method to work.

This commit also removes a useless test file.
  • Loading branch information
barucden authored Nov 19, 2024
1 parent 1a4e538 commit 4638697
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 20 deletions.
2 changes: 0 additions & 2 deletions src/conversion.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ function Decimal(x::AbstractFloat)
return Decimal(s, c, q)
end

Base.convert(::Type{Decimal}, x::Real) = Decimal(x)

function Base.BigFloat(x::Decimal)
y = BigFloat(x.c)
if x.q 0
Expand Down
10 changes: 0 additions & 10 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,8 @@ using Test

@testset "Decimals" begin

global d = [
Decimal(false, 2, -1)
Decimal(false, 1, -1)
Decimal(false, 100, -4)
Decimal(false, 1512, -2)
Decimal(true, 3, -2)
Decimal(true, 4, -6)
]

include("test_arithmetic.jl")
include("test_bigint.jl")
include("test_constructor.jl")
include("test_context.jl")
include("test_decimal.jl")
include("test_equals.jl")
Expand Down
8 changes: 0 additions & 8 deletions test/test_constructor.jl

This file was deleted.

5 changes: 5 additions & 0 deletions test/test_decimal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ using Decimals
using Test

@testset "Conversions" begin
@testset "Decimal to Decimal" begin
x = Decimal(1, 2, 3)
@test Decimal(x) === x
end

@testset "$T" for T in [Float32, Float64, BigFloat]
@test T(Decimal(T(0.0))) == T(0.0)
@test T(Decimal(T(-0.0))) == T(-0.0)
Expand Down

0 comments on commit 4638697

Please sign in to comment.