18 stream <<
"Integral types are: " <<
22 stream <<
"Signed integral types are: "
25 stream <<
"Unsigned integral types are: "
28 stream <<
"Integer types are: " <<
32 stream <<
"Signed integer types are: "
35 stream <<
"Unsigned integer types are: "
39template<
typename Type>
64constexpr auto upper_bound = std::numeric_limits<Type>::max();
65 constexpr auto lower_bound = safe::limits_min<Type>;
66 constexpr auto upper_bound = safe::limits_max<Type>;
71 if(a <= upper_bound - b)
76 os <<
"overflow: a = " << a
82 else if ( a < 0 && b < 0)
84 if(lower_bound - b <= a)
89 os <<
"overflow: a = " << a
100template<
typename Type>
109template<
typename Type>
124 constexpr auto upper_bound = safe::limits_max<Type>;
127 if(a <= upper_bound - b)
132 os <<
"overflow: a = " << a
139template<
typename Type>
155 os <<
"overflow: a = " << a
162template<
typename Type>
182 if( (b == 0) || (rlt / b == a) )
189 os <<
"overflow: a = " << a
196template<
typename Type>
207 os <<
"division by zero: a = " << a
224 constexpr auto int_lower_bound = safe::limits_min<int>;
225 constexpr auto int_upper_bound = safe::limits_max<int>;
227 constexpr auto unsigned_lower_bound = safe::limits_min<unsigned>;
228 constexpr auto unsigned_upper_bound = safe::limits_max<unsigned>;
234 auto signed_add =
safe_add(signed_a, signed_b);
235 stream <<signed_a <<
" + "<< signed_b <<
" = " << signed_add <<
endl;
237 auto signed_zero = 1;
239 auto signed_div =
safe_div(signed_a, signed_zero);
240 stream <<signed_a <<
" / "<< signed_zero <<
" = " << signed_div <<
endl;
246 auto signed_mul =
safe_mul(signed_c, signed_d);
247 stream <<signed_c <<
" * "<< signed_d <<
" = " << signed_mul <<
endl;
249 }
catch(std::exception& e)
types::enable_if_integral_t< Type > safe_div(Type a, Type b)
types::enable_if_signed_integral_t< Type > safe_sub(Type a, Type b)
types::enable_if_integral_t< Type > safe_mul(Type a, Type b)
void examples_for_safe_arithmetic()
void display_integral_types()
types::enable_if_signed_integral_t< Type > safe_add(Type a, Type b)
std::string integral_type_info()
Defines safe type operation.
Type to string name conversions are defined.
hidden::enable_if_integral_t< Type, ReturnType > enable_if_integral_t
hidden::enable_if_signed_integral_t< Type, ReturnType > enable_if_signed_integral_t
hidden::enable_if_unsigned_integral_t< Type, ReturnType > enable_if_unsigned_integral_t
This type is used to manipulate type list.
Stream output operators << are implemented.
This file implements safe arithmetic.
#define Tpf_ThrowDebugException(debug_message)
Throw a debug_exception with message as argument.