Skip to content

Convert temperature differences with the factor alone, without the scale offset [patch] - #342

Merged
matt-edmondson merged 2 commits into
mainfrom
fix/temperature-difference-offset
Sep 30, 2026
Merged

matt-edmondson merged 2 commits into
mainfrom
fix/temperature-difference-offset

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Fixes #283

What was wrong

TemperatureDelta, TemperatureRise and TemperatureDrop store a difference of temperatures. But their From{Unit} factories added the Celsius and Fahrenheit offsets, and In(unit) went through FromBase, which subtracts them:

Call Before After
TemperatureDelta<double>.FromCelsius(10).Value 283.15 10
TemperatureRise<double>.FromFahrenheit(18).Value 265.37 10
TemperatureDelta<double>.FromKelvin(10).In(Celsius) −263.15 10

Change

  • QuantitiesGenerator.BuildToBaseExpression takes an applyOffset flag. AddUnitFactories passes false for difference forms (V1 bases and V1 overloads).
  • AddDimensionAndInMembers emits Value / unit.ToBaseFactorAs<T>() for a V1 form of a dimension that has an offset unit. Every other form keeps unit.FromBase(Value).
  • The committed generated output changes only in TemperatureDelta.g.cs, TemperatureRise.g.cs and TemperatureDrop.g.cs. Absolute Temperature (V0) is unchanged.
  • The CLAUDE.md SEM010 note and docs/physics-generator.md used 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

  • Added StorageConversionTests<T>.TemperatureDifferencesLeaveOutTheScaleOffset. It covers Delta, Rise and Drop, and runs over double, decimal and PreciseNumber.
  • I reverted the generator and generated files and re-ran it: it fails on all three storage types (for example, Expected 10 … got 283.15). With the fix it passes.
  • Full Semantics.Test suite 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

…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
@sonarqubecloud

Copy link
Copy Markdown

@matt-edmondson
matt-edmondson merged commit 756bda4 into main Sep 30, 2026
15 checks passed
@matt-edmondson
matt-edmondson deleted the fix/temperature-difference-offset branch September 30, 2026 04:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TemperatureDelta/Rise/Drop.FromCelsius(10) is 283.15 K: the absolute-scale offset is applied to a temperature difference

2 participants