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) 10This example computes
2*3 + 4usingmuladdand returns the result. -
Compute a polynomial expression:
julia> x = 2; julia> y = 3; julia> z = 4; julia> muladd(x^2, y^2, z^2) 52It demonstrates how
muladdcan 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 27Here,
muladdis applied element-wise to the arraysa,b, andcto 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.