Created
July 12, 2021 04:16
-
-
Save krshrimali/5e0beca95ad0ca0bd4f05c0edb031bba to your computer and use it in GitHub Desktop.
Check for floating inputs for remainder implementation
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 <iostream> | |
#include <cmath> | |
#include <vector> | |
int main() { | |
std::vector<std::vector<double>> samples { {-7.5, -3.}, {-7.7, 3.1}, {-5.5, 3.}, {3., -2.5}, {3., 2.}, {7.3, 2.2}, {7.5, -2.} }; | |
std::cout << "Output format: a rem b is: std::remainder, output before PR, output after PR\n"; | |
for(auto vec: samples) { | |
double a = vec[0], b = vec[1]; | |
// Before https://github.com/pytorch/pytorch/pull/37758 | |
auto out_before = a - b * static_cast<int>(std::floor(a/b)); | |
// After https://github.com/pytorch/pytorch/pull/37758 | |
auto out_after = std::fmod(a, b); | |
if ((out_after != 0) && ((b < 0) != (out_after < 0))) out_after += b; | |
std::cout << a << " rem " << b << " is: " << std::remainder(a, b) << ", " << | |
out_before << ", " << out_after << '\n'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment