Skip to content

Commit 3ceb43c

Browse files
authored
Issue 316 (#317)
* close issue #316 * remove changes from a different branch
1 parent 4f7c566 commit 3ceb43c

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

docs/src/extending.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ Check out both the [`Polynomial`](@ref) and [`ChebyshevT`](@ref) for examples of
3535
## Example
3636

3737
The following shows a minimal example where the polynomial aliases the vector defining the coefficients.
38-
The constructor ensures that there are no trailing zeros. The `@register` call ensures a common interface. This example subtypes `StandardBasisPolynomial`, not `AbstractPolynomial`, and consequently inherits the methods above that otherwise would have been required. For other bases, more methods may be necessary to define (again, refer to [`ChebyshevT`](@ref) for an example).
38+
The constructor ensures that there are no trailing zeros. The `@register` call ensures a common interface. This example subtypes `StandardBasisPolynomial`, not `AbstractPolynomial`, and consequently inherits the methods above that otherwise would have been required. For other bases, more methods may be necessary to define (again, refer to [`ChebyshevT`](@ref) for an example).
3939

4040
```jldoctest AliasPolynomial
4141
julia> using Polynomials

src/abstract.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ macro register(name)
5656
$poly{eltype(cs), Symbol(var)}(cs)
5757
end
5858
$poly{T,X}(n::S) where {T, X, S<:Number} =
59-
n * one($poly{T, X})
59+
T(n) * one($poly{T, X})
6060
$poly{T}(n::S, var::SymbolLike = :x) where {T, S<:Number} =
61-
n * one($poly{T, Symbol(var)})
61+
T(n) * one($poly{T, Symbol(var)})
6262
$poly(n::S, var::SymbolLike = :x) where {S <: Number} = n * one($poly{S, Symbol(var)})
6363
$poly{T}(var::SymbolLike=:x) where {T} = variable($poly{T, Symbol(var)})
6464
$poly(var::SymbolLike=:x) = variable($poly, Symbol(var))
@@ -85,8 +85,8 @@ macro registerN(name, params...)
8585
$poly{$(αs...)}(coeffs::AbstractVector{T}, var::SymbolLike=:x) where {$(αs...),T} =
8686
$poly{$(αs...),T,Symbol(var)}(coeffs)
8787

88-
$poly{$(αs...),T,X}(n::Number) where {$(αs...),T,X} = n*one($poly{$(αs...),T,X})
89-
$poly{$(αs...),T}(n::Number, var::SymbolLike = :x) where {$(αs...),T} = n*one($poly{$(αs...),T,Symbol(var)})
88+
$poly{$(αs...),T,X}(n::Number) where {$(αs...),T,X} = T(n)*one($poly{$(αs...),T,X})
89+
$poly{$(αs...),T}(n::Number, var::SymbolLike = :x) where {$(αs...),T} = T(n)*one($poly{$(αs...),T,Symbol(var)})
9090
$poly{$(αs...)}(n::S, var::SymbolLike = :x) where {$(αs...), S<:Number} =
9191
n*one($poly{$(αs...),S,Symbol(var)})
9292
$poly{$(αs...),T}(var::SymbolLike=:x) where {$(αs...), T} = variable($poly{$(αs...),T,Symbol(var)})

test/StandardBasis.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ isimmutable(::Type{<:ImmutablePolynomial}) = true
4242
P == Polynomial && @test typeof(p).parameters[1] == eltype(coeff)
4343
@test eltype(p) == eltype(coeff)
4444
@test all([-200, -0.3, 1, 48.2] .∈ domain(p))
45+
46+
## issue #316
47+
@test_throws InexactError P{Int,:x}([1+im, 1])
48+
@test_throws InexactError P{Int}([1+im, 1], :x)
49+
@test_throws InexactError P{Int,:x}(1+im)
50+
@test_throws InexactError P{Int}(1+im)
4551
end
4652

4753
end

0 commit comments

Comments
 (0)