prc_bits.h 883 B

123456789101112131415161718192021222324252627
  1. #include "prcalc.h"
  2. _PRC_BOOL __test_negative(uint64_t val) {
  3. return (( val & 0b1000000000000000000000000000000000000000000000000000000000000000 ) == 0b1000000000000000000000000000000000000000000000000000000000000000) ;
  4. }
  5. _PRC_BOOL __test_overflow(uint64_t val1, uint64_t val2, uint64_t res, __PRC_OPERATION op) {
  6. if (op == ADD) {
  7. if ( __test_negative(val1) && __test_negative(val2) )
  8. return !__test_negative( res );
  9. else if ( (!__test_negative(val1)) && (!__test_negative(val2)) ) {
  10. return __test_negative( res ) ;
  11. }
  12. }
  13. else if (op == MUL) {
  14. if ( __test_negative(val1) && __test_negative(val2) )
  15. return !( __test_negative( res ) );
  16. else if ( (!__test_negative(val1)) && (!__test_negative(val2)) )
  17. return !( __test_negative( res ) );
  18. }
  19. return FALSE;
  20. }