Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix conversion of fractional units #335

Merged
merged 6 commits into from
May 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "Unitful"
uuid = "1986cc42-f94f-5a68-af5c-568840ba703d"
version = "1.2.0"
version = "1.2.1"

[deps]
ConstructionBase = "187b0558-2788-49d3-abe0-74a17ed4e7c9"
Expand Down
5 changes: 2 additions & 3 deletions src/conversion.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,9 @@ Find the conversion factor from unit `t` to unit `s`, e.g. `convfact(m,cm) = 0.0
end
end

if denominator(ex) == 1 # Use an integer for conversion if the ratio is whole
ex = numerator(ex) # so that, e.g., uconvert(s, 1minute) = 60s
if ex isa Rational && denominator(ex) == 1
ex = numerator(ex)
end

a ≈ 1.0 ? (inex = 1) : (inex = a)
y = inex * ex
:($y)
Expand Down
2 changes: 2 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ end
# Issue 26
@unit altL "altL" altLiter 1000*cm^3 true
@test convert(Float64, 1altL/cm^3) === 1000.0
# Issue 327
@test uconvert(u"√cm", 1u"√m") == 10u"√cm"
end
@testset "> Unitful ↔ unitful conversion" begin
@testset ">> Numeric conversion" begin
Expand Down