Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Bugfix in Horner's scheme #79

Merged
merged 1 commit into from
Dec 12, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Polynomials.jl
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ function polyval{T,S}(p::Poly{T}, x::S)
if lenp == 0
return zero(R) * x
else
y = convert(R, p[end]) + zero(T)*x
y = convert(R, p[end])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand why zero(T)*x is here. If there is any reason, perhaps changing to zero(T)*zero(x)?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually, I do not see any benefit in using zero(T)*zero(x). since we have convert(R, p[end]) where R = promote_type(T,S), zero(x) will be automatically promoted to R. For normal numbers, I mean standard Numbers, zero(x) is not needed at all. Then, if there is a custom type Type <: Number, it might make sense to use zero(x) and rely on the conversion rules among Numbers.

What do you think?

Do you think we can push these issues (i.e., Horner's bug, Base./ and perhaps polyder) this weekend?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel the same way, but didn't write this so may be missing something. As for time, yes if no one chimes in I'll merge the first two in a few days.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks! that'd be great! :)

for i = (endof(p)-1):-1:0
y = p[i] + x*y
end
Expand Down
8 changes: 8 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -250,3 +250,11 @@ r = Poly([1.0, 2, 3])
p = poly([1,2,3])
q = poly([1,2,3])
@test hash(p) == hash(q)

## Check for Inf/NaN operations
p1 = Poly([Inf, Inf])
p2 = Poly([0, Inf])
@test p1(Inf) == Inf
@test isnan(p1(-Inf))
@test isnan(p1(0))
@test p2(-Inf) == -Inf