Skip to content

Commit 7e7053e

Browse files
Convert Power to double (#1195)
Fixes #1194 --------- Co-authored-by: Andreas Gullberg Larsen <[email protected]>
1 parent 1c5a0f3 commit 7e7053e

File tree

20 files changed

+341
-412
lines changed

20 files changed

+341
-412
lines changed

Common/UnitDefinitions/Power.json

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{
22
"Name": "Power",
33
"BaseUnit": "Watt",
4-
"ValueType": "decimal",
54
"XmlDocSummary": "In physics, power is the rate of doing work. It is equivalent to an amount of energy consumed per unit time.",
65
"BaseDimensions": {
76
"L": 2,
@@ -30,8 +29,8 @@
3029
{
3130
"SingularName": "MechanicalHorsepower",
3231
"PluralName": "MechanicalHorsepower",
33-
"FromUnitToBaseFunc": "{x} * 745.69m",
34-
"FromBaseToUnitFunc": "{x} / 745.69m",
32+
"FromUnitToBaseFunc": "{x} * 745.69",
33+
"FromBaseToUnitFunc": "{x} / 745.69",
3534
"Localization": [
3635
{
3736
"Culture": "en-US",
@@ -42,8 +41,8 @@
4241
{
4342
"SingularName": "MetricHorsepower",
4443
"PluralName": "MetricHorsepower",
45-
"FromUnitToBaseFunc": "{x} * 735.49875m",
46-
"FromBaseToUnitFunc": "{x} / 735.49875m",
44+
"FromUnitToBaseFunc": "{x} * 735.49875",
45+
"FromBaseToUnitFunc": "{x} / 735.49875",
4746
"Localization": [
4847
{
4948
"Culture": "en-US",
@@ -54,8 +53,8 @@
5453
{
5554
"SingularName": "ElectricalHorsepower",
5655
"PluralName": "ElectricalHorsepower",
57-
"FromUnitToBaseFunc": "{x} * 746m",
58-
"FromBaseToUnitFunc": "{x} / 746m",
56+
"FromUnitToBaseFunc": "{x} * 746",
57+
"FromBaseToUnitFunc": "{x} / 746",
5958
"Localization": [
6059
{
6160
"Culture": "en-US",
@@ -66,8 +65,8 @@
6665
{
6766
"SingularName": "BoilerHorsepower",
6867
"PluralName": "BoilerHorsepower",
69-
"FromUnitToBaseFunc": "{x} * 9812.5m",
70-
"FromBaseToUnitFunc": "{x} / 9812.5m",
68+
"FromUnitToBaseFunc": "{x} * 9812.5",
69+
"FromBaseToUnitFunc": "{x} / 9812.5",
7170
"Localization": [
7271
{
7372
"Culture": "en-US",
@@ -78,8 +77,8 @@
7877
{
7978
"SingularName": "HydraulicHorsepower",
8079
"PluralName": "HydraulicHorsepower",
81-
"FromUnitToBaseFunc": "{x} * 745.69988145m",
82-
"FromBaseToUnitFunc": "{x} / 745.69988145m",
80+
"FromUnitToBaseFunc": "{x} * 745.69988145",
81+
"FromBaseToUnitFunc": "{x} / 745.69988145",
8382
"Localization": [
8483
{
8584
"Culture": "en-US",
@@ -90,8 +89,8 @@
9089
{
9190
"SingularName": "BritishThermalUnitPerHour",
9291
"PluralName": "BritishThermalUnitsPerHour",
93-
"FromUnitToBaseFunc": "{x} * 0.29307107017m",
94-
"FromBaseToUnitFunc": "{x} / 0.29307107017m",
92+
"FromUnitToBaseFunc": "{x} * 0.29307107017",
93+
"FromBaseToUnitFunc": "{x} / 0.29307107017",
9594
"Prefixes": [ "Kilo", "Mega" ],
9695
"Localization": [
9796
{
@@ -103,8 +102,8 @@
103102
{
104103
"SingularName": "JoulePerHour",
105104
"PluralName": "JoulesPerHour",
106-
"FromUnitToBaseFunc": "{x} / 3600m",
107-
"FromBaseToUnitFunc": "{x} * 3600m",
105+
"FromUnitToBaseFunc": "{x} / 3600",
106+
"FromBaseToUnitFunc": "{x} * 3600",
108107
"Prefixes": [ "Milli", "Kilo", "Mega", "Giga" ],
109108
"Localization": [
110109
{

UnitsNet.NanoFramework/GeneratedCode/Quantities/Power.g.cs

Lines changed: 28 additions & 28 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

UnitsNet.Serialization.JsonNet.Tests/UnitsNetBaseJsonConverterTest.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ public void UnitsNetBaseJsonConverter_ConvertIQuantity_works_with_double_type()
3333
[Fact]
3434
public void UnitsNetBaseJsonConverter_ConvertIQuantity_works_with_decimal_type()
3535
{
36-
var result = _sut.Test_ConvertDecimalIQuantity(Power.FromWatts(10.2365m));
36+
var result = _sut.Test_ConvertDecimalIQuantity(Information.FromBits(64m));
3737

38-
Assert.Equal("PowerUnit.Watt", result.Unit);
39-
Assert.Equal(10.2365m, result.Value);
38+
Assert.Equal("InformationUnit.Bit", result.Unit);
39+
Assert.Equal(64m, result.Value);
4040
}
4141

4242
[Fact]
@@ -54,8 +54,7 @@ public void UnitsNetBaseJsonConverter_ConvertValueUnit_works_as_expected()
5454

5555
Assert.NotNull(result);
5656
Assert.IsType<Power>(result);
57-
Assert.True(Power.FromWatts(10.2365m).Equals((Power)result, 1E-5m, ComparisonType.Absolute));
58-
57+
Assert.True(Power.FromWatts(10.2365).Equals((Power)result, 1e-5, ComparisonType.Absolute));
5958
}
6059

6160
[Fact]

UnitsNet.Serialization.JsonNet.Tests/UnitsNetIComparableJsonConverterTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public void UnitsNetIComparableJsonConverter_ReadJson_works_as_expected()
119119

120120
Assert.NotNull(result);
121121
Assert.IsType<Power>(result);
122-
Assert.Equal(120M, ((Power)result).Watts);
122+
Assert.Equal(120, ((Power)result).Watts);
123123
}
124124
}
125125
}

UnitsNet.Serialization.JsonNet.Tests/UnitsNetIQuantityJsonConverterTest.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,10 @@ public void UnitsNetIQuantityJsonConverter_WriteJson_works_with_decimal_quantity
7878
using (var stringWriter = new StringWriter(result))
7979
using(var writer = new JsonTextWriter(stringWriter))
8080
{
81-
_sut.WriteJson(writer, Power.FromWatts(value), JsonSerializer.CreateDefault());
81+
_sut.WriteJson(writer, Information.FromBits(value), JsonSerializer.CreateDefault());
8282
}
8383

84-
Assert.Equal($"{{\"Unit\":\"PowerUnit.Watt\",\"Value\":{expectedValue},\"ValueString\":\"{expectedValueString}\",\"ValueType\":\"decimal\"}}",
84+
Assert.Equal($"{{\"Unit\":\"InformationUnit.Bit\",\"Value\":{expectedValue},\"ValueString\":\"{expectedValueString}\",\"ValueType\":\"decimal\"}}",
8585
result.ToString());
8686
}
8787

@@ -135,7 +135,7 @@ public void UnitsNetIQuantityJsonConverter_ReadJson_works_as_expected()
135135

136136
Assert.NotNull(result);
137137
Assert.IsType<Power>(result);
138-
Assert.Equal(10.3654M, ((Power)result).Watts);
138+
Assert.Equal(10.3654, ((Power)result).Watts);
139139
}
140140
}
141141
}

UnitsNet.Tests/CustomCode/IQuantityTests.cs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,5 @@ public void IQuantityTUnitDecimal_AsEnum_ReturnsDecimal()
9393
IQuantity<InformationUnit, decimal> decimalQuantity = Information.FromKilobytes(1234.5);
9494
Assert.IsType<decimal>(decimalQuantity.As(InformationUnit.Byte));
9595
}
96-
97-
[Fact]
98-
public void IQuantityTUnitDecimal_AsUnitSystem_ReturnsDecimal()
99-
{
100-
IQuantity<PowerUnit, decimal> decimalQuantity = Power.FromMegawatts(1234.5);
101-
Assert.IsType<decimal>(decimalQuantity.As(UnitSystem.SI));
102-
}
10396
}
10497
}

UnitsNet.Tests/CustomCode/MassFlowTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public void TimeSpanTimesMassFlowEqualsMass()
108108
public void MassFlowDividedByBrakeSpecificFuelConsumptionEqualsPower()
109109
{
110110
Power power = MassFlow.FromTonnesPerDay(20) / BrakeSpecificFuelConsumption.FromGramsPerKiloWattHour(180.0);
111-
AssertEx.EqualTolerance(20.0m / 24.0m * 1e6m / 180.0m, power.Kilowatts, 1E-11m);
111+
AssertEx.EqualTolerance(20.0 / 24.0 * 1e6 / 180.0, power.Kilowatts, 1e-11);
112112
}
113113

114114
[Fact]

UnitsNet.Tests/CustomCode/PowerRatioTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ public void ExpectPowerConvertedCorrectly(double power, double expected)
5555
public void ExpectPowerRatioConvertedCorrectly(double powerRatio, double expected)
5656
{
5757
PowerRatio pr = PowerRatio.FromDecibelWatts(powerRatio);
58-
decimal actual = pr.ToPower().Watts;
59-
Assert.Equal((decimal)expected, actual);
58+
var actual = pr.ToPower().Watts;
59+
Assert.Equal(expected, actual);
6060
}
6161

6262
// http://www.maximintegrated.com/en/app-notes/index.mvp/id/808

UnitsNet.Tests/CustomCode/PowerTests.cs

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,57 +9,58 @@ namespace UnitsNet.Tests
99
public class PowerTests : PowerTestsBase
1010
{
1111
protected override bool SupportsSIUnitSystem => true;
12-
protected override decimal FemtowattsInOneWatt => 1e15m;
1312

14-
protected override decimal GigajoulesPerHourInOneWatt => 3600e-9m;
13+
protected override double FemtowattsInOneWatt => 1e15;
1514

16-
protected override decimal PicowattsInOneWatt => 1e12m;
15+
protected override double GigajoulesPerHourInOneWatt => 3600e-9;
1716

18-
protected override decimal NanowattsInOneWatt => 1e9m;
17+
protected override double PicowattsInOneWatt => 1e12;
1918

20-
protected override decimal MicrowattsInOneWatt => 1e6m;
19+
protected override double NanowattsInOneWatt => 1e9;
2120

22-
protected override decimal MillijoulesPerHourInOneWatt => 3600e3m;
21+
protected override double MicrowattsInOneWatt => 1e6;
2322

24-
protected override decimal MilliwattsInOneWatt => 1e3m;
23+
protected override double MillijoulesPerHourInOneWatt => 3600e3;
2524

26-
protected override decimal DeciwattsInOneWatt => 1e1m;
25+
protected override double MilliwattsInOneWatt => 1e3;
2726

28-
protected override decimal WattsInOneWatt => 1;
27+
protected override double DeciwattsInOneWatt => 1e1;
2928

30-
protected override decimal DecawattsInOneWatt => 1e-1m;
29+
protected override double WattsInOneWatt => 1;
3130

32-
protected override decimal KilojoulesPerHourInOneWatt => 3600e-3m;
31+
protected override double DecawattsInOneWatt => 1e-1;
3332

34-
protected override decimal KilowattsInOneWatt => 1e-3m;
33+
protected override double KilojoulesPerHourInOneWatt => 3600e-3;
3534

36-
protected override decimal MegajoulesPerHourInOneWatt => 3600e-6m;
35+
protected override double KilowattsInOneWatt => 1e-3;
3736

38-
protected override decimal MegawattsInOneWatt => 1e-6m;
37+
protected override double MegajoulesPerHourInOneWatt => 3600e-6;
3938

40-
protected override decimal GigawattsInOneWatt => 1e-9m;
39+
protected override double MegawattsInOneWatt => 1e-6;
4140

42-
protected override decimal TerawattsInOneWatt => 1e-12m;
41+
protected override double GigawattsInOneWatt => 1e-9;
4342

44-
protected override decimal PetawattsInOneWatt => 1e-15m;
43+
protected override double TerawattsInOneWatt => 1e-12;
4544

46-
protected override decimal JoulesPerHourInOneWatt => 3600;
45+
protected override double PetawattsInOneWatt => 1e-15;
4746

48-
protected override decimal KilobritishThermalUnitsPerHourInOneWatt => 3.412141633e-3m;
47+
protected override double JoulesPerHourInOneWatt => 3600;
4948

50-
protected override decimal BoilerHorsepowerInOneWatt => 1.0191082802547770700636942675159e-4m;
49+
protected override double KilobritishThermalUnitsPerHourInOneWatt => 3.412141633e-3;
5150

52-
protected override decimal MegabritishThermalUnitsPerHourInOneWatt => 3.412141633e-6m;
51+
protected override double BoilerHorsepowerInOneWatt => 1.0191082802547770700636942675159e-4;
5352

54-
protected override decimal BritishThermalUnitsPerHourInOneWatt => 3.412141633m;
53+
protected override double MegabritishThermalUnitsPerHourInOneWatt => 3.412141633e-6;
5554

56-
protected override decimal ElectricalHorsepowerInOneWatt => 0.00134048257372654155495978552279m;
55+
protected override double BritishThermalUnitsPerHourInOneWatt => 3.412141633;
5756

58-
protected override decimal HydraulicHorsepowerInOneWatt => 0.00134102207184949258114167291719m;
57+
protected override double ElectricalHorsepowerInOneWatt => 0.00134048257372654155495978552279;
5958

60-
protected override decimal MechanicalHorsepowerInOneWatt => 0.00134103984229371454625916935992m;
59+
protected override double HydraulicHorsepowerInOneWatt => 0.00134102207184949258114167291719;
6160

62-
protected override decimal MetricHorsepowerInOneWatt => 0.00135962161730390432342679032425m;
61+
protected override double MechanicalHorsepowerInOneWatt => 0.00134103984229371454625916935992;
62+
63+
protected override double MetricHorsepowerInOneWatt => 0.00135962161730390432342679032425;
6364

6465
[Fact]
6566
public void DurationTimesPowerEqualsEnergy()

UnitsNet.Tests/CustomCode/SpecificEnergyTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public void DoubleDividedBySpecificEnergyEqualsBrakeSpecificFuelConsumption()
7171
public void SpecificEnergyTimesMassFlowEqualsPower()
7272
{
7373
Power power = SpecificEnergy.FromJoulesPerKilogram(10.0) * MassFlow.FromKilogramsPerSecond(20.0);
74-
Assert.Equal(200m, power.Watts);
74+
Assert.Equal(200, power.Watts);
7575
}
7676

7777
[Fact]

UnitsNet.Tests/DecimalOverloadTests.cs

Lines changed: 0 additions & 24 deletions
This file was deleted.

0 commit comments

Comments
 (0)