Skip to content

Commit

Permalink
Adjust formatting, add entry in NEWS.md.
Browse files Browse the repository at this point in the history
Some small fixes in range.jl and conversion.jl.
  • Loading branch information
ajkeller34 committed Mar 24, 2017
1 parent 989bbab commit 1dac617
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
- v0.1.5
- Patch for Julia PR [#20889](https://github.com/JuliaLang/julia/pull/20889), which changes how lowering is done for exponentiation of integer literals.
- Bug fix to enable registering Main as a module for `u_str` (fixes [#61](https://github.com/ajkeller34/Unitful.jl/issues/61)).
- Implement readable message for `DimensionError` [#62](https://github.com/ajkeller34/Unitful.jl/pull/62).
- v0.1.4
- Critical bug fix owing to `mod_fast` changes.
- v0.1.3
Expand Down
2 changes: 1 addition & 1 deletion src/Conversion.jl
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Find the conversion factor from unit `t` to unit `s`, e.g. `convfact(m,cm) = 0.0
# Check if conversion is possible in principle
sdim = dimension(s())
tdim = dimension(t())
sdim != tdim && throw(DimensionError(s,t))
sdim != tdim && throw(DimensionError(s(),t()))

# first convert to base SI units.
# fact1 is what would need to be multiplied to get to base SI units
Expand Down
11 changes: 7 additions & 4 deletions src/Unitful.jl
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,16 @@ type DimensionError{T,S} <: Exception
y::S
end
```
Thrown when dimensions don't match in an operation that demands they do. Display `x` and `y` in error message.
Thrown when dimensions don't match in an operation that demands they do.
Display `x` and `y` in error message.
"""
type DimensionError{T,S} <: Exception
x::T
y::S
x::T
y::S
end
Base.showerror(io::IO, e::DimensionError) = print(io,"DimensionError: $(e.x) and $(e.y) are not dimensionally compatible.");
Base.showerror(io::IO, e::DimensionError) =
print(io,"DimensionError: $(e.x) and $(e.y) are not dimensionally compatible.");

"""
```
Expand Down
6 changes: 3 additions & 3 deletions src/range.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@
linspace(Float64, ustrip(start), ustrip(stop), len, 1)*unit(T)

function _linspace{T}(start::Quantity{T}, stop::Quantity{T}, len::Integer)
dimension(start) != dimension(stop) && throw(DimensionError())
dimension(start) != dimension(stop) && throw(DimensionError(start, stop))
linspace(start, stop, len)
end

@compat function colon(start::Quantity{<:Real}, step, stop::Quantity{<:Real})
dimension(start) != dimension(stop) && throw(DimensionError())
dimension(start) != dimension(stop) && throw(DimensionError(start, stop))
T = promote_type(typeof(start),typeof(stop))
return colon(convert(T,start), step, convert(T,stop))
end

function colon(start::A, step::B, stop::A) where A<:Quantity{<:Real} where B<:Quantity{<:Real}
dimension(start) != dimension(step) && throw(DimensionError())
dimension(start) != dimension(step) && throw(DimensionError(start, step))
colon(promote(start, step, stop)...)
end

Expand Down

0 comments on commit 1dac617

Please sign in to comment.