forked from PainterQubits/Unitful.jl
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implement Base.complex, Base.widen, Base.reim (PainterQubits#2)
- Loading branch information
Björn Stein
committed
May 2, 2019
1 parent
82f8496
commit 7fb6107
Showing
4 changed files
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ | |
deps/ | ||
docs/build/ | ||
docs/site/ | ||
*~ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# This file is meant to provide all the methods in | ||
# https://github.com/JuliaLang/julia/blob/master/base/complex.jl that | ||
# are defined for Real or Complex numbers, just for | ||
# AbstractQuantities{T,D,U} where T is Real or Complex, respectively. | ||
# | ||
# It is currently incomplete. | ||
|
||
complex(z::Quantity{T,D,U}) where {T<:Complex,D,U} = z | ||
function complex(x::Quantity{T,D,U}, y = zero(x)) where { | ||
T<:Real,D,U | ||
} | ||
r, i = promote(x, y) | ||
return Quantity{complex(T),D,U}(complex(ustrip(r), ustrip(i))) | ||
end | ||
complex(::Type{Quantity{T,D,U}}) where {T,D,U} = | ||
Quantity{complex(T),D,U} | ||
|
||
# implement Base.widen for real and complex quantities because Unitful | ||
# does not have an implementation for widen yet | ||
Base.widen(::Type{Quantity{T,D,U}}) where {T,D,U} = | ||
Quantity{widen(T),D,U} | ||
|
||
# skip Base.float, Base.real, Base.imag because it is already | ||
# implemented | ||
|
||
Base.reim(z::Quantity{T,D,U}) where {T<:Complex,D,U} = | ||
(real(z), imag(z)) | ||
|
||
# Base.real for types has a general implementation in julia; a faster | ||
# method could be provided but is not strictly required. | ||
|
||
# Base.isreal, etc., are already implemented in Unitful. | ||
|
||
# Base.flipsign is already implemented in Unitful. | ||
|
||
# To Do: Check if Base.show, Base.read, Base.write, etc. need any | ||
# attention | ||
|
||
# ... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters