Abs, _abs64

Calcule o valor absoluto.

int abs( 
   int n 
);
long abs( 
   long n 
);   // C++ only
double abs( 
   double n 
);   // C++ only
long double abs(
   long double n
);   // C++ only
float abs(
   float n 
);   // C++ only
__int64 _abs64( 
   __int64 n 
);

Parâmetros

  • n
    Valor inteiro.

Valor de retorno

The abs função retorna o valor absoluto de seu parâmetro. Não há nenhum retorno de erro.

Comentários

C++ permite sobrecarga, para que você possa telefonar sobrecargas de abs. Em um programa C, abs sempre utiliza e retorna um int.

Requisitos

Rotina

Cabeçalho necessário

abs

<stdlib.h> ou <math.h>

_abs64

<stdlib.h>

Exemplo

Este programa calcula e exibe os valores absolutos de vários números.

// crt_abs.c
// This program demonstrates the user of the abs function
// by computing and displaying the absolute values of
// several numbers.

#include  <stdio.h>
#include  <math.h>
#include  <stdlib.h>

int main( void )
{
    int     ix = -4,
            iy;
    long    lx = -41567L,
            ly;
    double  dx = -3.141593,
            dy;
    __int64 wx = -1, wy;

    // absolute 64 bit integer value
    wy = _abs64( wx );
    printf_s( "The absolute value of %I64x is %I64x\n", wx, wy);

    // absolute 32 bit integer value
    iy = abs( ix );
    printf_s( "The absolute value of %d is %d\n", ix, iy);

    // absolute long integer value
    ly = labs( lx );
    printf_s( "The absolute value of %ld is %ld\n", lx, ly);

    // absolute double value
    dy = fabs( dx );
    printf_s( "The absolute value of %f is %f\n", dx, dy );
}

The absolute value of ffffffffffffffff is 1 The absolute value of -4 is 4 The absolute value of -41567 is 41567 The absolute value of -3.141593 is 3.141593

Equivalente do NET Framework

sistema::Math::Abs

Consulte também

Referência

Conversão de Dados

Suporte de ponto flutuante

_cabs

fabs, fabsf

laboratórios