Forked from dbremner/arithmetical_way_testcases.c
Last active
March 18, 2019 19:47
-
-
Save ghoomfrog/a63f67b154f97c2dc12d4679bc73519a to your computer and use it in GitHub Desktop.
Two test cases for functions in https://lobste.rs/s/e7vp0t/arithmetical_way_check_for_number
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<limits.h> | |
#include<stdio.h> | |
#include<math.h> | |
// arithmetical definition of "abs" | |
int abs(int i) { | |
return pow((i*i), 0.5); | |
} | |
int f1(int num) | |
{ | |
const int result = abs(num) - num; | |
return result; | |
} | |
int f2(int num) | |
{ | |
const int result = num - abs(num); | |
return result; | |
} | |
int main() | |
{ | |
const int test_value = INT_MIN; | |
const int result1 = f1(test_value); | |
const int result2 = f2(test_value); | |
printf("f1:%d\n", result1); | |
printf("f2:%d\n", result2); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment