Anonymous user
Angles (geometric), normalization and conversion: Difference between revisions
Angles (geometric), normalization and conversion (view source)
Revision as of 14:04, 16 October 2020
, 3 years ago→{{header|C++}}: Boost used
(C++ entry) |
(→{{header|C++}}: Boost used) |
||
Line 404:
=={{header|C++}}==
{{libheader|Boost}}
<lang cpp>#include <functional>
#include <iostream>
#include <iomanip>
#include <math.h>
#include <sstream>
#include <vector>
#include <boost/algorithm/string.hpp>
template<typename T
T normalize(T a, double b) { return std::fmod(a,
inline double d2d(double a) { return normalize<double
inline double g2g(double a) { return normalize<double
inline double m2m(double a) { return normalize<double
inline double r2r(double a) { return
double d2g(double a) { return g2g(a * 10 / 9); }
Line 433 ⟶ 436:
void print(const std::vector<double> &values, const char *s, const char *unit, std::function<double(double)> f) {
using namespace std;
ostringstream out;
for (double i : values) {
▲ cout << fixed << i << defaultfloat << " │ " << setw(12) << unit << "| " << setw(12) << fixed << f(i);
}
auto str = out.str();
boost::algorithm::replace_all(str, ".000000", " ");
cout << str;
}
Line 476 ⟶ 480:
│ value │ unit(s) │ normalized │
├─────────────────┼─────────────┼──────────────┤
│ -2
│ -1
│ 0 │ deg | 0 │
│ 1
│ 2
│ 6.283185 │ deg | 6.283185 │
│ 16
│ 57.295780 │ deg | 57.295780 │
│ 359
│ 399
│ 6399
│ 1000000
└─────────────────┴─────────────┴──────────────┘
...
Line 493 ⟶ 497:
│ value │ unit(s) │ converted │
├─────────────────┼─────────────┼──────────────┤
│ -2
│ -1
│ 0 │ rad -> mil | 0 │
│ 1
│ 2
│ 6.283185 │ rad -> mil | 6399.999993 │
│ 16
│ 57.295780 │ rad -> mil | 761.001765 │
│ 359
│ 399
│ 6399
│ 1000000
└─────────────────┴─────────────┴──────────────┘</pre>
|