MCPcopy Create free account
hub / github.com/dcleblanc/SafeInt / operator %

Function operator %

Archive/releases/5/SafeInt_3013p.cpp:6128–6151  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6126// Modulus
6127template < typename T, typename U, typename E >
6128SafeInt< T, E > operator %( U lhs, SafeInt< T, E > rhs )
6129{
6130 // Value of return depends on sign of lhs
6131 // This one may not be safe - bounds check in constructor
6132 // if lhs is negative and rhs is unsigned, this will throw an exception.
6133
6134 // Fast-track the simple case
6135 // same size and same sign
6136 if( sizeof(T) == sizeof(U) &&
6137 (bool)IntTraits< T >::isSigned == (bool)IntTraits< U >::isSigned )
6138 {
6139 if( rhs != 0 )
6140 {
6141 if( IntTraits< T >::isSigned && (T)rhs == -1 )
6142 return 0;
6143
6144 return SafeInt< T, E >( (T)( lhs % (T)rhs ) );
6145 }
6146
6147 E::SafeIntOnDivZero();
6148 }
6149
6150 return SafeInt< T, E >( ( SafeInt< U, E >( lhs ) % (T)rhs ) );
6151}
6152
6153// Multiplication
6154template < typename T, typename U, typename E >

Callers

nothing calls this directly

Calls 1

SafeIntOnDivZeroFunction · 0.70

Tested by

no test coverage detected