Namespaces
Variants

fdim, fdimf, fdiml

From cppreference.net
< c ‎ | numeric ‎ | math
Common mathematical functions
Functions
Basic operations
(C99)
(C99)
fdim
(C99)
(C99) (C99) (C99) (C23)
Maximum/minimum operations
Exponential functions
Power functions
Trigonometric and hyperbolic functions
Nearest integer floating-point
(C99) (C99) (C99)
(C23) (C23) (C23) (C23)
Floating-point manipulation
Narrowing operations
(C23)
(C23)
(C23)
(C23)
(C23)
(C23)
Quantum and quantum exponent
Decimal re-encoding functions
Total order and payload functions
Classification
Error and gamma functions
(C99)
(C99)
(C99)
(C99)
Types
Macro constants
Special floating-point values
Arguments and return values
Error handling
Fast operation indicators
Definido en el encabezado <math.h>
float fdimf ( float x, float y ) ;
(1) (desde C99)
double fdim ( double x, double y ) ;
(2) (desde C99)
long double fdiml ( long double x, long double y ) ;
(3) (desde C99)
Definido en el encabezado <tgmath.h>
#define fdim( x, y )
(4) (desde C99)
1-3) Devuelve la diferencia positiva entre x y y , es decir, si x > y , devuelve x - y , en caso contrario (si x≤y ), devuelve +0.
4) Macro genérica de tipos: Si algún argumento tiene tipo long double , fdiml es llamado. De lo contrario, si algún argumento tiene tipo entero o tiene tipo double , fdim es llamado. De lo contrario, fdimf es llamado.

Contenidos

Parámetros

x, y - valor de punto flotante

Valor de retorno

Si tiene éxito, devuelve la diferencia positiva entre x y y .

Si ocurre un error de rango debido a desbordamiento, +HUGE_VAL , +HUGE_VALF , o +HUGE_VALL es devuelto.

Si ocurre un error de rango debido a desbordamiento inferior, se devuelve el valor correcto (después del redondeo).

Manejo de errores

Los errores se reportan como se especifica en Template:rllpt .

Si la implementación soporta aritmética de punto flotante IEEE (IEC 60559),

  • Si cualquiera de los argumentos es NaN, se devuelve NaN.

Notas

Equivalente a fmax ( x - y, 0 ) excepto por los requisitos de manejo de NaN.

Ejemplo

#include <errno.h>
#include <fenv.h>
#include <math.h>
#include <stdio.h>
// #pragma STDC FENV_ACCESS ON
int main(void)
{
    printf("fdim(4, 1) = %f, fdim(1, 4)=%f\n", fdim(4,1), fdim(1,4));
    printf("fdim(4,-1) = %f, fdim(1,-4)=%f\n", fdim(4,-1), fdim(1,-4));
    //error handling
    errno = 0; feclearexcept(FE_ALL_EXCEPT);
    printf("fdim(1e308, -1e308) = %f\n", fdim(1e308, -1e308));
    if (errno == ERANGE)
        perror("    errno == ERANGE");
    if (fetestexcept(FE_OVERFLOW))
        puts("    FE_OVERFLOW raised");
}

Salida posible:

fdim(4, 1) = 3.000000, fdim(1, 4)=0.000000
fdim(4,-1) = 5.000000, fdim(1,-4)=5.000000
fdim(1e308, -1e308) = inf
    errno == ERANGE: Resultado numérico fuera de rango
    FE_OVERFLOW raised

Referencias

  • Estándar C23 (ISO/IEC 9899:2024):
  • 7.12.12.1 Las funciones fdim (p: TBD)
  • 7.25 Matemáticas genéricas de tipos <tgmath.h> (p: TBD)
  • F.10.9.1 Las funciones fdim (p: TBD)
  • Estándar C17 (ISO/IEC 9899:2018):
  • 7.12.12.1 Las funciones fdim (p: 187-188)
  • 7.25 Matemáticas genéricas de tipos <tgmath.h> (p: 272-273)
  • F.10.9.1 Las funciones fdim (p: 386)
  • Estándar C11 (ISO/IEC 9899:2011):
  • 7.12.12.1 Las funciones fdim (p: 257)
  • 7.25 Matemáticas genéricas de tipo <tgmath.h> (p: 373-375)
  • F.10.9.1 Las funciones fdim (p: 530)
  • Estándar C99 (ISO/IEC 9899:1999):
  • 7.12.12.1 Las funciones fdim (p: 238)
  • 7.22 Matemáticas genéricas de tipo <tgmath.h> (p: 335-337)
  • F.9.9.1 Las funciones fdim (p: 466)

Véase también

calcula el valor absoluto de un valor integral ( |x| )
(función)
(C99) (C99) (C99)
determina el mayor de dos valores de punto flotante
(función)