Skip to content

Instantly share code, notes, and snippets.

@TkrUdagawa
Created April 17, 2018 07:39
Show Gist options
  • Save TkrUdagawa/885d25d8e242e39cc980abfe47d3e712 to your computer and use it in GitHub Desktop.
Save TkrUdagawa/885d25d8e242e39cc980abfe47d3e712 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <cmath>
template <typename T>
T dist(T a, T b) {
T l2_a = 0.f;
l2_a += a * a;
T l2_b = 0.f;
l2_b += b * b;
return l2_a + l2_b - 2 * a * b;
}
int main() {
double a, b;
float c, d;
a = 12.14362104;
b = 12.14078775;
c = a;
d = b;
std::cout << std::sqrt(dist(a, b)) << std::endl;
std::cout << std::sqrt(dist(c, d)) << std::endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment