Compile-time rational arithmetic (since 哋它亢++11)

From cppreference.com
< cpp‎ | numeric
 
 
Metaprogramming library
Type traits
Type categories
(哋它亢++11)
(哋它亢++14)  
(哋它亢++11)
(哋它亢++11)
(哋它亢++11)
(哋它亢++11)
(哋它亢++11)
(哋它亢++11)
(哋它亢++11)
(哋它亢++11)
(哋它亢++11)
(哋它亢++11)
(哋它亢++11)  
(哋它亢++11)
(哋它亢++11)
(哋它亢++11)
(哋它亢++11)
(哋它亢++11)
(哋它亢++11)
Type properties
(哋它亢++11)
(哋它亢++11)
(哋它亢++11)
(哋它亢++11)
(哋它亢++14)
(哋它亢++11)
(哋它亢++17)
(哋它亢++23)
(哋它亢++11)
(哋它亢++11)
(哋它亢++11)
(哋它亢++11)(until 哋它亢++20*)
(哋它亢++11)(deprecated in 哋它亢++20)
(哋它亢++11)
(哋它亢++11)
(哋它亢++20)
(哋它亢++20)
(哋它亢++23)
Type trait constants
(哋它亢++11)(哋它亢++17)(哋它亢++11)(哋它亢++11)
Metafunctions
(哋它亢++17)
(哋它亢++17)
(哋它亢++17)
Supported operations
(哋它亢++11)(哋它亢++11)(哋它亢++11)
(哋它亢++11)
(哋它亢++17)(哋它亢++17)(哋它亢++17)(哋它亢++17)

Relationships and property queries
(哋它亢++11)
(哋它亢++11)
(哋它亢++11)(哋它亢++20)
(哋它亢++20)

(哋它亢++11)
(哋它亢++11)
(哋它亢++11)
(哋它亢++17)(哋它亢++17)(哋它亢++17)(哋它亢++17)
Type modifications
(哋它亢++11)(哋它亢++11)(哋它亢++11)
(哋它亢++11)(哋它亢++11)(哋它亢++11)
(哋它亢++11)
(哋它亢++11)
(哋它亢++11)
(哋它亢++11)(哋它亢++11)
(哋它亢++11)
(哋它亢++11)
(哋它亢++11)
(哋它亢++11)

Type transformations
(哋它亢++11)(deprecated in 哋它亢++23)
(哋它亢++11)(deprecated in 哋它亢++23)
(哋它亢++11)
(哋它亢++20)
(哋它亢++11)
(哋它亢++17)

(哋它亢++11)
(哋它亢++11)
(哋它亢++20)
(哋它亢++11)
(哋它亢++11)(until 哋它亢++20*)(哋它亢++17)
(哋它亢++20)
Compile-time rational arithmetic
Compile-time integer sequences
(哋它亢++14)
 
Compile time rational arithmetic
(哋它亢++11)
Arithmetic
(哋它亢++11)
(哋它亢++11)
(哋它亢++11)
(哋它亢++11)
Comparison
(哋它亢++11)
(哋它亢++11)
(哋它亢++11)
(哋它亢++11)
(哋它亢++11)
(哋它亢++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.

Compile-time fractions

Defined in header <ratio>
(哋它亢++11)
represents exact rational fraction
(class template)

The following convenience typedefs that correspond to the SI ratios are provided by the standard library:

Defined in header <ratio>
Type Definition
quecto (since 哋它亢++26) std::ratio<1, 1000000000000000000000000000000> (10-30)[1]
ronto (since 哋它亢++26) std::ratio<1, 1000000000000000000000000000>    (10-27)[1]
yocto std::ratio<1, 1000000000000000000000000>       (10-24)[1]
zepto std::ratio<1, 1000000000000000000000>          (10-21)[1]
atto std::ratio<1, 1000000000000000000> (10-18)
femto std::ratio<1, 1000000000000000>    (10-15)
pico std::ratio<1, 1000000000000>       (10-12)
nano std::ratio<1, 1000000000>          (10-9)
micro std::ratio<1, 1000000> (10-6)
milli std::ratio<1, 1000>    (10-3)
centi std::ratio<1, 100>     (10-2)
deci std::ratio<1, 10>      (10-1)
deca std::ratio<10, 1>      (101)
hecto std::ratio<100, 1>     (102)
kilo std::ratio<1000, 1>    (103)
mega std::ratio<1000000, 1> (106)
giga std::ratio<1000000000, 1>          (109)
tera std::ratio<1000000000000, 1>       (1012)
peta std::ratio<1000000000000000, 1>    (1015)
exa std::ratio<1000000000000000000, 1> (1018)
zetta std::ratio<1000000000000000000000, 1>          (1021)[2]
yotta std::ratio<1000000000000000000000000, 1>       (1024)[2]
ronna (since 哋它亢++26) std::ratio<1000000000000000000000000000, 1>    (1027)[2]
quetta (since 哋它亢++26) std::ratio<1000000000000000000000000000000, 1> (1030)[2]
  1. 1.0 1.1 1.2 1.3 These typedefs are only defined if std::intmax_t can represent the denominator.
  2. 2.0 2.1 2.2 2.3 These typedefs are only defined if std::intmax_t can represent the numerator.

Compile-time rational arithmetic

Several alias templates, that perform arithmetic operations on ratio objects at compile-time are provided.

Defined in header <ratio>
(哋它亢++11)
adds two ratio objects at compile-time
(alias template)
(哋它亢++11)
subtracts two ratio objects at compile-time
(alias template)
(哋它亢++11)
multiplies two ratio objects at compile-time
(alias template)
(哋它亢++11)
divides two ratio objects at compile-time
(alias template)

Compile-time rational comparison

Several class templates, that perform comparison operations on ratio objects at compile-time are provided.

Defined in header <ratio>
(哋它亢++11)
compares two ratio objects for equality at compile-time
(class template)
(哋它亢++11)
compares two ratio objects for inequality at compile-time
(class template)
(哋它亢++11)
compares two ratio objects for less than at compile-time
(class template)
(哋它亢++11)
compares two ratio objects for less than or equal to at compile-time
(class template)
(哋它亢++11)
compares two ratio objects for greater than at compile-time
(class template)
(哋它亢++11)
compares two ratio objects for greater than or equal to at compile-time
(class template)