Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ public readonly partial record struct Cents<T>(T Value) : IComparable<Cents<T>>
/// <returns>A new <see cref="Cents{T}"/>. A linear value of zero maps to negative infinity.</returns>
public static Cents<T> FromFrequencyRatio(Ratio<T> linear)
{
ArgumentNullException.ThrowIfNull(linear);
double linearValue = double.CreateChecked(linear.Value);
return new(T.CreateChecked(1200.0 * Math.Log2(linearValue)));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ public readonly partial record struct Decibels<T>(T Value) : IComparable<Decibel
/// <returns>A new <see cref="Decibels{T}"/>. A linear value of zero maps to negative infinity.</returns>
public static Decibels<T> FromGain(Gain<T> linear)
{
ArgumentNullException.ThrowIfNull(linear);
double linearValue = double.CreateChecked(linear.Value);
return new(T.CreateChecked(20.0 * Math.Log10(linearValue)));
}
Expand All @@ -58,7 +57,6 @@ public Gain<T> ToAmplitude()
/// <returns>A new <see cref="Decibels{T}"/>. A linear value of zero maps to negative infinity.</returns>
public static Decibels<T> FromPowerRatio(Ratio<T> linear)
{
ArgumentNullException.ThrowIfNull(linear);
double linearValue = double.CreateChecked(linear.Value);
return new(T.CreateChecked(10.0 * Math.Log10(linearValue)));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ public readonly partial record struct DirectionalityIndex<T>(T Value) : ICompara
/// <returns>A new <see cref="DirectionalityIndex{T}"/>. A linear value of zero maps to negative infinity.</returns>
public static DirectionalityIndex<T> FromIntensityRatio(Ratio<T> linear)
{
ArgumentNullException.ThrowIfNull(linear);
double linearValue = double.CreateChecked(linear.Value);
return new(T.CreateChecked(10.0 * Math.Log10(linearValue)));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ public readonly partial record struct PH<T>(T Value) : IComparable<PH<T>>
/// <returns>A new <see cref="PH{T}"/>. A linear value of zero maps to negative infinity.</returns>
public static PH<T> FromHydrogenConcentration(Concentration<T> linear)
{
ArgumentNullException.ThrowIfNull(linear);
double linearValue = double.CreateChecked(linear.Value);
double reference = 1000.0;
return new(T.CreateChecked(-1.0 * Math.Log10(linearValue / reference)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ public readonly partial record struct Semitones<T>(T Value) : IComparable<Semito
/// <returns>A new <see cref="Semitones{T}"/>. A linear value of zero maps to negative infinity.</returns>
public static Semitones<T> FromFrequencyRatio(Ratio<T> linear)
{
ArgumentNullException.ThrowIfNull(linear);
double linearValue = double.CreateChecked(linear.Value);
return new(T.CreateChecked(12.0 * Math.Log2(linearValue)));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ public readonly partial record struct SoundIntensityLevel<T>(T Value) : ICompara
/// <returns>A new <see cref="SoundIntensityLevel{T}"/>. A linear value of zero maps to negative infinity.</returns>
public static SoundIntensityLevel<T> FromSoundIntensity(SoundIntensity<T> linear)
{
ArgumentNullException.ThrowIfNull(linear);
double linearValue = double.CreateChecked(linear.Value);
double reference = PhysicalConstants.Generic.ReferenceSoundIntensity<double>();
return new(T.CreateChecked(10.0 * Math.Log10(linearValue / reference)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ public readonly partial record struct SoundPowerLevel<T>(T Value) : IComparable<
/// <returns>A new <see cref="SoundPowerLevel{T}"/>. A linear value of zero maps to negative infinity.</returns>
public static SoundPowerLevel<T> FromSoundPower(SoundPower<T> linear)
{
ArgumentNullException.ThrowIfNull(linear);
double linearValue = double.CreateChecked(linear.Value);
double reference = PhysicalConstants.Generic.ReferenceSoundPower<double>();
return new(T.CreateChecked(10.0 * Math.Log10(linearValue / reference)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ public readonly partial record struct SoundPressureLevel<T>(T Value) : IComparab
/// <returns>A new <see cref="SoundPressureLevel{T}"/>. A linear value of zero maps to negative infinity.</returns>
public static SoundPressureLevel<T> FromSoundPressure(SoundPressure<T> linear)
{
ArgumentNullException.ThrowIfNull(linear);
double linearValue = double.CreateChecked(linear.Value);
double reference = PhysicalConstants.Generic.ReferenceSoundPressure<double>();
return new(T.CreateChecked(20.0 * Math.Log10(linearValue / reference)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ private static void WriteConversion(CodeBlocker cb, LogarithmicScaleDefinition s
cb.WriteLine($"public static {fullType} {fromName}({linear}<T> linear)");
using (new Scope(cb))
{
cb.WriteLine("ArgumentNullException.ThrowIfNull(linear);");
cb.WriteLine("double linearValue = double.CreateChecked(linear.Value);");
if (referenceExpr != null)
{
Expand Down
2 changes: 2 additions & 0 deletions Semantics.Test/Quantities/QuantityValueTypeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public void QuantityArithmeticDoesNotAllocate()
{
Length<double> a = Length<double>.FromMeter(3.0);
Duration<double> t = Duration<double>.FromSecond(1.5);
Gain<double> gain = Gain<double>.Create(2.0);

Assert.AreEqual(0L, MeasureAllocation(() => (a + a).Value), "addition allocated");
Assert.AreEqual(0L, MeasureAllocation(() => (a - a).Value), "subtraction allocated");
Expand All @@ -66,6 +67,7 @@ public void QuantityArithmeticDoesNotAllocate()
Assert.AreEqual(0L, MeasureAllocation(() => Length<double>.FromFoot(3.0).Value), "a converting factory allocated");
Assert.AreEqual(0L, MeasureAllocation(() => Length<double>.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<double>.FromGain(gain).Value), "a logarithmic conversion allocated");
}

/// <summary>
Expand Down
Loading