Convert temperature differences with the factor alone, without the scale offset [patch] - #342
Merged
Merged
Conversation
…ale offset [patch]
TemperatureDelta, TemperatureRise and TemperatureDrop hold a difference of
temperatures, but their From{Unit} factories added the Celsius/Fahrenheit
offset and In(unit) subtracted it through FromBase. A 10 °C rise was stored
as 283.15 K, and a 10 K rise read back as -263.15 °C.
The generator now leaves the offset out of every V1 scalar factory, and emits
a factor-only In(unit) for V1 forms of a dimension that has an offset unit.
Absolute temperatures (V0) are unchanged. Behaviour change for callers of the
three difference types' Celsius and Fahrenheit conversions.
Fixes #283
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015i2yeKwKRWtHhdc6NPySjW
…n eighth parameter Addresses SonarCloud S107 on AddUnitFactories. Every call site passed isDifference as the negation of applyV0Guard, so the parameter carried nothing the guard flag did not. Generated output is unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015i2yeKwKRWtHhdc6NPySjW
|
This was referenced Sep 30, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Fixes #283
What was wrong
TemperatureDelta,TemperatureRiseandTemperatureDropstore a difference of temperatures. But theirFrom{Unit}factories added the Celsius and Fahrenheit offsets, andIn(unit)went throughFromBase, which subtracts them:TemperatureDelta<double>.FromCelsius(10).ValueTemperatureRise<double>.FromFahrenheit(18).ValueTemperatureDelta<double>.FromKelvin(10).In(Celsius)Change
QuantitiesGenerator.BuildToBaseExpressiontakes anapplyOffsetflag.AddUnitFactoriespassesfalsefor difference forms (V1 bases and V1 overloads).AddDimensionAndInMembersemitsValue / unit.ToBaseFactorAs<T>()for a V1 form of a dimension that has an offset unit. Every other form keepsunit.FromBase(Value).TemperatureDelta.g.cs,TemperatureRise.g.csandTemperatureDrop.g.cs. AbsoluteTemperature(V0) is unchanged.docs/physics-generator.mdused to say "the offset is correct for a V0 or V1". Both now say only V0 applies it.Behaviour change: anyone calling the Celsius or Fahrenheit conversions on the three difference types gets different values after this PR, and those values are now correct.
Tests
StorageConversionTests<T>.TemperatureDifferencesLeaveOutTheScaleOffset. It covers Delta, Rise and Drop, and runs overdouble,decimalandPreciseNumber.Expected 10 … got 283.15). With the fix it passes.Semantics.Testsuite on Linux: 1363 passed, 0 failed, 8 skipped (Windows-only path tests).🤖 Generated with Claude Code
https://claude.ai/code/session_015i2yeKwKRWtHhdc6NPySjW
Generated by Claude Code