Skip to content

QuantityValue implemented as a fractional number 🐲 #1544

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 38 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
3c61dd6
- QuantityValue implemented as a fractional number
lipchev Apr 13, 2025
e421a1b
adding the git-ignored files
lipchev Apr 13, 2025
53f00cd
changing the CultureInfo? parameters back to IFormatProvder?
lipchev Apr 17, 2025
e339d87
- `UnitAbbreviationsCahe` and `UnitParser`: replaced the IReadOnlyCol…
lipchev Apr 18, 2025
d3092bc
including the changes from https://github.com/angularsen/UnitsNet/pul…
lipchev Apr 19, 2025
5693259
Completed the QuantityFormatter test coverage (and some cosmetic chan…
lipchev Apr 19, 2025
b027df2
UnitKey: making the constructor internal and renaming the properties
lipchev Apr 19, 2025
e23973a
removing the QuantityFormatter overloads and re-organizing the extens…
lipchev Apr 20, 2025
fe0a4c9
- updating the implicit usings and cleanup some of the using statements
lipchev Apr 21, 2025
56b1df9
adding a few more tests
lipchev Apr 21, 2025
da9a3e9
removing some unnecessary using statements and replacing the target f…
lipchev Jul 25, 2025
345ae06
renaming the default quantity provider
lipchev Jul 25, 2025
3c84a32
removing Quantity.FromQuantityInfo
lipchev Jul 25, 2025
5907e18
avoiding the ToArray call when initializing the quantity info using a…
lipchev Jul 25, 2025
82edf5c
Merge remote-tracking branch 'upstream\master' into fractional-quanti…
lipchev Jul 25, 2025
b07cab1
Merge remote-tracking branch 'upstream\master' into fractional-quanti…
lipchev Jul 26, 2025
e27cc5b
removing the remnents of the IQuantityInfo<TUnit> interface and the u…
lipchev Jul 26, 2025
faa0c1e
removed the unit-not-found comment
lipchev Jul 26, 2025
eb22805
merging the removal of the EnumUtils (i'm keeping it for now)
lipchev Jul 26, 2025
ece337d
merging the AoT compatibility: https://github.com/angularsen/UnitsNet…
lipchev Jul 26, 2025
cdf2016
adding the missing TryGetUnitFromAbbreviation overload and the tests
lipchev Jul 26, 2025
b1130f4
merging from upstream: ✨Add more Gray units (#1568)
lipchev Jul 26, 2025
f425ebe
removed the EnumUtils and replacing the usages with the EnumHelper
lipchev Jul 26, 2025
c53e7e9
bumping the pre-release version to 6.0.0-pre017 (staying ahead of the…
lipchev Jul 26, 2025
e5664e7
merging from upstream (keeping ahead of the official nugget version: …
lipchev Jul 27, 2025
e43068f
cleanup some namespaces and other cosmetic changes
lipchev Jul 29, 2025
35619ee
merging from upstream and bumping the nugget versions (keeping ahead …
lipchev Jul 30, 2025
ffc88de
splitting the IQuantity interface definitions into separate files
lipchev Jul 30, 2025
f7118a4
- renamed IQuantityInstance to IQuantityOfType
lipchev Aug 3, 2025
192ecae
making the GenericMathExtensions class obsolete and replacing the rel…
lipchev Aug 3, 2025
75fe28c
remove the GenerateArithmetic from the Temperature.json
lipchev Aug 3, 2025
fb01d4f
- re-formatting the QuantityInfo and making the IQuantityInfo interna…
lipchev Aug 3, 2025
db8ee3e
cleanup and reformat the UnitInfo/IUnitDefinition
lipchev Aug 3, 2025
b8877e1
merging from upstream: Add prefix milli to torr unit (#1588)
lipchev Aug 3, 2025
8c31f4e
cosmetic changes
lipchev Aug 3, 2025
f94a4d0
refactored test: From_ValueAndUnit_ReturnsQuantityWithSameValueAndUnit
lipchev Aug 3, 2025
0133647
renamed the UnitsNetSetup.QuantityInfoLookup
lipchev Aug 9, 2025
338da80
Merge remote-tracking branch 'upstream\master' into fractional-quanti…
lipchev Aug 10, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 3 additions & 1 deletion Build/build-functions.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ function Start-Tests {
$projectPaths = @(
"UnitsNet.Tests\UnitsNet.Tests.csproj",
"UnitsNet.NumberExtensions.Tests\UnitsNet.NumberExtensions.Tests.csproj",
"UnitsNet.Serialization.JsonNet.Tests\UnitsNet.Serialization.JsonNet.Tests.csproj"
"UnitsNet.Serialization.JsonNet.Tests\UnitsNet.Serialization.JsonNet.Tests.csproj",
"UnitsNet.Serialization.SystemTextJson.Tests\UnitsNet.Serialization.SystemTextJson.csproj"
)

# Parent dir must exist before xunit tries to write files to it
Expand Down Expand Up @@ -102,6 +103,7 @@ function Start-PackNugets([boolean] $IncludeNanoFramework = $false) {
$projectPaths = @(
"UnitsNet\UnitsNet.csproj",
"UnitsNet.Serialization.JsonNet\UnitsNet.Serialization.JsonNet.csproj",
"UnitsNet.Serialization.SystemTextJson\UnitsNet.Serialization.SystemTextJson.csproj",
"UnitsNet.NumberExtensions\UnitsNet.NumberExtensions.csproj"
)

Expand Down
3 changes: 2 additions & 1 deletion CodeGen/CodeGen.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
Expand All @@ -10,6 +10,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Fractions" />
<PackageReference Include="Newtonsoft.Json" />
<PackageReference Include="NuGet.Protocol" />
<PackageReference Include="Serilog" />
Expand Down
2 changes: 1 addition & 1 deletion CodeGen/Generators/NanoFrameworkGen/NuspecGenerator.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using CodeGen.JsonTypes;

namespace CodeGen.Generators.NanoFrameworkGen
Expand Down
6 changes: 3 additions & 3 deletions CodeGen/Generators/UnitsNetGen/NumberExtensionsGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public static class NumberTo{_quantityName}Extensions
continue;

Writer.WL(2, $@"
/// <inheritdoc cref=""{_quantityName}.From{unit.PluralName}(double)"" />");
/// <inheritdoc cref=""{_quantityName}.From{unit.PluralName}(QuantityValue)"" />");

// Include obsolete text from the quantity per extension method, to make it visible when the class is not explicitly referenced in code.
Writer.WLIfText(2, GetObsoleteAttributeOrNull(unit.ObsoleteText ?? _quantity.ObsoleteText));
Expand All @@ -49,10 +49,10 @@ public static class NumberTo{_quantityName}Extensions
where T : notnull
#if NET7_0_OR_GREATER
, INumber<T>
=> {_quantityName}.From{unit.PluralName}(double.CreateChecked(value));
=> {_quantityName}.From{unit.PluralName}(QuantityValue.CreateChecked(value));
#else
, IConvertible
=> {_quantityName}.From{unit.PluralName}(value.ToDouble(null));
=> {_quantityName}.From{unit.PluralName}(value.ToQuantityValue());
#endif
");
}
Expand Down
514 changes: 211 additions & 303 deletions CodeGen/Generators/UnitsNetGen/QuantityGenerator.cs

Large diffs are not rendered by default.

43 changes: 32 additions & 11 deletions CodeGen/Generators/UnitsNetGen/StaticQuantityGenerator.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using CodeGen.JsonTypes;
using System.Collections.Generic;
using System.Linq;
using CodeGen.JsonTypes;

namespace CodeGen.Generators.UnitsNetGen
{
Expand Down Expand Up @@ -33,27 +35,46 @@ internal static class DefaultProvider
/// <summary>
/// All QuantityInfo instances that are present in UnitsNet by default.
/// </summary>
internal static IReadOnlyList<QuantityInfo> Quantities { get; } =
[");
internal static IReadOnlyList<QuantityInfo> Quantities => new QuantityInfo[]
{");
foreach (var quantity in _quantities)
Writer.WL($@"
{quantity.Name}.Info,");
Writer.WL(@"
];
};

internal static void RegisterUnitConversions(UnitConverter unitConverter)
/// <summary>
/// All implicit quantity conversions that exist by default.
/// </summary>
internal static readonly IReadOnlyList<QuantityConversionMapping> Conversions = new QuantityConversionMapping[]
{");
foreach (Quantity quantity in _quantities)
{
foreach (var quantityRelation in _quantities.SelectMany(quantity => quantity.Relations.Where(x => x.Operator == "inverse")).Distinct(new CumulativeRelationshipEqualityComparer()).OrderBy(relation => relation.LeftQuantity.Name))
Writer.WL($@"
{quantity.Name}.RegisterDefaultConversions(unitConverter);");
}

new (typeof({quantityRelation.LeftQuantity.Name}), typeof({quantityRelation.RightQuantity.Name})),");
Writer.WL(@"
}
};
}
}");
return Writer.ToString();
}
}

internal class CumulativeRelationshipEqualityComparer: IEqualityComparer<QuantityRelation>{
public bool Equals(QuantityRelation? x, QuantityRelation? y)
{
if (ReferenceEquals(x, y)) return true;
if (x is null) return false;
if (y is null) return false;
if (x.GetType() != y.GetType()) return false;
return
x.ResultQuantity == y.ResultQuantity && (
(x.LeftQuantity.Equals(y.LeftQuantity) && x.RightQuantity.Equals(y.RightQuantity))
|| (x.LeftQuantity.Equals(y.RightQuantity) && x.RightQuantity.Equals(y.LeftQuantity)));
}

public int GetHashCode(QuantityRelation obj)
{
return obj.LeftQuantity.GetHashCode() ^ obj.RightQuantity.GetHashCode();
}
}
}
88 changes: 56 additions & 32 deletions CodeGen/Generators/UnitsNetGen/UnitTestBaseClassGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ internal class UnitTestBaseClassGenerator : GeneratorBase
/// A dimensionless quantity has all base dimensions (L, M, T, I, Θ, N, J) equal to zero.
/// </remarks>
private readonly bool _isDimensionless;

/// <summary>
/// Stores a mapping of culture names to their corresponding unique unit abbreviations.
/// Each culture maps to a dictionary where the key is the unit abbreviation and the value is the corresponding
Expand Down Expand Up @@ -101,7 +101,7 @@ internal class UnitTestBaseClassGenerator : GeneratorBase
/// is not available for the defined unit localizations.
/// </remarks>
private const string FallbackCultureName = "en-US";

public UnitTestBaseClassGenerator(Quantity quantity)
{
_quantity = quantity;
Expand Down Expand Up @@ -263,6 +263,7 @@ public abstract partial class {_quantity.Name}TestsBase : QuantityTestsBase
Writer.WL($@"
new object[] {{ {GetUnitFullName(unit)} }},");
}

Writer.WL($@"
}};

Expand Down Expand Up @@ -339,6 +340,20 @@ public void Ctor_UnitSystem_ThrowsArgumentExceptionIfNotSupported()
Assert.Equal(quantityInfo, ((IQuantity<{_unitEnumName}>)quantity).QuantityInfo);
}}

[Fact]
public void {_quantity.Name}Info_CreateWithCustomUnitInfos()
{{
{_unitEnumName}[] expectedUnits = [{_baseUnitFullName}];

{_quantity.Name}.{_quantity.Name}Info quantityInfo = {_quantity.Name}.{_quantity.Name}Info.CreateDefault(mappings => mappings.SelectUnits(expectedUnits));

Assert.Equal(""{_quantity.Name}"", quantityInfo.Name);
Assert.Equal({_quantity.Name}.Zero, quantityInfo.Zero);
Assert.Equal({_quantity.Name}.BaseUnit, quantityInfo.BaseUnitInfo.Value);
Assert.Equal(expectedUnits, quantityInfo.Units);
Assert.Equal(expectedUnits, quantityInfo.UnitInfos.Select(x => x.Value));
}}

[Fact]
public void {_baseUnit.SingularName}To{_quantity.Name}Units()
{{
Expand Down Expand Up @@ -584,7 +599,7 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported()
}

Writer.WL($@"
public void Parse(string culture, string quantityString, {_unitEnumName} expectedUnit, double expectedValue)
public void Parse(string culture, string quantityString, {_unitEnumName} expectedUnit, decimal expectedValue)
{{
using var _ = new CultureScope(culture);
var parsed = {_quantity.Name}.Parse(quantityString);
Expand Down Expand Up @@ -629,7 +644,7 @@ public void ParseWithAmbiguousAbbreviation(string culture, string quantityString
}

Writer.WL($@"
public void TryParse(string culture, string quantityString, {_unitEnumName} expectedUnit, double expectedValue)
public void TryParse(string culture, string quantityString, {_unitEnumName} expectedUnit, decimal expectedValue)
{{
using var _ = new CultureScope(culture);
Assert.True({_quantity.Name}.TryParse(quantityString, out {_quantity.Name} parsed));
Expand Down Expand Up @@ -887,7 +902,7 @@ public void GetAbbreviationWithDefaultCulture()
}});
}}
");

Writer.WL($@"
[Theory]
[MemberData(nameof(UnitTypes))]
Expand Down Expand Up @@ -919,6 +934,7 @@ public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit({_unitEnumName}
var quantity = {_quantity.Name}.From(3.0, fromUnit);
var converted = quantity.ToUnit(unit);
Assert.Equal(converted.Unit, unit);
Assert.Equal(quantity, converted);
}});
}}

Expand All @@ -942,20 +958,22 @@ public void ToUnit_FromIQuantity_ReturnsTheExpectedIQuantity({_unitEnumName} uni
IQuantity<{_unitEnumName}> quantityToConvert = quantity;
IQuantity<{_unitEnumName}> convertedQuantity = quantityToConvert.ToUnit(unit);
Assert.Equal(unit, convertedQuantity.Unit);
Assert.Equal(expectedQuantity, convertedQuantity);
}}, () =>
{{
IQuantity quantityToConvert = quantity;
IQuantity convertedQuantity = quantityToConvert.ToUnit(unit);
Assert.Equal(unit, convertedQuantity.Unit);
Assert.Equal(expectedQuantity, convertedQuantity);
}});
}}

[Fact]
public void ConversionRoundTrip()
{{
{_quantity.Name} {baseUnitVariableName} = {_quantity.Name}.From{_baseUnit.PluralName}(1);");
{_quantity.Name} {baseUnitVariableName} = {_quantity.Name}.From{_baseUnit.PluralName}(3);");
foreach (var unit in _quantity.Units) Writer.WL($@"
AssertEx.EqualTolerance(1, {_quantity.Name}.From{unit.PluralName}({baseUnitVariableName}.{unit.PluralName}).{_baseUnit.PluralName}, {unit.PluralName}Tolerance);");
Assert.Equal(3, {_quantity.Name}.From{unit.PluralName}({baseUnitVariableName}.{unit.PluralName}).{_baseUnit.PluralName});");
Writer.WL($@"
}}
");
Expand All @@ -967,13 +985,13 @@ public void ConversionRoundTrip()
public void LogarithmicArithmeticOperators()
{{
{_quantity.Name} v = {_quantity.Name}.From{_baseUnit.PluralName}(40);
AssertEx.EqualTolerance(-40, -v.{_baseUnit.PluralName}, {unit.PluralName}Tolerance);
Assert.Equal(-40, -v.{_baseUnit.PluralName});
AssertLogarithmicAddition();
AssertLogarithmicSubtraction();
AssertEx.EqualTolerance(50, (v*10).{_baseUnit.PluralName}, {unit.PluralName}Tolerance);
AssertEx.EqualTolerance(50, (10*v).{_baseUnit.PluralName}, {unit.PluralName}Tolerance);
AssertEx.EqualTolerance(35, (v/5).{_baseUnit.PluralName}, {unit.PluralName}Tolerance);
AssertEx.EqualTolerance(35, v/{_quantity.Name}.From{_baseUnit.PluralName}(5), {unit.PluralName}Tolerance);
Assert.Equal(50, (v * 10).{_baseUnit.PluralName});
Assert.Equal(50, (10 * v).{_baseUnit.PluralName});
Assert.Equal(35, (v / 5).{_baseUnit.PluralName});
Assert.Equal(35, v / {_quantity.Name}.From{_baseUnit.PluralName}(5));
}}

protected abstract void AssertLogarithmicAddition();
Expand All @@ -988,13 +1006,13 @@ public void LogarithmicArithmeticOperators()
public void ArithmeticOperators()
{{
{_quantity.Name} v = {_quantity.Name}.From{_baseUnit.PluralName}(1);
AssertEx.EqualTolerance(-1, -v.{_baseUnit.PluralName}, {_baseUnit.PluralName}Tolerance);
AssertEx.EqualTolerance(2, ({_quantity.Name}.From{_baseUnit.PluralName}(3)-v).{_baseUnit.PluralName}, {_baseUnit.PluralName}Tolerance);
AssertEx.EqualTolerance(2, (v + v).{_baseUnit.PluralName}, {_baseUnit.PluralName}Tolerance);
AssertEx.EqualTolerance(10, (v*10).{_baseUnit.PluralName}, {_baseUnit.PluralName}Tolerance);
AssertEx.EqualTolerance(10, (10*v).{_baseUnit.PluralName}, {_baseUnit.PluralName}Tolerance);
AssertEx.EqualTolerance(2, ({_quantity.Name}.From{_baseUnit.PluralName}(10)/5).{_baseUnit.PluralName}, {_baseUnit.PluralName}Tolerance);
AssertEx.EqualTolerance(2, {_quantity.Name}.From{_baseUnit.PluralName}(10)/{_quantity.Name}.From{_baseUnit.PluralName}(5), {_baseUnit.PluralName}Tolerance);
Assert.Equal(-1, -v.{_baseUnit.PluralName});
Assert.Equal(2, ({_quantity.Name}.From{_baseUnit.PluralName}(3) - v).{_baseUnit.PluralName});
Assert.Equal(2, (v + v).{_baseUnit.PluralName});
Assert.Equal(10, (v * 10).{_baseUnit.PluralName});
Assert.Equal(10, (10 * v).{_baseUnit.PluralName});
Assert.Equal(2, ({_quantity.Name}.From{_baseUnit.PluralName}(10) / 5).{_baseUnit.PluralName});
Assert.Equal(2, {_quantity.Name}.From{_baseUnit.PluralName}(10) / {_quantity.Name}.From{_baseUnit.PluralName}(5));
}}
");
}
Expand Down Expand Up @@ -1047,13 +1065,6 @@ public void CompareToThrowsOnNull()
[Theory]
[InlineData(1, {_baseUnitFullName}, 1, {_baseUnitFullName}, true)] // Same value and unit.
[InlineData(1, {_baseUnitFullName}, 2, {_baseUnitFullName}, false)] // Different value.
[InlineData(2, {_baseUnitFullName}, 1, {_otherOrBaseUnitFullName}, false)] // Different value and unit.");
if (_baseUnit != _otherOrBaseUnit)
{
Writer.WL($@"
[InlineData(1, {_baseUnitFullName}, 1, {_otherOrBaseUnitFullName}, false)] // Different unit.");
}
Writer.WL($@"
public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, {_unitEnumName} unitA, double valueB, {_unitEnumName} unitB, bool expectEqual)
{{
var a = new {_quantity.Name}(valueA, unitA);
Expand Down Expand Up @@ -1118,8 +1129,8 @@ public void Equals_Logarithmic_WithTolerance(double firstValue, double secondVal
var quantity = {_quantity.Name}.From{_baseUnit.PluralName}(firstValue);
var otherQuantity = {_quantity.Name}.From{_baseUnit.PluralName}(secondValue);
{differenceResultType} maxTolerance = quantity > otherQuantity ? quantity - otherQuantity : otherQuantity - quantity;
var largerTolerance = maxTolerance * 1.1;
var smallerTolerance = maxTolerance / 1.1;
var largerTolerance = maxTolerance * 1.1m;
var smallerTolerance = maxTolerance / 1.1m;
Assert.True(quantity.Equals(quantity, {differenceResultType}.Zero));
Assert.True(quantity.Equals(quantity, maxTolerance));
Assert.True(quantity.Equals(otherQuantity, largerTolerance));
Expand Down Expand Up @@ -1151,8 +1162,8 @@ public void Equals_WithTolerance(double firstValue, double secondValue)
var quantity = {_quantity.Name}.From{_baseUnit.PluralName}(firstValue);
var otherQuantity = {_quantity.Name}.From{_baseUnit.PluralName}(secondValue);
{differenceResultType} maxTolerance = quantity > otherQuantity ? quantity - otherQuantity : otherQuantity - quantity;
var largerTolerance = maxTolerance * 1.1;
var smallerTolerance = maxTolerance / 1.1;
var largerTolerance = maxTolerance * 1.1m;
var smallerTolerance = maxTolerance / 1.1m;
Assert.True(quantity.Equals(quantity, {differenceResultType}.Zero));
Assert.True(quantity.Equals(quantity, maxTolerance));
Assert.True(quantity.Equals(otherQuantity, maxTolerance));
Expand Down Expand Up @@ -1193,7 +1204,7 @@ public void Equals_WithNegativeTolerance_ThrowsArgumentOutOfRangeException()
[Fact]
public void HasAtLeastOneAbbreviationSpecified()
{{
var units = Enum.GetValues<{_unitEnumName}>();
var units = EnumHelper.GetValues<{_unitEnumName}>();
foreach (var unit in units)
{{
var defaultAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit);
Expand All @@ -1206,6 +1217,18 @@ public void BaseDimensionsShouldNeverBeNull()
Assert.False({_quantity.Name}.BaseDimensions is null);
}}

[Fact]
public void Units_ReturnsTheQuantityInfoUnits()
{{
Assert.Equal({_quantity.Name}.Info.Units, {_quantity.Name}.Units);
}}

[Fact]
public void DefaultConversionFunctions_ReturnsTheDefaultUnitConverter()
{{
Assert.Equal(UnitConverter.Default, {_quantity.Name}.DefaultConversionFunctions);
}}

[Fact]
public void ToString_ReturnsValueAndUnitAbbreviationInCurrentCulture()
{{
Expand Down Expand Up @@ -1278,7 +1301,8 @@ public void ToString_NullProvider_EqualsCurrentCulture(string format)
public void GetHashCode_Equals()
{{
var quantity = {_quantity.Name}.From{_baseUnit.PluralName}(1.0);
Assert.Equal(Comparison.GetHashCode(quantity.Unit, quantity.Value), quantity.GetHashCode());
var expected = Comparison.GetHashCode(typeof({_quantity.Name}), quantity.As({_quantity.Name}.BaseUnit));
Assert.Equal(expected, quantity.GetHashCode());
}}
");

Expand Down
3 changes: 0 additions & 3 deletions CodeGen/Generators/UnitsNetGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,6 @@ private static void GenerateResourceFiles(Quantity[] quantities, string resource
$"{resourcesDirectory}/{quantity.Name}.restext" :
$"{resourcesDirectory}/{quantity.Name}.{culture}.restext";

// Ensure parent folder exists
Directory.CreateDirectory(resourcesDirectory);

using var writer = File.CreateText(fileName);

foreach(Unit unit in quantity.Units)
Expand Down
14 changes: 14 additions & 0 deletions CodeGen/Helpers/ExpressionAnalyzer/ExpressionEvaluationTerm.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Fractions;

namespace CodeGen.Helpers.ExpressionAnalyzer;

/// <summary>
/// A term of the form "P^n" where P is a term that hasn't been parsed, raised to the given power.
/// </summary>
/// <param name="Expression">The actual expression to parse</param>
/// <param name="Exponent">The exponent to use on the parsed expression (default is 1)</param>
/// <remarks>
/// Since we're tokenizing the expressions from top to bottom, the first step is parsing the exponent of the
/// expression: e.g. Math.Pow(P, 2)
/// </remarks>
public record ExpressionEvaluationTerm(string Expression, Fraction Exponent);
Loading