text: /* Determine whether two signed numbers can be added without overflow,
   * either negative overflow or positive overflow.
   */
  
  #include <stdio.h>
  #include <stdbool.h>
  #include <limits.h>
  
  /* Determine whether two signed numbers can be added without overflow.
   * Returns true if it's safe.
   */
  bool is_signed_add_safe (int x, int y){
          int sum = x + y;
          bool neg_over = x <  0 && y <  0 && sum >= 0;
          bool pos_over = x >= 0 && y >= 0 && sum <  0;
          return !neg_over && !pos_over;
  }
  
  int main (void)
  {
          int x =  1;
          int y = -1;
          int min = INT_MIN;
          int max = INT_MAX;
          
          if(is_signed_add_safe(x, y))
                  printf("It is safe to sum %d and %d.\n", x, y);
          else
                  printf("Sorry: it isn't safe to sum %d and %d.\n", x, y);
  
          // Positive overflow
          if(is_signed_add_safe(x, max))
                  printf("It is safe to sum %d and %d.\n", x, max);
          else
                  printf("Sorry: it isn't safe to sum %d and %d.\n", x, max);
  
          // Negative overflow
          if(is_signed_add_safe(y, min))
                  printf("It is safe to sum %d and %d.\n", y, min);
          else
                  printf("Sorry: it isn't safe to sum %d and %d.\n", y, min);
  
          return 0;
  }
  