-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
52 additions
and
29 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
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,46 @@ | ||
# This file is a part of Julia. License is MIT: https://julialang.org/license | ||
|
||
module DualNumbers | ||
|
||
export Dual | ||
|
||
# Dual numbers type with minimal interface | ||
# example of a (real) number type that subtypes Number, but not Real. | ||
# Can be used to test generic linear algebra functions. | ||
|
||
struct Dual{T<:Real} <: Number | ||
val::T | ||
eps::T | ||
end | ||
Base.:+(x::Dual, y::Dual) = Dual(x.val + y.val, x.eps + y.eps) | ||
Base.:-(x::Dual, y::Dual) = Dual(x.val - y.val, x.eps - y.eps) | ||
Base.:*(x::Dual, y::Dual) = Dual(x.val * y.val, x.eps * y.val + y.eps * x.val) | ||
Base.:*(x::Number, y::Dual) = Dual(x*y.val, x*y.eps) | ||
Base.:*(x::Dual, y::Number) = Dual(x.val*y, x.eps*y) | ||
Base.:/(x::Dual, y::Dual) = Dual(x.val / y.val, (x.eps*y.val - x.val*y.eps)/(y.val*y.val)) | ||
|
||
Base.:(==)(x::Dual, y::Dual) = x.val == y.val && x.eps == y.eps | ||
|
||
Base.promote_rule(::Type{Dual{T}}, ::Type{T}) where {T} = Dual{T} | ||
Base.promote_rule(::Type{Dual{T}}, ::Type{S}) where {T,S<:Real} = Dual{promote_type(T, S)} | ||
Base.promote_rule(::Type{Dual{T}}, ::Type{Dual{S}}) where {T,S} = Dual{promote_type(T, S)} | ||
|
||
Base.convert(::Type{Dual{T}}, x::Dual{T}) where {T} = x | ||
Base.convert(::Type{Dual{T}}, x::Dual) where {T} = Dual(convert(T, x.val), convert(T, x.eps)) | ||
Base.convert(::Type{Dual{T}}, x::Real) where {T} = Dual(convert(T, x), zero(T)) | ||
|
||
Base.float(x::Dual) = Dual(float(x.val), float(x.eps)) | ||
# the following two methods are needed for normalize (to check for potential overflow) | ||
Base.typemax(x::Dual) = Dual(typemax(x.val), zero(x.eps)) | ||
Base.prevfloat(x::Dual{<:AbstractFloat}) = prevfloat(x.val) | ||
|
||
Base.abs2(x::Dual) = x*x | ||
Base.abs(x::Dual) = sqrt(abs2(x)) | ||
Base.sqrt(x::Dual) = Dual(sqrt(x.val), x.eps/(2sqrt(x.val))) | ||
|
||
Base.isless(x::Dual, y::Dual) = x.val < y.val | ||
Base.isless(x::Real, y::Dual) = x < y.val | ||
Base.isinf(x::Dual) = isinf(x.val) & isfinite(x.eps) | ||
Base.real(x::Dual) = x # since we curently only consider Dual{<:Real} | ||
|
||
end # module |
ea5c9cb
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Executing the daily package evaluation, I will reply here when finished:
@nanosoldier
runtests(isdaily = true)
ea5c9cb
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your package evaluation job has completed - possible new issues were detected.
A full report can be found here.
ea5c9cb
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nanosoldier
runtests(vs = "@9ed4087f7f515f76a71164e292b013043b862053")
ea5c9cb
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nanosoldier
runtests(vs = "@9ed4087f7f515f76a71164e292b013043b862053")
ea5c9cb
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your package evaluation job has completed - possible new issues were detected.
A full report can be found here.
ea5c9cb
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nanosoldier
runtests(configuration = (env=["ENABLE_GDBLISTENER=1"],), vs = "@9ed4087f7f515f76a71164e292b013043b862053")
ea5c9cb
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your package evaluation job has completed - possible new issues were detected.
A full report can be found here.