Constants 1.0
Constants related to math, environment, unit ocnversion macros.
Loading...
Searching...
No Matches
Constants Library

Introduction

This library provides a collection of commonly used mathematical constants, unit-conversion macros, SI and IEC prefixes, and data-type-related constants.

The library is organized into three main categories:

  • Mathematical constants and precomputed values.
  • Unit conversion and measurement prefixes.
  • Data type limits, ranges, and floating-point precision values.

Features

The constants library provides:

  • Mathematical constants such as pi and tau.
  • Precomputed powers of Euler's number.
  • Precomputed square-root and cube-root values.
  • Integer type minimum and maximum values.
  • Floating-point range and magnitude constants.
  • Floating-point machine epsilon values.
  • Macros for unit conversions, such as:
    • Length, mass, and time
    • Frequency and period
    • Temperature
    • Angle
    • Rotational speed
  • SI decimal prefixes.
  • IEC binary prefixes.

Header Files

The library is provided through the following headers:

Mathematical Constants

The mathematical constants header provides commonly used values of pi, tau, Euler's number, square roots, and cube roots.

Examples include:

double pi = MATH_PI;
double tau = MATH_TAU;
double e = MATH_e;
double sqrt_2 = MATH_SQRT_2;
double cbrt_2 = MATH_CUBRT_2;
#define MATH_TAU
Precalculated values tau.
#define MATH_e
#define MATH_SQRT_2
Precalculated square root values from 2 to 25.
#define MATH_CUBRT_2
Precalculated cube root values from 2 to 25.
#define MATH_PI

Precomputed multiples and sub-multiples of pi are also available, together with powers of Euler's number and roots from 2 through 25.

Unit Conversion

The unit conversion header provides macros for commonly used engineering and scientific unit conversions.

Length

Examples:

double meters = IN_2_M(10.0);
double feet = M_2_FT(2.0);
double miles = M_2_MILE(1609.344);
#define IN_2_M(x)
#define M_2_MILE(x)
#define M_2_FT(x)

Mass

Examples:

double kg = LB_2_KG(10.0);
double lb = KG_2_LB(5.0);
#define KG_2_LB(x)
#define LB_2_KG(x)

Time

Examples:

double ms = SEC_2_MS(2.0);
double s = MS_2_SEC(500.0);
#define MS_2_SEC(x)
#define SEC_2_MS(x)

Frequency and Period

Examples:

double period = HZ_2_SEC(100.0);
double freq = SEC_2_HZ(0.01);
#define SEC_2_HZ(x)
#define HZ_2_SEC(x)
Frequency and period conversion macros.

Temperature

Examples:

double fahrenheit = C_2_F(25.0);
double kelvin = C_2_K(25.0);
double celsius = F_2_C(77.0);
#define C_2_F(x)
Temperature conversion macros.
#define C_2_K(x)
#define F_2_C(x)

Angle

Examples:

double radians = DEG_2_RAD(90.0);
double degrees = RAD_2_DEG(MATH_PI);
#define DEG_2_RAD(x)
#define RAD_2_DEG(x)
Angle conversion macros.

Rotational Speed

Examples:

double radps = RPM_2_RADPS(1000.0);
double rpm = RADPS_2_RPM(10.0);
#define RADPS_2_RPM(x)
#define RPM_2_RADPS(x)
Rotational speed conversion macros.

Prefixes

The library provides SI decimal prefixes ranging from QUETTA through QUECTO.

Examples:

double mega = MEGA;
double micro = MICRO;
double nano = NANO;
#define MICRO
#define MEGA
#define NANO

IEC binary prefixes are also provided:

auto kibi = KIBI;
auto mebi = MEBI;
auto gibi = GIBI;
#define MEBI
#define KIBI
IEC binary prefixes.
#define GIBI

Data Type Constants

The data type constants header provides minimum and maximum values for integer types together with floating-point range and precision constants.

Examples:

auto int_min = INT_32_MIN;
auto int_max = INT_32_MAX;
double epsilon = DOUBLE_EPSILON;
float small = FLOAT_SMALL;
#define INT_32_MAX
#define DOUBLE_EPSILON
#define INT_32_MIN
#define FLOAT_SMALL

Floating-point constants include:

  • FLOAT_MIN
  • FLOAT_MAX
  • FLOAT_MIN_POS
  • FLOAT_SMALL
  • FLOAT_BIG
  • FLOAT_EPSILON
  • DOUBLE_MIN
  • DOUBLE_MAX
  • DOUBLE_MIN_POS
  • DOUBLE_SMALL
  • DOUBLE_BIG
  • DOUBLE_EPSILON

Basic Usage

The complete constants library can be included through the main header:

#include "constants.h"
double angle = DEG_2_RAD(90.0);
double value = MATH_PI * 2.0;
double time = MS_2_SEC(100.0);
Aggregates mathematical, unit, and data type constants.

Library Organization

The library is divided into the following functional groups:

Copyright

Copyright (c) 2026 Abhinay Kumar