Skip to content

Commit

Permalink
Add abs!
Browse files Browse the repository at this point in the history
  • Loading branch information
Luis Benet committed Aug 29, 2017
1 parent 840b042 commit 4a91d06
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/dictmutfunct.jl
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ const _dict_unary_ops = Dict(
:identity => [:identity!, (:_res, :_arg1, :_k), :(_res = identity(_arg1))],
:zero => [:zero!, (:_res, :_arg1, :_k), :(_res = zero(_arg1))],
:one => [:one!, (:_res, :_arg1, :_k), :(_res = one(_arg1))],
:abs => [:abs!, (:_res, :_arg1, :_k), :(_res = abs(_arg1))],
#
:sin => [:sincos!, (:_res, :_aux, :_arg1, :_k), :(_res = sin(_arg1)),
:(_aux = cos(_arg1))],
Expand Down
14 changes: 14 additions & 0 deletions src/functions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,20 @@ for T in (:Taylor1, :TaylorN)
return nothing
end

@inline function abs!(c::$T, a::$T, k::Int)
z = zero(constant_term(a))
if constant_term(a) > z
return add!(c, a, k)
elseif constant_term(a) < z
return subst!(c, a, k)
else
throw(ArgumentError(
"""The 0th order coefficient must be non-zero
(abs(x) is not differentiable at x=0)."""))
end
return nothing
end

@inline function exp!(c::$T, a::$T, k::Int)
if k == 0
@inbounds c[1] = exp(constant_term(a))
Expand Down

0 comments on commit 4a91d06

Please sign in to comment.