sqrt sqrtf

計算這個平方根。

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

參數

  • x
    非負浮點值

備註

C++ 允許多載,因此,使用者可以呼叫採用浮動或長雙精度浮點數型別 sqrt 的多載。在 C++ 程式,. sqrt 一定會採用,並且傳回 double。

傳回值

sqrt 函式傳回 x平方根。如果 x 是負值,則 sqrt 會傳回不確定,預設為。

輸入

SEH 例外狀況

Matherr 例外狀況。

± QNAN 、 IND

_DOMAIN

- ∞

無效

_DOMAIN

x<0

無效

_DOMAIN

需求

程序

必要的標頭檔

sqrt, sqrtf

<math.h>

如需其他相容性資訊,請參閱入門介紹中的 相容性 (Compatibility)

範例

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

.NET Framework 對等用法

System::Math::Sqrt

請參閱

參考

浮點支援

expf exp

log、 logf、 log10、 log10f

pow powf

_CIsqrt