Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef _USE_MATH_DEFINES
- # error "Define _USE_MATH_DEFINES in the build settings, please."
- # include <fatal-error> // Just stop the compiler here.
- #endif
- #include <math.h>
- const double pi = M_PI;
- template< auto unitfunc() -> double >
- struct Angle_
- {
- double value;
- operator double() const { return value; }
- static auto unit() -> double { return unitfunc(); }
- template< class Other_angle_type >
- auto to_() const
- -> Other_angle_type
- { return {(value / unit()) * Other_angle_type::unit()}; }
- };
- auto degrees_unit() -> double { return 180; }
- using Degrees = Angle_<degrees_unit>;
- auto radians_unit() -> double { return pi; }
- using Radians = Angle_<radians_unit>;
- #include <iomanip>
- #include <iostream>
- using std::setprecision,
- std::cout, std::endl, std::fixed;
- auto main()
- -> int
- {
- const Radians r = Degrees{ 180 }.to_<Radians>();
- cout << sin( r ) << endl;
- cout << cos( r ) << endl;
- cout << endl;
- cout << fixed << setprecision( 10 );
- cout << sin( r ) << endl;
- cout << cos( r ) << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement