'C++' std::pow, std::powf, std::powl

토스트·2025년 1월 16일

'C++' std::cmath

목록 보기
3/10

pow

template<class Arithmetic1, class Arithmetic2>
/*common-floating-point-type*/ pow(Arithmetic1 base, Arithmetic2 exp);

common floating point type
두 개 이상의 부동소수점 타입이 결합될 때, 가장 높은 정밀도의 타입으로 결과가 결정됩니다.
일반적으로 float → double → long double 순으로 타입의 정밀도가 증가합니다.

~ C++23

float pow(float base, float exp);

double pow(double base, double exp);

long double pow(long double base, long double exp);

C++23 ~

/*floating-point-type*/ pow(/*floating-point-type*/ base, /*floating-point-type*/ exp);

: base 값에 대해 exp 제곱을 한 power(거듭제곱)을 반환합니다.

powf

float powf(float base, float exp);

: float 타입에 대해 형 변환없이 power(거듭제곱)을 반환합니다.

powl

long double powl(long double base, long double exp);

: long double 타입에 대해 형 변환없이 power(거듭제곱)을 반환합니다.

baseexpbase^{exp}

  • base : "기본 값" 또는 "밑"으로, 거듭제곱 연산의 기준이 되는 값
  • exp : "지수"로, 기본 값을 몇 번 곱할지를 결정하는 값

<example>

#include <iostream>
#include <cmath>

using namespace std;

int main() {
    cout << pow(5, 3) << endl;

    cout << pow(5.2, 1.2);

    return 0;
}

결과값

0개의 댓글