1 #pragma once // Source encoding: UTF-8 with BOM (π is a lowercase Greek "pi"). 17 #include <c/limits.hpp> 18 #include <c/stdint.hpp> 19 #include <c/stdlib.hpp> 21 #include <type_traits> 28 {
return x % 2 == 0; }
33 {
return x % 2 == 1; }
36 inline auto intdiv(
const Int a,
const Int b ) noexcept
39 const div_t r = ::div( a, b );
40 return (r.quot < 0 and r.rem != 0? r.quot - 1 : r.quot);
43 inline auto intmod(
const int a,
const int b ) noexcept
45 {
return a - b*
intdiv( a, b ); }
47 template<
class Int =
int >
52 template<
class Int =
int >
57 template<
class... Ints >
58 inline auto intmin(
const Ints... args )
59 -> std::common_type_t<Ints...>
61 static_assert( (... and std::is_integral_v<Ints> ) );
62 return std::min( {std::common_type_t<Ints...>( args )...} );
65 template<
class... Ints >
66 inline auto intmax(
const Ints... args )
67 -> std::common_type_t<Ints...>
69 static_assert( (... and std::is_integral_v<Ints> ) );
70 return std::max( {std::common_type_t<Ints...>( args )...} );
auto intmax(const Ints... args) -> std::common_type_t< Ints... >
auto intmod(const int a, const int b) noexcept -> int
A drop-in replacement for bool without implicit conversion from/to types other than bool.
CPPX_USE_CPPX(intpow, squared, cubed)
auto is_even(const Int x) -> Truth
Truth is a drop-in replacement for bool without implicit conversion from/to types other than bool.
auto intsquare(const Int x) -> Int
auto intcube(const Int x) -> Int
Macros for generating more concise and clear using statements, primarily $use_cppx and $use_std,...
auto intmin(const Ints... args) -> std::common_type_t< Ints... >
auto is_odd(const Int x) -> Truth
auto intdiv(const Int a, const Int b) noexcept -> Int