fma - C math.h

C examples for math.h:fma

Type

function

From

<cmath>
<ctgmath>
<math.h>

Description

Returns x*y+z. The function computes the result without losing precision in any intermediate result.

Macro Type Description
FP_FAST_FMA int if defined, identifies for which type fma is at least as efficient as x*y+z.
FP_FAST_FMAF int if defined, identifies for which type fmaf is at least as efficient as x*y+z.
FP_FAST_FMAL int if defined, identifies for which type fmal is at least as efficient as x*y+z.

Prototype

long double fmal (long double x, long double y, long double z);
long double fma (long double x, long double y, long double z);
     double fma  (double x, double y, double z);
      float fmaf (float x,  float y , float z);
      float fma (float x,   float y , float z);
     double fma (Type1 x,   Type2 y , Type3 z);       

Parameters

Parameter Description
x Values to be multiplied.
y Values to be multiplied.
z Value to be added.

Return Value

The result of x*y+z

Example

Demo Code


#include <stdio.h>
#include <math.h> /* fma, FP_FAST_FMA */

int main ()//from  w  w w. ja va2  s. com
{
  double x,y,z,result;
  x = 10.0, y = 20.0, z = 30.0;

#ifdef FP_FAST_FMA
  result = fma(x,y,z);
#else
  result = x*y+z;
#endif

  printf ("10.0 * 20.0 + 30.0 = %f\n", result);
  return 0;
}

Related Tutorials