Compartir a través de


sqrt, sqrtf, sqrtl

Calcula la raíz cuadrada.

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
    Valor de punto flotante no negativo

Comentarios

Como C++ permite las sobrecargas, puede llamar a las sobrecargas de sqrt que toman los tipos float y long double. En un programa C, sqrt siempre toma y devuelve un tipo double.

Valor devuelto

Las funciones sqrt devuelven la raíz cuadrada de x. Si x es negativo, sqrt devuelve un NaN indefinido de forma predeterminada.

Entrada

Excepción SEH

Excepción de _matherr

± QNAN,IND

ninguna

_DOMAIN

- ∞

ninguna

_DOMAIN

x<0

ninguna

_DOMAIN

Requisitos

Función

Encabezado C

Encabezado C++

sqrt, sqrtf, sqrtl

<math.h>

<cmath>

Para obtener información de compatibilidad, vea Compatibilidad.

Ejemplo

// 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 );
}
  

Equivalente en .NET Framework

System::Math::Sqrt

Vea también

Referencia

Compatibilidad con el punto flotante

exp, expf

log, logf, log10, log10f

pow, powf, powl

_CIsqrt