Skip to content

Instantly share code, notes, and snippets.

@TABETA
Created February 11, 2016 05:48
Show Gist options
  • Save TABETA/4b0edd8fabfc1f8f2949 to your computer and use it in GitHub Desktop.
Save TABETA/4b0edd8fabfc1f8f2949 to your computer and use it in GitHub Desktop.
#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;
}
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