muladd
muladd(x, y, z)
Combined multiply-add, computes x*y+z
in an efficient manner. This may on some systems be equivalent to x*y+z
, or to fma(x,y,z)
. muladd
is used to improve performance. See fma
.
Examples
-
Basic usage with numbers:
julia> muladd(2, 3, 4) 10
This example computes
2*3 + 4
usingmuladd
and returns the result. -
Compute a polynomial expression:
julia> x = 2; julia> y = 3; julia> z = 4; julia> muladd(x^2, y^2, z^2) 52
It demonstrates how
muladd
can be used to efficiently compute a polynomial expressionx^2 * y^2 + z^2
. - Use with arrays:
julia> a = [1, 2, 3]; julia> b = [4, 5, 6]; julia> c = [7, 8, 9]; julia> muladd.(a, b, c) 3-element Array{Int64,1}: 11 18 27
Here,
muladd
is applied element-wise to the arraysa
,b
, andc
to computea[i]*b[i] + c[i]
for each element.
Common mistake example:
julia> muladd([1, 2, 3], [4, 5, 6])
ERROR: MethodError: no method matching muladd(::Array{Int64,1}, ::Array{Int64,1})
In this example, the muladd
function is called with only two arguments, while it requires three arguments. Make sure to provide all three required arguments when using muladd
.
See Also
User Contributed Notes
Add a Note
The format of note supported is markdown, use triple backtick to start and end a code block.