Last active
June 6, 2020 20:15
-
-
Save nbougalis/30ff5e9768fe7d574f4db5a216765e26 to your computer and use it in GitHub Desktop.
std::ratio for amendments
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
// Example for comment in PR 3428: https://github.com/ripple/rippled/pull/3428 | |
#include <iostream> | |
#include <ratio> | |
constexpr int oldN = 204; | |
constexpr int oldD = 256; | |
constexpr int newN = 80; | |
constexpr int newD = 100; | |
std::ratio<oldN, oldD> const pre3396; | |
std::ratio<newN, newD> const post3396; | |
int main(int argc, char **argv) | |
{ | |
std::cout << " pre: "<< pre3396.num << " / " << pre3396.den << "\n"; | |
for (int i = 0; i < 100000; ++i) | |
{ | |
auto x = (i * oldN) / oldD; | |
auto y = (i * pre3396.num) / pre3396.den; | |
if (x != y) | |
std::cout << i << ": old=" << x << ", new=" << y << "\n"; | |
} | |
std::cout << "post: " << post3396.num << " / " << post3396.den << "\n"; | |
for (int i = 0; i < 100000; ++i) | |
{ | |
auto x = (i * newN / newD); | |
auto y = (i * post3396.num) / post3396.den; | |
if (x != y) | |
std::cout << i << ": old=" << x << ", new=" << y << "\n"; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment