From ad091bbe58aacbd3840989ff691952118054703f Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 13 Sep 2026 12:37:25 +0000 Subject: [PATCH 1/2] Initial plan From c191dd29bb41e5e061741dd2b0000a869dc824cf Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 13 Sep 2026 12:45:32 +0000 Subject: [PATCH 2/2] Fix boxed null-check in generated logarithmic conversions Co-authored-by: matt-edmondson <19528727+matt-edmondson@users.noreply.github.com> --- .../Cents.g.cs | 1 - .../Decibels.g.cs | 2 -- .../DirectionalityIndex.g.cs | 1 - .../PH.g.cs | 1 - .../Semitones.g.cs | 1 - .../SoundIntensityLevel.g.cs | 1 - .../SoundPowerLevel.g.cs | 1 - .../SoundPressureLevel.g.cs | 1 - .../Generators/LogarithmicScalesGenerator.cs | 1 - Semantics.Test/Quantities/QuantityValueTypeTests.cs | 2 ++ 10 files changed, 2 insertions(+), 10 deletions(-) diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.LogarithmicScalesGenerator/Cents.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.LogarithmicScalesGenerator/Cents.g.cs index 95d0c0ff..1d597af6 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.LogarithmicScalesGenerator/Cents.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.LogarithmicScalesGenerator/Cents.g.cs @@ -36,7 +36,6 @@ public readonly partial record struct Cents(T Value) : IComparable> /// A new . A linear value of zero maps to negative infinity. public static Cents FromFrequencyRatio(Ratio linear) { - ArgumentNullException.ThrowIfNull(linear); double linearValue = double.CreateChecked(linear.Value); return new(T.CreateChecked(1200.0 * Math.Log2(linearValue))); } diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.LogarithmicScalesGenerator/Decibels.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.LogarithmicScalesGenerator/Decibels.g.cs index d60a9f61..6ffaa346 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.LogarithmicScalesGenerator/Decibels.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.LogarithmicScalesGenerator/Decibels.g.cs @@ -36,7 +36,6 @@ public readonly partial record struct Decibels(T Value) : IComparableA new . A linear value of zero maps to negative infinity. public static Decibels FromGain(Gain linear) { - ArgumentNullException.ThrowIfNull(linear); double linearValue = double.CreateChecked(linear.Value); return new(T.CreateChecked(20.0 * Math.Log10(linearValue))); } @@ -58,7 +57,6 @@ public Gain ToAmplitude() /// A new . A linear value of zero maps to negative infinity. public static Decibels FromPowerRatio(Ratio linear) { - ArgumentNullException.ThrowIfNull(linear); double linearValue = double.CreateChecked(linear.Value); return new(T.CreateChecked(10.0 * Math.Log10(linearValue))); } diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.LogarithmicScalesGenerator/DirectionalityIndex.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.LogarithmicScalesGenerator/DirectionalityIndex.g.cs index 3d855bea..6c6c4890 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.LogarithmicScalesGenerator/DirectionalityIndex.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.LogarithmicScalesGenerator/DirectionalityIndex.g.cs @@ -36,7 +36,6 @@ public readonly partial record struct DirectionalityIndex(T Value) : ICompara /// A new . A linear value of zero maps to negative infinity. public static DirectionalityIndex FromIntensityRatio(Ratio linear) { - ArgumentNullException.ThrowIfNull(linear); double linearValue = double.CreateChecked(linear.Value); return new(T.CreateChecked(10.0 * Math.Log10(linearValue))); } diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.LogarithmicScalesGenerator/PH.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.LogarithmicScalesGenerator/PH.g.cs index 0222816f..98659b47 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.LogarithmicScalesGenerator/PH.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.LogarithmicScalesGenerator/PH.g.cs @@ -36,7 +36,6 @@ public readonly partial record struct PH(T Value) : IComparable> /// A new . A linear value of zero maps to negative infinity. public static PH FromHydrogenConcentration(Concentration linear) { - ArgumentNullException.ThrowIfNull(linear); double linearValue = double.CreateChecked(linear.Value); double reference = 1000.0; return new(T.CreateChecked(-1.0 * Math.Log10(linearValue / reference))); diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.LogarithmicScalesGenerator/Semitones.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.LogarithmicScalesGenerator/Semitones.g.cs index 3c137115..bc7c03ca 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.LogarithmicScalesGenerator/Semitones.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.LogarithmicScalesGenerator/Semitones.g.cs @@ -36,7 +36,6 @@ public readonly partial record struct Semitones(T Value) : IComparableA new . A linear value of zero maps to negative infinity. public static Semitones FromFrequencyRatio(Ratio linear) { - ArgumentNullException.ThrowIfNull(linear); double linearValue = double.CreateChecked(linear.Value); return new(T.CreateChecked(12.0 * Math.Log2(linearValue))); } diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.LogarithmicScalesGenerator/SoundIntensityLevel.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.LogarithmicScalesGenerator/SoundIntensityLevel.g.cs index 48c56c41..260a2a0a 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.LogarithmicScalesGenerator/SoundIntensityLevel.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.LogarithmicScalesGenerator/SoundIntensityLevel.g.cs @@ -36,7 +36,6 @@ public readonly partial record struct SoundIntensityLevel(T Value) : ICompara /// A new . A linear value of zero maps to negative infinity. public static SoundIntensityLevel FromSoundIntensity(SoundIntensity linear) { - ArgumentNullException.ThrowIfNull(linear); double linearValue = double.CreateChecked(linear.Value); double reference = PhysicalConstants.Generic.ReferenceSoundIntensity(); return new(T.CreateChecked(10.0 * Math.Log10(linearValue / reference))); diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.LogarithmicScalesGenerator/SoundPowerLevel.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.LogarithmicScalesGenerator/SoundPowerLevel.g.cs index fb45efdf..695252b2 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.LogarithmicScalesGenerator/SoundPowerLevel.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.LogarithmicScalesGenerator/SoundPowerLevel.g.cs @@ -36,7 +36,6 @@ public readonly partial record struct SoundPowerLevel(T Value) : IComparable< /// A new . A linear value of zero maps to negative infinity. public static SoundPowerLevel FromSoundPower(SoundPower linear) { - ArgumentNullException.ThrowIfNull(linear); double linearValue = double.CreateChecked(linear.Value); double reference = PhysicalConstants.Generic.ReferenceSoundPower(); return new(T.CreateChecked(10.0 * Math.Log10(linearValue / reference))); diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.LogarithmicScalesGenerator/SoundPressureLevel.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.LogarithmicScalesGenerator/SoundPressureLevel.g.cs index 92533528..0f38e163 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.LogarithmicScalesGenerator/SoundPressureLevel.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.LogarithmicScalesGenerator/SoundPressureLevel.g.cs @@ -36,7 +36,6 @@ public readonly partial record struct SoundPressureLevel(T Value) : IComparab /// A new . A linear value of zero maps to negative infinity. public static SoundPressureLevel FromSoundPressure(SoundPressure linear) { - ArgumentNullException.ThrowIfNull(linear); double linearValue = double.CreateChecked(linear.Value); double reference = PhysicalConstants.Generic.ReferenceSoundPressure(); return new(T.CreateChecked(20.0 * Math.Log10(linearValue / reference))); diff --git a/Semantics.SourceGenerators/Generators/LogarithmicScalesGenerator.cs b/Semantics.SourceGenerators/Generators/LogarithmicScalesGenerator.cs index 6cf0e9b8..83cb0ce4 100644 --- a/Semantics.SourceGenerators/Generators/LogarithmicScalesGenerator.cs +++ b/Semantics.SourceGenerators/Generators/LogarithmicScalesGenerator.cs @@ -148,7 +148,6 @@ private static void WriteConversion(CodeBlocker cb, LogarithmicScaleDefinition s cb.WriteLine($"public static {fullType} {fromName}({linear} linear)"); using (new Scope(cb)) { - cb.WriteLine("ArgumentNullException.ThrowIfNull(linear);"); cb.WriteLine("double linearValue = double.CreateChecked(linear.Value);"); if (referenceExpr != null) { diff --git a/Semantics.Test/Quantities/QuantityValueTypeTests.cs b/Semantics.Test/Quantities/QuantityValueTypeTests.cs index 9b38ca26..d03ce3cb 100644 --- a/Semantics.Test/Quantities/QuantityValueTypeTests.cs +++ b/Semantics.Test/Quantities/QuantityValueTypeTests.cs @@ -58,6 +58,7 @@ public void QuantityArithmeticDoesNotAllocate() { Length a = Length.FromMeter(3.0); Duration t = Duration.FromSecond(1.5); + Gain gain = Gain.Create(2.0); Assert.AreEqual(0L, MeasureAllocation(() => (a + a).Value), "addition allocated"); Assert.AreEqual(0L, MeasureAllocation(() => (a - a).Value), "subtraction allocated"); @@ -66,6 +67,7 @@ public void QuantityArithmeticDoesNotAllocate() Assert.AreEqual(0L, MeasureAllocation(() => Length.FromFoot(3.0).Value), "a converting factory allocated"); Assert.AreEqual(0L, MeasureAllocation(() => Length.FromMeter(3.0).In(ktsu.Semantics.Quantities.Units.Units.Foot)), "converting to a unit allocated"); Assert.AreEqual(0L, MeasureAllocation(() => (a / t).Value), "a cross-dimensional operator allocated"); + Assert.AreEqual(0L, MeasureAllocation(() => Decibels.FromGain(gain).Value), "a logarithmic conversion allocated"); } ///