sqrt, sqrtf, sqrtl

Calcola la radice quadrata.

Sintassi

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
);
#define sqrt(x) // Requires C11 or higher

Parametri

x
Valore a virgola mobile non negativo

Osservazioni:

Poiché C++ consente l'overload, è possibile chiamare overload di sqrt che accettino tipi float e long double. In un programma C, a meno che non si usi la <tgmath.h> macro per chiamare questa funzione, sqrt accetta sempre e restituisce double.

Se si utilizza la <tgmath.h> sqrt() macro, il tipo dell'argomento determina quale versione della funzione è selezionata. Per informazioni dettagliate, vedere La matematica generica dei tipi.

Per impostazione predefinita, lo stato globale di questa funzione è limitato all'applicazione. Per modificare questo comportamento, vedere Stato globale in CRT.

Valore restituito

La funzione sqrt restituisce la radice quadrata di x. Per impostazione predefinita, se x è negativo, sqrt restituisce un valore illimitato NaN.

Input Eccezione SEH Eccezione _matherr
± QNaN, IND Nessuno _DOMAIN
-INF Nessuno _DOMAIN
x < 0 Nessuno _DOMAIN

Requisiti

Funzione Intestazione C Intestazione C++
sqrt, sqrtf, sqrtl <math.h> <cmath>
sqrt Macro <tgmath.h>

Per informazioni sulla compatibilità, vedere Compatibilità.

Esempio

// 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 );
}
The square root of 45.35 is 6.73

Vedi anche

Supporto matematico e a virgola mobile
exp, expf, expl
log, logf, log10, log10f
pow, powf, powl
_CIsqrt