Created
February 11, 2016 05:48
-
-
Save TABETA/4b0edd8fabfc1f8f2949 to your computer and use it in GitHub Desktop.
unsigned型の引き算 ref: http://qiita.com/abedominal/items/34c11e712c88c0d66fb4
This file contains 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 <string> | |
#include <iostream> | |
#include <chrono> | |
#include <cstdint> | |
#include <cmath> | |
using namespace std; | |
void checkDiff(uint32_t l, uint32_t r, bool isLeftBigger) | |
{ | |
int a = l - r; | |
int b = r - l; | |
if (a < b && isLeftBigger) | |
{ | |
cout << a << " is smaller than " << b << endl; | |
} | |
else if (a > b && !isLeftBigger) | |
{ | |
cout << a << " is larger than " << b << endl; | |
} | |
else | |
{ | |
cout << "OK" << endl; | |
} | |
} | |
int main(int argv, char* argc[]) | |
{ | |
checkDiff(UINT_MAX, UINT_MAX - 1, true); | |
checkDiff(UINT_MAX - 1, UINT_MAX, false); | |
checkDiff(UINT_MAX, 0, true); | |
checkDiff(UINT_MAX, 1, true); | |
checkDiff(0x7FFFFFFFU, 0xFFFFFFFFU, false); | |
return 0; | |
} |
This file contains 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
OK | |
OK | |
-1 is smaller than 1 | |
-2 is smaller than 2 | |
OK | |
続行するには何かキーを押してください . . . |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment