Skip to content

Commit da2908a

Browse files
authored
Create polynomial of order 0 with Taylor1([Type], 0) (#402)
* Fix bug for `Taylor1(T, 0)` (with test) * Bump patch version
1 parent 9bb0b11 commit da2908a

3 files changed

Lines changed: 5 additions & 1 deletion

File tree

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "TaylorSeries"
22
uuid = "6aa5eb33-94cf-58f4-a9d0-e4b2c4fc25ea"
3-
version = "0.21.2"
3+
version = "0.21.3"
44
repo = "https://github.com/JuliaDiff/TaylorSeries.jl.git"
55

66
[deps]

src/constructors.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,14 @@ julia> Taylor1(Rational{Int}, 4)
8383
```
8484
"""
8585
function Taylor1(::Type{T}, order::Int) where {T<:Number}
86+
order == 0 && return Taylor1{T}(FixedSizeVectorDefault{T}([zero(T)]))
8687
coeffs = FixedSizeVectorDefault{T}(undef, order+1)
8788
coeffs .= zero(T)
8889
coeffs[2] = one(T)
8990
return Taylor1{T}(coeffs)
9091
end
9192
function Taylor1(order::Int)
93+
order == 0 && return Taylor1{Float64}(FixedSizeVectorDefault{Float64}([0.0]))
9294
coeffs = FixedSizeVectorDefault{Float64}(undef, order+1)
9395
coeffs .= 0.0
9496
coeffs[2] = 1.0

test/onevariable.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ Base.iszero(::SymbNumber) = false
105105
@test y.coeffs[1:2:9] == rv[1:5]
106106
@test_throws AssertionError y[0:2:3] = rv
107107

108+
@test Taylor1(0) == Taylor1(0.0, 0)
109+
@test Taylor1(Rational{Int}, 0) == Taylor1(0//1, 0)
108110
@test Taylor1([0,1,0,0]) == Taylor1(3)
109111
@test getcoeff(Taylor1(Complex{Float64},3),1) == complex(1.0,0.0)
110112
@test Taylor1(Complex{Float64},3)[1] == complex(1.0,0.0)

0 commit comments

Comments
 (0)