You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
1001 B

  1. #include "arithmeticDivision.h"
  2. #include <stdio.h>
  3. #include <limits.h>
  4. #include <stdlib.h>
  5. int* division_integer(int dividend, int divisor) {
  6. if(divisor == 0) {
  7. return NULL;
  8. }
  9. // Overflow protection
  10. if (dividend == INT_MIN && divisor == -1) {
  11. return NULL;
  12. }
  13. int* result = malloc(sizeof(int));
  14. *result = dividend / divisor;
  15. return result;
  16. }
  17. long* division_long(long dividend, long divisor) {
  18. if(divisor == 0) {
  19. return NULL;
  20. }
  21. long* result = malloc(sizeof(long));
  22. *result = dividend / divisor;
  23. return result;
  24. }
  25. double* division_double(double dividend, double divisor) {
  26. if(divisor == 0) {
  27. return NULL;
  28. }
  29. double* result = malloc(sizeof(double ));
  30. *result = dividend / divisor;
  31. return result;
  32. }
  33. float* division_float(float dividend, float divisor) {
  34. if(divisor == 0) {
  35. return NULL;
  36. }
  37. float* result = malloc(sizeof(float));
  38. *result = dividend / divisor;
  39. return result;
  40. }