Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public struct Angle
- {
- internal const decimal SCALAR = 100000000000000000000000000m;
- internal const decimal BASE = 36000000000000000000000000000m;
- internal readonly decimal _numerator;
- private Angle(decimal numerator)
- {
- if (numerator % 1 > 0) throw new Exception("Precision exceeded the capabilities of Angle."); ;
- _numerator = numerator < 0 ? ((numerator + 1) % BASE + BASE - 1) : numerator % BASE;
- }
- public static implicit operator Angle(decimal degrees) =>
- new Angle(degrees * SCALAR);
- public static Angle operator +(Angle angle1, Angle angle2) =>
- new Angle(angle1._numerator + angle2._numerator);
- public static Angle operator -(Angle angle1, Angle angle2) =>
- new Angle(angle1._numerator - angle2._numerator);
- public override string ToString() =>
- (_numerator / SCALAR).ToString();
- }
- public static class AngleEx
- {
- private const decimal PI = 3.1415926535897932384626433832m;
- public static decimal Radians(this Angle @this) =>
- @this._numerator / Angle.SCALAR * PI / 180m;
- public static decimal Degrees(this Angle @this) =>
- @this._numerator / Angle.SCALAR;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement