Remove Scalar quantity by angularsen · Pull Request #1680 · angularsen/UnitsNet · GitHub
Skip to content

Remove Scalar quantity - #1680

Draft
angularsen wants to merge 1 commit into
masterfrom
agl-codex/remove-scalar
Draft

angularsen wants to merge 1 commit into
masterfrom
agl-codex/remove-scalar

Conversation

@angularsen

@angularsen angularsen commented Jul 17, 2026 •

Copy link
Copy Markdown
Owner

Motivation

Scalar was added in #889 for #849 as a way to wrap plain user-entered counts or values in an IQuantity shape. The historical use case was essentially "double/float/etc in an IQuantity format", not a dimensional quantity with real units.

Recent discussion in #1679 re-raised whether Scalar should exist at all. Looking at the current codebase, Scalar has not grown meaningful semantic usage: it only appears as its own generated quantity, generated number extensions, generated tests, and aggregate registration entries. It is not used by quantity relations or handwritten domain code.

Removing it avoids keeping a unitless value wrapper in the quantity model where APIs such as scalar.As(ScalarUnit.Amount) and Scalar / Scalar -> double are awkward. For callers that need plain numeric values, double/decimal/QuantityValue are clearer; for dimensionless physical relationships, existing quantities such as Ratio remain available when they are semantically appropriate.

Changes

  • Remove Common/UnitDefinitions/Scalar.json.
  • Remove generated Scalar, ScalarUnit, resource, tests, and number-extension artifacts.
  • Regenerate aggregate quantity registration and IQuantity test lists without Scalar.
  • Remove the stale Scalar entry from Common/UnitEnumValues.g.json.

Breaking change

This removes the public Scalar quantity and ScalarUnit.Amount, including factory/accessor APIs such as Scalar.FromAmount(...), .Amount, parsing/formatting APIs, and number extensions such as 2.Amount() / 2.Amount.

Marked obsolete in v5: #1681

Validation

  • rg -n "\bScalar\b" Common UnitsNet UnitsNet.Tests UnitsNet.NumberExtensions UnitsNet.NumberExtensions.Tests UnitsNet.NumberExtensions.CS14 UnitsNet.NumberExtensions.CS14.Tests
  • dotnet build UnitsNet.slnx
  • dotnet test UnitsNet.Tests --no-build
  • dotnet test UnitsNet.NumberExtensions.Tests --no-build
  • dotnet test UnitsNet.NumberExtensions.CS14.Tests --no-build

Refs #849, #1200, #1679.

@claude

claude Bot commented Jul 17, 2026

Copy link
Copy Markdown

@angularsen

Copy link
Copy Markdown
Owner Author

@Muximize @lipchev Would like a second opinion here.

Scalar is largely unused in our code base, and as discussed in #1679 (review) I don't believe Scalar is an improvement over double in the UnitsNet API for scalar results.

I'd rather move towards QuantityValue as part of #1544 if it helps improve precision beyond what double can do.

However, looking at the original motivation for adding Scalar #849, I can see some minor convenience in offering it and it may just cause more harm removing it than keeping it.

Thoughts?

@codecov

codecov Bot commented Jul 17, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96%. Comparing base (a7443cf) to head (6cd1891).
⚠️ Report is 86 commits behind head on master.

Additional details and impacted files
@@          Coverage Diff           @@
##           master   #1680   +/-   ##
======================================
  Coverage      96%     96%           
======================================
  Files         450     447    -3     
  Lines       29306   29207   -99     
======================================
- Hits        28271   28189   -82     
+ Misses       1035    1018   -17     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Muximize

Muximize commented Jul 23, 2026 •

Copy link
Copy Markdown
Contributor

I've read the motivations in #849 and I don't find them very convincing.

I have a property of type IQuantity

But if the value is not always a quantity, why was that type chosen? It looks like a design problem in that framework which was worked around by adding a misfeature to UnitsNet.

I'm in favor of removing Scalar, also to avoid confusion about whether to use it where double etc. would suffice (I guess I was a victim of that in #1679 😅).

@angularsen

Copy link
Copy Markdown
Owner Author

Thanks, yes I also lean towards removing it because it semantically isn't a quantity and adds confusion rather than value.
Also, anyone can just implement their own Scalar if actually needed.

@angularsen

Copy link
Copy Markdown
Owner Author

Another use case for Scalar: #1678

@Applesauce314

Applesauce314 commented Aug 18, 2026 •

Copy link
Copy Markdown

I use Scalar and would have issues if it disappears
i have types with a quantity column, the quantity can be any type, feet, inches, gallons, pounds, etc.
but it can also be "Each" or count.
i.e.

  • 3ft of wire - Length
  • 1 oz glue - Mass
  • 3 (EA) wire lugs - Scalar

without the scalar type, this property can no longer be a units net IQuantity as it is now, as I will have to revert to having untyped data, or reimplement the Scalar myself.

this pattern is common in Bill of Material scenarios.
i think there has been no usage of the type in unitsnet code because its a simple guy, its only purpose is like the above and it requires no modifications otherwise.

@github-actions

Copy link
Copy Markdown
Contributor

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants