Skip to content

Commit f541687

Browse files
authored
Fix basefactor calculation in case of rational tensfactor (#783)
* Fix basefactor calculation in case of Rational tensfactor * Add (broken) tests for exact conversion
1 parent 038656a commit f541687

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/units.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,9 @@ function basefactor(inex, ex, eq, tens, p)
209209
if isinteger(p)
210210
p = Integer(p)
211211
end
212+
if isinteger(tens)
213+
tens = Integer(tens)
214+
end
212215

213216
eq_is_exact = false
214217
output_ex_float = (10.0^tens * float(ex))^p
@@ -226,7 +229,7 @@ function basefactor(inex, ex, eq, tens, p)
226229
can_exact2 &= (1/eq_raised < typemax(Int))
227230
can_exact2 &= isinteger(p)
228231

229-
if can_exact
232+
if can_exact && isinteger(tens)
230233
if eq_is_exact
231234
# If we got here then p is an integer.
232235
# Note that sometimes x^1 can cause an overflow error if x is large because

test/runtests.jl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import Unitful:
1212
Ra, °F, °C, K,
1313
rad, mrad, °,
1414
ms, s, minute, hr, d, yr, Hz,
15-
J, A, N, mol, V, mJ, eV,
15+
J, A, N, mol, V, mJ, eV, dyn, mN,
1616
mW, W,
1717
dB, dB_rp, dB_p, dBm, dBV, dBSPL, Decibel,
1818
Np, Np_rp, Np_p, Neper,
@@ -314,6 +314,13 @@ Base.float(x::ErrReal) = error("float not defined")
314314
(1u"ab^8", 1u"fb^8")
315315
# Issue 660:
316316
@test uconvert(u"Å * ps^-2", 1.0u"kcal*Å^-1*g^-1") 418.4u"Å * ps^-2"
317+
# Issue 780:
318+
@unit Fr "Fr" franklin 1sqrt(dyn)*cm false
319+
@unit Test780 "Test780" test780 1sqrt(mN)*cm false
320+
@test uconvert(dyn, 1Fr^2/cm^2) 1dyn
321+
@test uconvert(mN, 1Test780^2/cm^2) 1mN
322+
@test_broken uconvert(dyn, 1Fr^2/cm^2) === 1dyn
323+
@test_broken uconvert(mN, 1Test780^2/cm^2) === 1mN
317324
end
318325
end
319326
end

0 commit comments

Comments
 (0)