Skip to content

Commit b6fc85a

Browse files
committed
Add Knot and NauticalMile
1 parent e994d9d commit b6fc85a

3 files changed

Lines changed: 48 additions & 20 deletions

File tree

LanguageExt.Core/Units of Measure/Length.cs

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -129,19 +129,20 @@ public Length Min(Length rhs) =>
129129
public Length Max(Length rhs) =>
130130
new (Math.Max(Value, rhs.Value));
131131

132-
public double Miles => Value * 6.2137119223484848484848484848485e-4;
133-
public double Yards => Value * 1.0936132983333333333333333333333;
134-
public double Feet => Value * 3.280839895;
135-
public double Inches => Value * 39.37007874;
136-
public double Kilometres => Value / 1000.0;
137-
public double Hectometres => Value / 100.0;
138-
public double Decametres => Value / 10.0;
139-
public double Metres => Value;
140-
public double Centimetres => Value * 100.0;
141-
public double Millimetres => Value * 1000.0;
142-
public double Micrometres => Value * 1000000.0;
143-
public double Nanometres => Value * 1000000000.0;
144-
public double Angstroms => Value * 10000000000.0;
132+
public double Miles => Value * 6.2137119223484848484848484848485e-4;
133+
public double NauticalMiles => Value * 1852.0;
134+
public double Yards => Value * 1.0936132983333333333333333333333;
135+
public double Feet => Value * 3.280839895;
136+
public double Inches => Value * 39.37007874;
137+
public double Kilometres => Value / 1000.0;
138+
public double Hectometres => Value / 100.0;
139+
public double Decametres => Value / 10.0;
140+
public double Metres => Value;
141+
public double Centimetres => Value * 100.0;
142+
public double Millimetres => Value * 1000.0;
143+
public double Micrometres => Value * 1000000.0;
144+
public double Nanometres => Value * 1000000000.0;
145+
public double Angstroms => Value * 10000000000.0;
145146

146147
static Fin<Length> DomainType<Length, double>.From(double repr) =>
147148
new Length(repr);
@@ -164,6 +165,15 @@ public static Length Miles(this float self) =>
164165
public static Length Miles(this double self) =>
165166
new (1609.344000006437376000025749504 * self);
166167

168+
public static Length NauticalMiles(this int self) =>
169+
new (self / 1852.0);
170+
171+
public static Length NauticalMiles(this float self) =>
172+
new (self / 1852.0);
173+
174+
public static Length NauticalMiles(this double self) =>
175+
new (self / 1852.0);
176+
167177
public static Length Yards(this int self) =>
168178
new (0.9144000000036576000000146304 * self);
169179

LanguageExt.Core/Units of Measure/Module.cs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ public class UnitsOfMeasure
173173
/// Inch
174174
/// </summary>
175175
/// <example>
176-
/// Length x = 7*inch;
176+
/// Length x = 7*inches;
177177
/// </example>
178178
public static readonly Length inches = 1.Inches();
179179

@@ -189,15 +189,15 @@ public class UnitsOfMeasure
189189
/// Feet
190190
/// </summary>
191191
/// <example>
192-
/// Length x = 7*ft;
192+
/// Length x = 7*foot;
193193
/// </example>
194194
public static readonly Length foot = 1.Feet();
195195

196196
/// <summary>
197197
/// Feet
198198
/// </summary>
199199
/// <example>
200-
/// Length x = 7*ft;
200+
/// Length x = 7*feet;
201201
/// </example>
202202
public static readonly Length feet = 1.Feet();
203203

@@ -213,15 +213,15 @@ public class UnitsOfMeasure
213213
/// Yard
214214
/// </summary>
215215
/// <example>
216-
/// Length x = 7*yd;
216+
/// Length x = 7*yard;
217217
/// </example>
218218
public static readonly Length yard = 1.Yards();
219219

220220
/// <summary>
221221
/// Yard
222222
/// </summary>
223223
/// <example>
224-
/// Length x = 7*yd;
224+
/// Length x = 7*yards;
225225
/// </example>
226226
public static readonly Length yards = 1.Yards();
227227

@@ -237,10 +237,18 @@ public class UnitsOfMeasure
237237
/// Mile
238238
/// </summary>
239239
/// <example>
240-
/// Length x = 7*mile;
240+
/// Length x = 7*miles;
241241
/// </example>
242242
public static readonly Length miles = 1.Miles();
243243

244+
/// <summary>
245+
/// NauticalMile
246+
/// </summary>
247+
/// <example>
248+
/// Length x = 7*nauticalMile;
249+
/// </example>
250+
public static readonly Length nauticalMile = 1.NauticalMiles();
251+
244252
/// <summary>
245253
/// Millimetre squared
246254
/// </summary>

LanguageExt.Core/Units of Measure/Velocity.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public Velocity Divide(double rhs) =>
7575
public static VelocitySq operator *(Velocity lhs, Velocity rhs) =>
7676
new (lhs.Value * rhs.Value);
7777

78-
public static VelocitySq operator^(Velocity lhs, int power) =>
78+
public static VelocitySq operator ^(Velocity lhs, int power) =>
7979
power == 2
8080
? new VelocitySq(lhs.Value * lhs.Value)
8181
: raise<VelocitySq>(new NotSupportedException("Velocity can only be raised to the power of 2"));
@@ -133,6 +133,7 @@ public Velocity Max(Velocity rhs) =>
133133
public double KilometresPerHour => Value / 1000.0 * 3600.0;
134134
public double MilesPerSecond => Value / 1609.344000006437376000025749504;
135135
public double MilesPerHour => Value / 1609.344000006437376000025749504 * 3600.0;
136+
public double Knots => Value / 0.51444444444444;
136137
}
137138

138139
public static class UnitsVelocityExtensions
@@ -181,4 +182,13 @@ public static Velocity MilesPerHour(this float self) =>
181182

182183
public static Velocity MilesPerHour(this double self) =>
183184
new (self * 1609.344000006437376000025749504 / 3600.0);
185+
186+
public static Velocity Knots(this int self) =>
187+
new (self * 0.51444444444444);
188+
189+
public static Velocity Knots(this float self) =>
190+
new(self * 0.51444444444444);
191+
192+
public static Velocity Knots(this double self) =>
193+
new(self * 0.51444444444444);
184194
}

0 commit comments

Comments
 (0)