diff --git a/src/arithmetic.jl b/src/arithmetic.jl index 95ae14a9..10bfffc8 100644 --- a/src/arithmetic.jl +++ b/src/arithmetic.jl @@ -116,6 +116,10 @@ for (f, fc) in ((:+, :(add!)), (:-, :(subst!))) @inbounds v[k+1] = ($f)(a[k+1]) return nothing end + function ($fc)(v::$T, a::NumberNotSeries, k::Int) + @inbounds v[k+1] = k==0 ? ($f)(a) : zero(v[k+1]) + return nothing + end function ($fc)(v::$T, a::$T, b::$T, k::Int) @inbounds v[k+1] = ($f)(a[k+1], b[k+1]) return nothing diff --git a/test/manyvariables.jl b/test/manyvariables.jl index 3ad22790..4c97a7ae 100644 --- a/test/manyvariables.jl +++ b/test/manyvariables.jl @@ -263,8 +263,16 @@ using Base.Test xx = 1.0*zeroT TaylorSeries.add!(xx, 1.0*xT, 2yT, 1) @test xx[2] == HomogeneousPolynomial([1,2]) + TaylorSeries.add!(xx, 5.0, 0) + @test xx[1] == HomogeneousPolynomial([5.0]) + TaylorSeries.add!(xx, -5.0, 1) + @test xx[2] == zero(xx[2]) TaylorSeries.subst!(xx, 1.0*xT, yT, 1) @test xx[2] == HomogeneousPolynomial([1,-1]) + TaylorSeries.subst!(xx, 5.0, 0) + @test xx[1] == HomogeneousPolynomial([-5.0]) + TaylorSeries.subst!(xx, -5.0, 1) + @test xx[2] == zero(xx[2]) TaylorSeries.div!(xx, 1.0+xT, 1.0+xT, 0) @test xx[1] == 1.0 TaylorSeries.pow!(xx, 1.0+xT, 1.5, 0) diff --git a/test/onevariable.jl b/test/onevariable.jl index c73cb7cf..fe5fd4e3 100644 --- a/test/onevariable.jl +++ b/test/onevariable.jl @@ -180,8 +180,16 @@ using Base.Test tt = zero(ut) TaylorSeries.add!(tt, ut, ut, 1) @test tt[2] == 2.0 + TaylorSeries.add!(tt, -3.0, 0) + @test tt[1] == -3.0 + TaylorSeries.add!(tt, -3.0, 1) + @test tt[2] == 0.0 TaylorSeries.subst!(tt, ut, ut, 1) @test tt[2] == 0.0 + TaylorSeries.subst!(tt, -3.0, 0) + @test tt[1] == 3.0 + TaylorSeries.subst!(tt, -2.5, 1) + @test tt[2] == 0.0 iind, cind = TaylorSeries.divfactorization(ut, ut) @test iind == 1 @test cind == 1.0