math — 공통 수학 함수

math — 공통 수학 함수 (Common mathematical functions)

**공통 수학 함수(common mathematical functions)**는 <cmath>(그리고 일부 <cstdlib>, <cinttypes>)가 제공하는 수학 함수들의 집합이에요.

기본 연산, 지수·로그, 삼각, 쌍곡선, 반올림 등 다양한 범주로 구성돼요.

출처: cppreference

본문

함수 범주

<cstdlib>

  • abs, div — 정수 절댓값과 나눗셈

<cinttypes>

  • imaxabs, imaxdiv — intmax_t 절댓값·나눗셈

<cmath> 기본 연산 (Basic operations)

  • fabs — 절댓값
  • fmod, remainder, remquo — 나머지
  • fma — 곱셈-덧셈 융합
  • fmin, fmax — 최소/최대
  • fdim — 양의 차이

지수·로그 (Exponential & logarithmic)

  • exp, exp2, expm1 — 지수
  • log, log2, log10, log1p, logb, ilogb — 로그
  • pow — 거듭제곱
  • sqrt, cbrt, hypot — 제곱근·세제곱근·빗변

삼각 (Trigonometric)

  • sin, cos, tan
  • asin, acos, atan, atan2
  • sinh, cosh, tanh, asinh, acosh, atanh

반올림 (Rounding)

  • ceil, floor, trunc, round, nearbyint, rint, lround, llround
  • fmod, modf
#include <cmath>
#include <numbers>

double x = std::pow(2.0, 10.0);     // 1024
double s = std::sqrt(144.0);        // 12
double e = std::exp(1.0);           // ≈ 2.718...
double t = std::atan2(1.0, 1.0);    // π/4
double c = std::ceil(2.3);          // 3
double f = std::floor(2.7);         // 2

특징

  • 대부분의 함수는 float/double/long double 오버로드와 정수 오버로드를 제공해요.
  • 오류(도메인·극·범위)는 부동 소수점 환경 플래그(FE_*)로 보고돼요.
  • 각 함수의 constexpr 지원은 버전(C++23/26)에 따라 달라져요.

<cmath>의 수학 함수들은 과학·공학·게임·그래픽 등에서 광범위하게 쓰여요. 특정 함수 하나하나는 개별 문서를 참고하면 돼요.

더 알아보기 (Learn more)

cppreference