Skip to content

Commit

Permalink
Clean up docstring style.
Browse files Browse the repository at this point in the history
  • Loading branch information
ajkeller34 committed Jun 14, 2017
1 parent c669cfa commit 9e3525d
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 254 deletions.
35 changes: 7 additions & 28 deletions src/Conversion.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
"""
```
uconvert{T,D,U}(a::Units, x::Quantity{T,D,U})
```
uconvert{T,D,U}(a::Units, x::Quantity{T,D,U})
Convert a [`Unitful.Quantity`](@ref) to different units. The conversion will
fail if the target units `a` have a different dimension than the dimension of
the quantity `x`. You can use this method to switch between equivalent
Expand Down Expand Up @@ -34,10 +31,7 @@ function uconvert(a::Units, x::Number)
end

"""
```
convfact(s::Units, t::Units)
```
convfact(s::Units, t::Units)
Find the conversion factor from unit `t` to unit `s`, e.g. `convfact(m,cm) = 0.01`.
"""
@generated function convfact(s::Units, t::Units)
Expand Down Expand Up @@ -82,19 +76,13 @@ Find the conversion factor from unit `t` to unit `s`, e.g. `convfact(m,cm) = 0.0
end

"""
```
convfact{S}(s::Units{S}, t::Units{S})
```
convfact{S}(s::Units{S}, t::Units{S})
Returns 1. (Avoids effort when unnecessary.)
"""
convfact{S}(s::Units{S}, t::Units{S}) = 1

"""
```
convert{T,D,U}(::Type{Quantity{T,D,U}}, x::Number)
```
convert{T,D,U}(::Type{Quantity{T,D,U}}, x::Number)
Direct type conversion using `convert` is permissible provided conversion
is between two quantities of the same dimension.
"""
Expand All @@ -107,10 +95,7 @@ function convert{T,D,U}(::Type{Quantity{T,D,U}}, x::Number)
end

"""
```
convert{T}(::Type{Quantity{T}}, x::Number)
```
convert{T}(::Type{Quantity{T}}, x::Number)
Convert the numeric backing type of `x` to `T`. If `x <: Real`, for example,
this method yields the same result as `convert(T, x)`. If `x <: Quantity{S,D,U}`,
this method returns a `Quantity{T,D,U}` object.
Expand All @@ -126,20 +111,14 @@ function convert{T}(::Type{Quantity{T}}, x::Quantity)
end

"""
```
convert{T,U}(::Type{DimensionlessQuantity{T,U}}, x::Number)
```
convert{T,U}(::Type{DimensionlessQuantity{T,U}}, x::Number)
Convert `x` to a [`Unitful.DimensionlessQuantity`](@ref) type.
"""
convert{T,U}(::Type{DimensionlessQuantity{T,U}}, x::Number) =
uconvert(U(), convert(T,x))

"""
```
convert{T,U}(::Type{DimensionlessQuantity{T,U}}, x::Quantity)
```
convert{T,U}(::Type{DimensionlessQuantity{T,U}}, x::Quantity)
Convert `x` to a [`Unitful.DimensionlessQuantity`](@ref) type.
If `x` is already dimensionless, this is a no-op; if it is not, an
`ErrorException` is thrown.
Expand Down
35 changes: 7 additions & 28 deletions src/Display.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,7 @@ for generic arguments to flag unexpected behavior.
abbr(x) = "" # Indicate missing abbreviations

"""
```
prefix(x::Unit)
```
prefix(x::Unit)
Returns a string representing the SI prefix for the power-of-ten held by
this particular unit.
"""
Expand All @@ -48,10 +45,7 @@ function prefix(x::Unit)
end

"""
```
show(io::IO, x::Quantity)
```
show(io::IO, x::Quantity)
Show a unitful quantity by calling `show` on the numeric value, appending a
space, and then calling `show` on a units object `U()`.
"""
Expand All @@ -65,10 +59,7 @@ function show(io::IO, x::Quantity)
end

"""
```
show{T,D,U}(io::IO, ::Type{Quantity{T,D,U}})
```
show{T,D,U}(io::IO, ::Type{Quantity{T,D,U}})
Show the type of a unitful quantity in a succinct way. Otherwise,
array summaries are nearly unreadable.
"""
Expand All @@ -80,10 +71,7 @@ function show{T,D,U}(io::IO, ::Type{Quantity{T,D,U}})
end

"""
```
show(io::IO, x::Unitlike)
```
show(io::IO, x::Unitlike)
Call [`Unitful.showrep`](@ref) on each object in the tuple that is the type
variable of a [`Unitful.Units`](@ref) or [`Unitful.Dimensions`](@ref) object.
"""
Expand All @@ -98,10 +86,7 @@ function show(io::IO, x::Unitlike)
end

"""
```
showrep(io::IO, x::Unit)
```
showrep(io::IO, x::Unit)
Show the unit, prefixing with any decimal prefix and appending the exponent as
formatted by [`Unitful.superscript`](@ref).
"""
Expand All @@ -113,10 +98,7 @@ function showrep(io::IO, x::Unit)
end

"""
```
showrep(io::IO, x::Dimension)
```
showrep(io::IO, x::Dimension)
Show the dimension, appending any exponent as formatted by
[`Unitful.superscript`](@ref).
"""
Expand All @@ -126,10 +108,7 @@ function showrep(io::IO, x::Dimension)
end

"""
```
superscript(i::Rational)
```
superscript(i::Rational)
Prints exponents.
"""
function superscript(i::Rational)
Expand Down
61 changes: 15 additions & 46 deletions src/Types.jl
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@

"""
```
immutable Dimension{D}
power::Rational{Int}
end
```
immutable Dimension{D}
power::Rational{Int}
end
Description of a dimension. The name of the dimension `D` is a symbol, e.g.
`:Length`, `:Time`, `:Mass`, etc.
Expand All @@ -17,13 +13,10 @@ immutable Dimension{D}
end

"""
```
immutable Unit{U,D}
tens::Int
power::Rational{Int}
end
```
immutable Unit{U,D}
tens::Int
power::Rational{Int}
end
Description of a physical unit, including powers-of-ten prefixes and powers of
the unit. The name of the unit is encoded in the type parameter `U` as a symbol,
e.g. `:Meter`, `:Second`, `:Gram`, etc. The type parameter `D` contains dimension
Expand All @@ -40,29 +33,20 @@ immutable Unit{U,D}
end

"""
```
abstract type Unitlike end
```
abstract type Unitlike end
Represents units or dimensions. Dimensions are unit-like in the sense that they are
not numbers but you can multiply or divide them and exponentiate by rationals.
"""
@compat abstract type Unitlike end

"""
```
abstract type Units{N,D} <: Unitlike end
```
abstract type Units{N,D} <: Unitlike end
Abstract supertype of all units objects, which can differ in their implementation details.
"""
@compat abstract type Units{N,D} <: Unitlike end

"""
```
immutable FreeUnits{N,D} <: Units{N,D}
```
immutable FreeUnits{N,D} <: Units{N,D}
Instances of this object represent units, possibly combinations thereof. These behave like
units have behaved in previous versions of Unitful, and provide a basic level of
functionality that should be acceptable to most users. See
Expand All @@ -78,10 +62,7 @@ immutable FreeUnits{N,D} <: Units{N,D} end
FreeUnits{N,D}(::Units{N,D}) = FreeUnits{N,D}()

"""
```
immutable ContextUnits{N,D,P} <: Units{N,D}
```
immutable ContextUnits{N,D,P} <: Units{N,D}
Instances of this object represent units, possibly combinations thereof.
It is in most respects like `FreeUnits{N,D}`, except that the type parameter `P` is
again a `FreeUnits{M,D}` type that specifies a preferred unit for promotion.
Expand All @@ -95,10 +76,7 @@ end
ContextUnits{N,D}(u::Units{N,D}) = ContextUnits{N,D,typeof(FreeUnits(upreferred(u)))}()

"""
```
immutable FixedUnits{N,D} <: Units{N,D} end
```
immutable FixedUnits{N,D} <: Units{N,D} end
Instances of this object represent units, possibly combinations thereof.
These are primarily intended for use when you would like to disable automatic unit
conversions. See [Advanced promotion mechanisms](@ref) in the docs for details.
Expand All @@ -107,10 +85,7 @@ immutable FixedUnits{N,D} <: Units{N,D} end
FixedUnits{N,D}(::Units{N,D}) = FixedUnits{N,D}()

"""
```
immutable Dimensions{N} <: Unitlike
```
immutable Dimensions{N} <: Unitlike
Instances of this object represent dimensions, possibly combinations thereof.
"""
immutable Dimensions{N} <: Unitlike end
Expand All @@ -135,10 +110,7 @@ else
end

"""
```
immutable Quantity{T,D,U} <: Number
```
immutable Quantity{T,D,U} <: Number
A quantity, which has dimensions and units specified in the type signature.
The dimensions and units are allowed to be the empty set, in which case a
dimensionless, unitless number results.
Expand All @@ -152,10 +124,7 @@ kept separate to permit convenient dispatch on dimensions.
Quantity

"""
```
DimensionlessQuantity{T,U} = Quantity{T, Dimensions{()}, U}
```
DimensionlessQuantity{T,U} = Quantity{T, Dimensions{()}, U}
Useful for dispatching on [`Unitful.Quantity`](@ref) types that may have units
but no dimensions. (Units with differing power-of-ten prefixes are not canceled
out.)
Expand Down
Loading

0 comments on commit 9e3525d

Please sign in to comment.