Skip to content

Commit

Permalink
Merge pull request #123 from SymbolicML/fix-fixedrational
Browse files Browse the repository at this point in the history
Make default parametric denominator of FixedRational `::Int64`
  • Loading branch information
MilesCranmer committed Mar 13, 2024
2 parents be3be32 + 37be60f commit 25e55a1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/fixed_rational.jl
Expand Up @@ -32,7 +32,7 @@ val_denom(::Type{<:F}) where {F<:FixedRational} = Val(_denom(F))
Base.eltype(::Type{<:FixedRational{T}}) where {T} = T

const DEFAULT_NUMERATOR_TYPE = Int32
const DEFAULT_DENOM = DEFAULT_NUMERATOR_TYPE(2^4 * 3^2 * 5^2 * 7)
const DEFAULT_DENOM = 2^4 * 3^2 * 5^2 * 7

(::Type{F})(x::F) where {F<:FixedRational} = x
(::Type{F})(x::F2) where {T,T2,den,F<:FixedRational{T,den},F2<:FixedRational{T2,den}} = unsafe_fixed_rational(x.num, eltype(F), val_denom(F))
Expand Down
8 changes: 7 additions & 1 deletion test/unittests.jl
Expand Up @@ -595,6 +595,12 @@ end
@test promote_type(FixedRational{Int64,10},FixedRational{BigInt,10}) == FixedRational{BigInt,10}
@test promote_type(Rational{Int8}, FixedRational{Int,12345}) == Rational{Int}
@test promote_type(Int8, FixedRational{Int,12345}) == FixedRational{Int,12345}

# Bug where user would create a FixedRational{::Type{Int32}, ::Int64} and get stack overflow,
# because the stored type was FixedRational{::Type{Int32}, ::Int32}
x = 10u"m"
user_quantity = Quantity(10.0, Dimensions{FixedRational{Int32,25200}}(1, 0, 0, 0, 0, 0, 0))
@test x == user_quantity
end

@testset "Quantity promotion" begin
Expand Down Expand Up @@ -1978,7 +1984,7 @@ end
push!(LOAD_PATH, joinpath(@__DIR__, "precompile_test"))

using ExternalUnitRegistration: MyWb
@testset "Type of Extenral Unit" begin
@testset "Type of External Unit" begin
@test MyWb isa DEFAULT_QUANTITY_TYPE
@test MyWb/u"m^2*kg*s^-2*A^-1" == 1.0
end
Expand Down

0 comments on commit 25e55a1

Please sign in to comment.