# Unitful divide error (but not multiply)

**URL:** <https://discourse.julialang.org/t/unitful-divide-error-but-not-multiply/94249>\
**Category:** General Usage\
**Created:** [February 8, 2023, 2:46am UTC](https://discourse.julialang.org/t/unitful-divide-error-but-not-multiply/94249 "2023-02-08T02:46:41Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jake](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jake/32/46007_2.png) [@Jake](https://discourse.julialang.org/u/Jake)\
**Post date:** [February 8, 2023, 2:46am UTC](https://discourse.julialang.org/t/unitful-divide-error-but-not-multiply/94249/1 "2023-02-08T02:46:41Z")

</div>

I am getting an error when dividing with Unitful but not when I multiply by the inverse of the divisor. For example:

```julia
julia> using Unitful

julia> a = 1250u"mm"
1250 mm

julia> b = (0.865:0.01:2.0)u"m";

julia> (a .+ b) .* 0.5;

julia> (a .+ b) ./ 2;
ERROR: DimensionError: m and 2 are not dimensionally compatible.
Stacktrace:
 [1] convert(#unused#::Type{Quantity{Float64, 𝐋, Unitful.FreeUnits{(m,), 𝐋, nothing}}} , x::Int64)
   @ Unitful C:\Users\jakez\.julia\packages\Unitful\fbiNW\src\conversion.jl:112
 [2] oftype(x::Quantity{Float64, 𝐋, Unitful.FreeUnits{(m,), 𝐋, nothing}} , y::Int64)
   @ Base .\essentials.jl:391
 [3] /(x::Base.TwicePrecision{Quantity{Float64, 𝐋, Unitful.FreeUnits{(m,), 𝐋, nothing}}} , v::Int64)
   @ Base .\twiceprecision.jl:327
 [4] broadcasted(#unused#::Base.Broadcast.DefaultArrayStyle{1}, #unused#::typeof(/), r::StepRangeLen{Quantity{Float64, �,, Unitful.FreeUnits{(m,), 𝐋, nothing}}, Base.TwicePrecision{Quantity{Float64, 𝐋, Unitful.FreeUnits{(m,), 𝐋, nothing}
}}, Base.TwicePrecision{Quantity{Float64, 𝐋, Unitful.FreeUnits{(m,), 𝐋, nothing}}}, Int64} , x::Int64)
   @ Base.Broadcast .\broadcast.jl:1135
 [5] broadcasted(::Function, ::StepRangeLen{Quantity{Float64, 𝐋, Unitful.FreeUnits{(m,), 𝐋, nothing}}, Base.TwicePreci
sion{Quantity{Float64, 𝐋, Unitful.FreeUnits{(m,), 𝐋, nothing}}}, Base.TwicePrecision{Quantity{Float64, 𝐋, Unitful.Fre
eUnits{(m,), 𝐋, nothing}}}, Int64} , ::Int64)
   @ Base.Broadcast .\broadcast.jl:1304
 [6] top-level scope
   @ REPL[8]:1

```

Since I have this workaround it is not a big deal, but it does seem odd. Is there an explanation or is this a bug?

---

<div class="post-metadata">

**Author:** ![torrance](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/torrance/32/38990_2.png) [@torrance](https://discourse.julialang.org/u/torrance)\
**Post date:** [February 8, 2023, 3:56am UTC](https://discourse.julialang.org/t/unitful-divide-error-but-not-multiply/94249/2 "2023-02-08T03:56:31Z")

</div>

It looks like bug to me that is specific to the range.

For example, if you force the range into a standard vector, then `collect(a .+ b) ./ 2` works just fine.

I would file a bug report at [GitHub - PainterQubits/Unitful.jl: Physical quantities with arbitrary units](https://github.com/PainterQubits/Unitful.jl)

---

<div class="post-metadata">

**Author:** ![Jake](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jake/32/46007_2.png) [@Jake](https://discourse.julialang.org/u/Jake)\
**Post date:** [February 8, 2023, 2:08pm UTC](https://discourse.julialang.org/t/unitful-divide-error-but-not-multiply/94249/3 "2023-02-08T14:08:56Z")

</div>

Thanks - Done
