Compartilhar via


sqrt, sqrtf, sqrtl

Calcula a raiz quadrada.

double sqrt(    double x  ); float sqrt(    float x  );  // C++ only long double sqrt(    long double x );  // C++ only float sqrtf(    float x  ); long double sqrtl(    long double x  );

Parâmetros

  • x
    Um valor de ponto flutuante não negativo

Comentários

Como C++ permite a sobrecarga, você pode chamar sobrecargas de sqrt que usam o tipo float ou long double. Em programas C, sqrt sempre usa e retorna double.

Valor de retorno

A função sqrt retorna a raiz quadrada de x. Por padrão, se x for um valor negativo, sqrt retorna um NaN (não é um número) indefinido.

Entrada

Exceção SEH

Exceção _matherr

± QNAN,IND

nenhum

_DOMAIN

- ∞

nenhum

_DOMAIN

x<0

nenhum

_DOMAIN

Requisitos

Função

Cabeçalho C

Cabeçalho C++

sqrt, sqrtf, sqrtl

<math.h>

<cmath>

Para obter informações sobre compatibilidade, consulte Compatibilidade.

Exemplo

// crt_sqrt.c
// This program calculates a square root.

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

int main( void )
{
   double question = 45.35, answer;
   answer = sqrt( question );
   if( question < 0 )
      printf( "Error: sqrt returns %f\n", answer );
   else
      printf( "The square root of %.2f is %.2f\n", question, answer );
}
  

Equivalência do .NET Framework

System::Math::Sqrt

Consulte também

Referência

Suporte de ponto flutuante

exp, expf

log, logf, log10, log10f

pow, powf, powl

_CIsqrt