avx2 fma_fma()函数以及C ++中的示例

C++ fma() 函数是cmath库的一部分,用于执行精确的乘加操作,避免精度损失。它接受三个参数x、y和z,返回x * y + z的结果。fma()函数的使用可以确保高精度计算。在示例中,展示了如何在C++代码中使用fma()函数。
摘要由CSDN通过智能技术生成

avx2 fma

C ++ fma()函数 (C++ fma() function)

fma() function is a library function of cmath header, it is used to find the result of multiply-add, it accepts three arguments and returns the result of the expression where first and second arguments will be multiplied and the third argument will be added to the multiplied result. It the arguments are x, y and z, it returns (x*y+z).

fma()函数cmath标头的库函数,用于查找乘加结果,它接受三个参数并返回表达式的结果,其中第一个和第二个参数将相乘,第三个参数将被添加相乘的结果。 如果参数是x , y和z ,则返回(x * y + z) 。

Note: The fma() function computes and returns the exact result without losing precision.

注意: fma()函数计算并返回精确结果,而不会损失精度。

Syntax of fma() function:

fma()函数的语法:

    fma(x, y, z);

Parameter(s): x, y, z – are the numbers to calculate the multiply-add.

参数: x,y,z –是用于计算乘加的数字。

Return value: double – it returns double value that is the result of x*y+z.

返回值: double-返回x * y + z的结果double值。

Example:

例:

    Input:
    float x = 10.20;
    float y = 20.91;
    float z = 30.12;

    Function call:
    fma(x, y, z);

    Output:
    243.402

C ++代码演示fma()函数的示例 (C++ code to demonstrate the example of fma() function)

// C++ code to demonstrate the example of 
// fma() function

#include <iostream>
#include <cmath>
using namespace std;

// main() section
int main()
{
    float x,y,z;
    float result;
    
    x = 1;
    y = 2;
    z = 3;
    result = fma(x,y,z);
    cout<<"result: "<<result<<endl;

    x = 10.20;
    y = 20.91;
    z = 30.12;
    result = fma(x,y,z);
    cout<<"result: "<<result<<endl;    

    x = -10.21220;
    y = 20.9122;
    z = -30.1212;
    result = fma(x,y,z);
    cout<<"result: "<<result<<endl;    

    return 0;
}

Output

输出量

result: 5
result: 243.402
result: -243.681


翻译自: https://www.includehelp.com/cpp-tutorial/fma-function-with-example.aspx

avx2 fma

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值