'C++' std::sqrt, std::sqrtf, std::sqrtl

토스트·2025년 1월 16일

'C++' std::cmath

목록 보기
2/10

sqrt

template<class Integer>
double sqrt(Integer num); // constexpr since C++26

~ C++23

float sqrt(float num);

double sqrt(double num);

long double sqrt(long double num);

C++23 ~

/*floating-point-type*/ sqrt(/*floating-point-type*/ num); // constexpr since C++26

: square root(제곱근)을 반환합니다.

sqrtf

float sqrtf(float num);

: float 타입에 대해 형 변환없이 square root(제곱근)을 반환합니다.

sqrtl

long double sqrtl(long double num);

: long double 타입에 대해 형 변환없이 square root(제곱근)을 반환합니다.

num\sqrt{num}

  • num : 제곱근을 구하려는 값

<example>

#include <iostream>
#include <cmath>

using namespace std;

int main() {
    
    cout << sqrtf(16) << endl;

    cout << sqrtf(15.3);

    return 0;
}

결과값

0개의 댓글