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

  1. Basic usage with numbers:

    julia> muladd(2, 3, 4)
    10

    This example computes 2*3 + 4 using muladd and returns the result.

  2. 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 expression x^2 * y^2 + z^2.

  3. 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 arrays a, b, and c to compute a[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.

*Required Field
Details

Checking you are not a robot: