Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

use muladd in horner macro #9881

Merged
merged 3 commits into from
Feb 4, 2015
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
8 changes: 4 additions & 4 deletions base/math.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ clamp{T}(x::AbstractArray{T}, lo, hi) =
macro horner(x, p...)
ex = esc(p[end])
for i = length(p)-1:-1:1
ex = :($(esc(p[i])) + t * $ex)
ex = :(muladd(t, $ex, $(esc(p[i]))))
end
Expr(:block, :(t = $(esc(x))), ex)
end
Expand All @@ -61,8 +61,8 @@ macro evalpoly(z, p...)
for i = length(p)-2:-1:1
ai = symbol("a", i)
push!(as, :($ai = $a))
a = :($b + r*$ai)
b = :($(esc(p[i])) - s * $ai)
a = :(muladd(r, $ai, $b))
b = :(muladd(-s, $ai, $(esc(p[i]))))
end
ai = :a0
push!(as, :($ai = $a))
Expand All @@ -72,7 +72,7 @@ macro evalpoly(z, p...)
:(r = x + x),
:(s = x*x + y*y),
as...,
:($ai * tt + $b))
:(muladd($ai, tt, $b)))
R = Expr(:macrocall, symbol("@horner"), :tt, p...)
:(let tt = $(esc(z))
isa(tt, Complex) ? $C : $R
Expand Down
2 changes: 1 addition & 1 deletion base/promotion.jl
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ no_op_err(name, T) = error(name," not defined for ",T)

fma{T<:Number}(x::T, y::T, z::T) = no_op_err("fma", T)
fma(x::Integer, y::Integer, z::Integer) = x*y+z
muladd{T<:Number}(x::T, y::T, z::T) = no_op_err("muladd", T)
muladd{T<:Number}(x::T, y::T, z::T) = x*y+z

(&){T<:Integer}(x::T, y::T) = no_op_err("&", T)
(|){T<:Integer}(x::T, y::T) = no_op_err("|", T)
Expand Down