Compile-time rational arithmetic (since C++11)
From cppreference.com
C++
Feature test macros (C++20)
Concepts library (C++20)
Metaprogramming library (C++11)
Ranges library (C++20)
Filesystem library (C++17)
Concurrency support library (C++11)
Execution control library (C++26)
Metaprogramming library
Type traits
Type categories
(C++11)
(C++11)(DR*)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
Type properties
(C++11)
(C++11)
(C++11)
(C++11)
(C++14)
(C++11)
(C++17)
(C++23)
(C++11)(deprecated in C++26)
(C++11)
(C++11)
(C++11)(until C++20*)
(C++11)(deprecated in C++20)
(C++11)
(C++11)
(C++20)
(C++20)
(C++23)
Type trait constants
(C++11)(C++17)(C++11)(C++11)
Metafunctions
(C++17)
(C++17)
(C++17)
Supported operations
(C++11)(C++11)(C++11)
(C++11)(C++11)(C++11)
(C++11)(C++11)(C++11)
(C++11)(C++11)(C++11)
(C++11)(C++11)(C++11)
(C++11)(C++11)(C++11)
(C++11)(C++11)(C++11)
(C++11)
(C++17)(C++17)(C++17)(C++17)
Relationships and property queries
(C++11)
(C++11)(C++20)
(C++20)
(C++20)
(C++11)
(C++26)
(C++11)
(C++11)
(C++11)
(C++17)(C++17)(C++17)(C++17)
Type modifications
(C++11)(C++11)(C++11)
(C++11)(C++11)(C++11)
(C++11)
(C++11)
(C++11)
(C++11)(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
Type transformations
(C++11)(deprecated in C++23)
(C++11)(deprecated in C++23)
(C++11)
(C++20)
(C++11)(until C++20*)(C++17)
(C++11)
(C++11)
(C++20)
(C++11)
(C++20)
(C++11)
(C++17)
Compile-time rational arithmetic
Compile-time integer sequences
(C++14)
Compile time rational arithmetic
(C++11)
Arithmetic
(C++11)
(C++11)
(C++11)
(C++11)
Comparison
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
The class template std::ratio
and associated templates provide compile-time rational arithmetic support. Each instantiation of this template exactly represents any finite rational number.
[edit] Compile-time fractions
Defined in header
<ratio>
The following convenience typedefs that correspond to the SI ratios are provided by the standard library:
Defined in header
<ratio>
Type
Definition
- ↑ 1.0 1.1 1.2 1.3 These typedefs are only declared if std::intmax_t can represent the denominator.
- ↑ 2.0 2.1 2.2 2.3 These typedefs are only declared if std::intmax_t can represent the numerator.
[edit] Compile-time rational arithmetic
Several alias templates, that perform arithmetic operations on ratio
objects at compile-time are provided.
Defined in header
<ratio>
[edit] Compile-time rational comparison
Several class templates, that perform comparison operations on ratio
objects at compile-time are provided.
Defined in header
<ratio>
(C++11)
ratio
objects for less than or equal to at compile-time (class template) [edit]
(C++11)
ratio
objects for greater than or equal to at compile-time (class template) [edit]