Skip to content

Commit 3c97b64

Browse files
committed
Improved precision of MicroInch constant in Length. Fixed test.
1 parent 61313cc commit 3c97b64

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

Src/UnitsNet/Length.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@ namespace UnitsNet
2828
/// </summary>
2929
public struct Length : IComparable, IComparable<Length>
3030
{
31-
private const double MilsToMetersRatio = 2.54E-5;
3231
public readonly double Meters;
32+
private const double MilsToMetersRatio = 2.54E-5;
33+
private const double MicroInchToMeterRatio = 2.54E-8;
3334

3435
/// <summary>
3536
/// Enforce static methods for creation.
@@ -93,7 +94,7 @@ public double Nanometers
9394

9495
public double Microinch
9596
{
96-
get { return Meters * 39370078.7; }
97+
get { return Meters / MicroInchToMeterRatio; }
9798
}
9899

99100
public double Mil
@@ -183,7 +184,7 @@ public static Length FromNanometers(double nm)
183184

184185
public static Length FromMicroinches(double mi)
185186
{
186-
return FromMeters(mi / 39370078.7);
187+
return FromMeters(mi * MicroInchToMeterRatio);
187188
}
188189

189190
public static Length FromMils(double mils)

Tests/LengthTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public void MetersToDistanceUnits()
2525
Assert.AreEqual(1.09361, meter.Yards, Delta);
2626
Assert.AreEqual(3.28084, meter.Feet, Delta);
2727
Assert.AreEqual(39.3701, meter.Inches, Delta);
28-
Assert.AreEqual(39370078.7, meter.Microinch, Delta);
28+
Assert.AreEqual(39370078.74015748, meter.Microinch, Delta);
2929
Assert.AreEqual(39370.07874015, meter.Mil, Delta);
3030
}
3131

0 commit comments

Comments
 (0)