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.
38 lines
783 B
38 lines
783 B
#include "arithmeticDivision.h"
|
|
#include <stdio.h>
|
|
#include <limits.h>
|
|
#include <stdlib.h>
|
|
|
|
int* division_integer(int dividend, int divisor) {
|
|
if(divisor == 0) {
|
|
return NULL;
|
|
}
|
|
// Overflow protection
|
|
if (dividend == INT_MIN && divisor == -1) {
|
|
return NULL;
|
|
}
|
|
int* result = malloc(sizeof(int));
|
|
*result = dividend / divisor;
|
|
return result;
|
|
}
|
|
|
|
long* division_long(long dividend, long divisor) {
|
|
if(divisor == 0) {
|
|
return NULL;
|
|
}
|
|
long* result = malloc(sizeof(long));
|
|
*result = dividend / divisor;
|
|
return result;
|
|
}
|
|
|
|
double* division_double(double num1, double num2) {
|
|
if(num2 == 0) {
|
|
return NULL;
|
|
}
|
|
|
|
|
|
|
|
double* result = malloc(sizeof(double ));
|
|
*result = num1 / num2;
|
|
return result;
|
|
}
|