Last active
December 3, 2021 19:12
-
-
Save fclairamb/0387016387c5474e06476f0a84b6ad86 to your computer and use it in GitHub Desktop.
round.cpp
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
#ifdef __SHELL__ | |
set -ex | |
if [ "$0" = "sh" ]; then | |
curl https://gist.githubusercontent.com/fclairamb/0387016387c5474e06476f0a84b6ad86/raw/round.cpp > round.cpp && \ | |
chmod a+rx round.cpp && \ | |
./round.cpp | |
exit $? | |
fi | |
BIN=test-$(arch) | |
if [ "$FLAGS" = "" ]; then | |
FLAGS="-ffast-math -ffp-contract=fast -O3" | |
fi | |
g++ $FLAGS $0 -o $BIN | |
./$BIN | |
exit $? | |
#endif | |
#include <stdio.h> | |
void example_1() { | |
printf("Example 1:\n"); | |
double x = 50178230318.0; | |
double y = 100000000000.0; | |
double ratio = x/y; | |
printf("x/y = %18.18f\n", ratio); | |
} | |
#include <cstdlib> | |
#include <iostream> | |
#include <cmath> | |
double round(double v, double digit) | |
{ | |
double pow = std::pow(10.0, digit); | |
double t = v * pow; | |
//std::cout << "t:" << t << std::endl; | |
double r = std::floor(t + 0.5); | |
//std::cout << "r:" << r << std::endl; | |
return r / pow; | |
} | |
void example_2() { | |
std::cout << "Example 2:" << std::endl; | |
std::cout << round(4.45, 1) << std::endl; | |
std::cout << round(4.55, 1) << std::endl; | |
} | |
int main(int argc, char **argv) { | |
example_1(); | |
example_2(); | |
} |
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
#!/usr/bin/env python3 | |
from shapely.geometry import LineString | |
line1 = LineString([(3726.17, -181.848), (3726.19, -181.794)]) | |
line2 = LineString([(3726.18, -181.729), (3726.25, -182.435)]) | |
point = line1.intersection(line2) | |
print(point, point.is_valid) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Run it with: