C Numeric

Curated hub for C numerics: math, complex arithmetic, floating-point environment, random number generation, bit utilities, and newer checked integer helpers.

The C numerics area covers much more than “math functions”. It includes floating-point classification and exceptions, complex arithmetic, pseudo-random number generation, bit utilities, type-generic dispatch, and newer checked integer arithmetic helpers.

Use this hub when your question is about numeric computation or numeric representation. For raw memory, strings, or time/date functions, start from Memory, String, or Chrono instead.

# Start Here

Real-valued math

Elementary functions, powers, rounding, classification, special values, and the core floating-point function families.

Complex arithmetic

Complex numbers, projections, magnitudes, trigonometric/exponential functions, and the C99 complex model.

Floating-point environment

Exception flags, rounding direction, saved environments, and the parts of C numerics that depend on the current FP execution state.

Pseudo-random number generation

The classic `rand`/`srand` surface and its limits, suitable mostly for simple or legacy code paths.

Bit utilities

C23 bit operations and endian-related helpers for low-level integer representation work.

Type-generic and checked arithmetic

Macros that dispatch across floating/complex families and the newer checked integer operations added for overflow-aware arithmetic.

# Quick Map

If you need to...Start withWhy
Compute elementary functions, powers, roots, or rounding behaviorMathThe main real-valued function families, classification macros, and floating constants live here.
Work with `double complex` and related typesComplexComplex-specific functions and constants are separate from the real-valued math surface.
Inspect or control FP exceptions and rounding modeFloating-point environmentThese APIs deal with execution-state side effects, not just numeric values.
Generate simple pseudo-random integersRandomThe C library exposes the traditional `rand`/`srand` interface here.
Use type-generic numeric macros across float/double/complex variantsType-generic math<tgmath.h> chooses the right overload-like macro expansion for you.
Write overflow-aware integer arithmetic in modern Cckd_add, ckd_sub, ckd_mulThe checked integer helpers are the direct route when arithmetic overflow must be detected rather than ignored.
Reason about bit widths, leading/trailing zeros, or endiannessBit manipulationThe newer bit utilities cover low-level representation-oriented integer tasks.

# Numeric Families

FamilyRepresentative entry pointsUse it for
Core mathsin, cos, pow, sqrt, fmaReal-valued mathematical computation, rounding, powers, logs, and transcendental functions.
Classification and special valuesfpclassify, isfinite, isnan, NAN, INFINITYDetect value categories and handle NaN/infinity-aware code paths.
Complex arithmeticcabs, creal, cimag, cpowComplex-number computation and decomposition under the C complex model.
Floating-point environmentfeclearexcept, fetestexcept, feraiseexcept, feholdexceptException flags, saved environments, and rounding/FP-state-sensitive execution.
Pseudo-random numbersrand, srand, RAND_MAXTraditional C library PRNG entry points for simple or legacy use.
Type-generic dispatchtgmathCalling the right math/complex family through macros instead of choosing the suffixed name manually.
Checked and bit-oriented integer helpersckd_add, ckd_sub, ckd_mul, stdc_leading_zerosOverflow-aware arithmetic and low-level integer representation utilities in newer C revisions.

# Common Entry Points

TaskGo hereNotes
Absolute value / magnitudeabs, fabs, cabsPick integer, real floating, or complex magnitude based on the numeric domain.
Exponentials, logs, and powersexp, log, powThese are central math-family entry points and often pair with classification/error handling.
Roots and distance-like helperssqrt, cbrt, hypotUse these instead of ad hoc formulas when precision and special cases matter.
Classify a floating-point resultfpclassify, isfinite, isnan, signbitThese are often needed around exceptional or boundary numeric cases.
Check or clear FP exceptionsfeclearexcept, fetestexceptStart here when correctness depends on FP status flags rather than only returned values.
Seed and draw from the classic PRNGsrand, randUseful mainly for compatibility and simple code; not a modern high-quality generator design.

# Standard Evolution

StandardNavigation impact
C99Major expansion: complex arithmetic, floating-point environment, type-generic math, classification macros, and many modern math facilities became part of the standard library.
C11The numeric area gained alignment with newer language features and continued to rely on the C99 math/complex/fenv core as the main navigation backbone.
C23Added newer bit helpers and checked integer arithmetic entry points, making `/c/numeric/` broader than just floating-point and complex APIs.

# Boundary Lines

This hub coversUse a different hub for
Math, complex numbers, FP environment, random numbers, checked arithmetic, and bit-oriented numeric helpers.String for text-to-number conversion and byte-string utilities, Chrono for time/date arithmetic, Language for constant-expression and conversion rules.
The C library view of numerics.C++ numerics when you need the C++ library surface instead of the C one.

# Practical Routes

I need a math function

Start from the math section when the main question is about a computation on real-valued arguments or a floating-point classification rule.

I need complex-number support

Start from the complex section when values are truly complex, not just paired real values passed through ordinary math functions.

I need FP state or exception control

Start from the floating-point environment when return values alone are not enough and FP flags or rounding mode affect correctness.