Repository navigation
Unit-consistent conversion functions, starting with 'to_deg' and 'from_deg' - #4829
Open
henrikt-ma wants to merge 1 commit into
Open
henrikt-ma wants to merge 1 commit into
henrikt-ma wants to merge 1 commit into
Conversation
beutlich
force-pushed
the
unit-consistent-conversions
branch
from
October 20, 2026 20:42
3e4ace3 to
26baa91
Compare
This branch has not been deployed
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.
The unit conversion functions in
Modelica.Units.Conversionsare a poor man's solution to something that should be a language responsibility. For now, we have to live with them, but all the conversion functions suffer from not being expressed with consistent use of units.While Modelica 3.7 didn't introduce operators for safe unit conversion, it did introduce implicit unit conversion for unitful literals, which allows us to solve two problems at once:
I know that some people find the simple solution hard to understand, but it would also be possible to combine old-style error-prone conversion factors with the safety of implicit conversion by the use of an assert which can be checked once at translation time:
Note that the question of how to express as 180/π is orthogonal to the idea of using constant asserts to make more people feel safe.
Personally, I'd prefer to not express this sort of lack of faith in the unit machineries, but it's a perfect topic for a MAP-LIB discussion.
I suggest that we concentrate on
to_degandfrom_degin this PR, and then do the other unit conversion functions similarly in a follow-up PR once the design pattern is clear.