Clingo
Loading...
Searching...
No Matches
Math Functions

Additional (checked) math functions. More...

Functions

template<std::signed_integral T, std::signed_integral S>
auto CppClingo::Util::check_cast (S in) -> bool
 Check if s of type S can be casted to T without loss.
 
template<std::integral T, std::integral S>
auto CppClingo::Util::safe_cast (S in) -> T
 Cast S to T if possible.
 
template<std::signed_integral S>
auto CppClingo::Util::check_add (S a, S b) -> std::optional< S >
 Add two integers checking overflows.
 
template<std::signed_integral S>
auto CppClingo::Util::check_sub (S a, S b) -> std::optional< S >
 Subtract two integers checking overflows.
 
template<std::signed_integral S>
auto CppClingo::Util::check_neg (S a) -> std::optional< S >
 Negate an integer checking overflows.
 
template<std::signed_integral S>
auto CppClingo::Util::check_abs (S a) -> std::optional< S >
 The absolute of an integer checking overflows.
 
template<std::signed_integral S>
auto CppClingo::Util::check_mul (S a, S b) -> std::optional< S >
 Multiply two integers checking overflows.
 
template<std::signed_integral S>
auto CppClingo::Util::check_div (S a, S b) -> std::optional< S >
 Divide two integers checking overflows (truncating toward negative infinity).
 
template<std::signed_integral S>
auto CppClingo::Util::check_mod (S a, S b) -> std::optional< S >
 Modulo of two integers checking overflows (truncating toward negative infinity).
 
template<std::signed_integral S>
auto CppClingo::Util::check_pow (S a, S b) -> std::optional< S >
 Power of the given integers checking overflows.
 

Detailed Description

Additional (checked) math functions.

Function Documentation

◆ check_add()

template<std::signed_integral S>
auto CppClingo::Util::check_add ( a,
b 
) -> std::optional<S>

Add two integers checking overflows.

Fallback for the general case.

◆ check_mul()

template<std::signed_integral S>
auto CppClingo::Util::check_mul ( a,
b 
) -> std::optional<S>

Multiply two integers checking overflows.

Fallback for the general case.

◆ check_pow()

template<std::signed_integral S>
auto CppClingo::Util::check_pow ( a,
b 
) -> std::optional<S>

Power of the given integers checking overflows.

Note that a^0 = 1 for all values of a and a^b=0 whenever b is less than zero.

◆ check_sub()

template<std::signed_integral S>
auto CppClingo::Util::check_sub ( a,
b 
) -> std::optional<S>

Subtract two integers checking overflows.

Fallback for the general case.