Skip to content

Add Japanese Hydrometer Scale support with conversions and localization - #1746

Open
Nishiwaki-Takao wants to merge 1 commit into
angularsen:masterfrom
Nishiwaki-Takao:JapaneseHydrometer
Open

Nishiwaki-Takao wants to merge 1 commit into
angularsen:masterfrom
Nishiwaki-Takao:JapaneseHydrometer

Conversation

@Nishiwaki-Takao

@Nishiwaki-Takao Nishiwaki-Takao commented Oct 14, 2026 •

Copy link
Copy Markdown

Summary

This PR adds JapaneseHydrometerScale, a dimensionless quantity for Japanese hydrometer readings derived from reciprocal specific gravity.

The quantity includes:

  • Reciprocal specific gravity
  • Heavy Baumé
  • Light Baumé
  • Sake Meter Value

It also provides conversions from the scale to Ratio as specific gravity and to an equivalent Density using the density of water at 4 °C as the reference.

Definition

Let specific gravity be $SG$, and define reciprocal specific gravity as:

$$ R = \frac{1}{SG} $$

ReciprocalSpecificGravity is used as the base unit of JapaneseHydrometerScale.

Heavy Baumé

$$ ^\circ\mathrm{Bé}_{\mathrm{heavy}} = 144.3(1-R) $$

Equivalently:

$$ R = 1-\frac{^\circ\mathrm{Bé}_{\mathrm{heavy}}}{144.3} $$

Examples:

  • $SG = 1.000$, or $R = 1.000$, gives $0,^\circ\mathrm{Bé}_{\mathrm{heavy}}$
  • $SG = 1.200$, or $R \approx 0.8333333$, gives approximately $24.05,^\circ\mathrm{Bé}_{\mathrm{heavy}}$

Light Baumé

$$ ^\circ\mathrm{Bé}_{\mathrm{light}} = 144.3R-134.3 $$

Equivalently:

$$ R = \frac{^\circ\mathrm{Bé}_{\mathrm{light}}+134.3}{144.3} $$

At $R = 1$, the light Baumé value is $10,^\circ\mathrm{Bé}_{\mathrm{light}}$.

Sake Meter Value

$$ \mathrm{SMV} = 1443(R-1) $$

Equivalently:

$$ R = 1+\frac{\mathrm{SMV}}{1443} $$

At $R = 1$, the Sake Meter Value is zero.

Motivation

These scales are conventional hydrometer readings used in Japanese industrial and brewing contexts. They are not plain ratios: each scale has its own name, formula, abbreviation, parsing behavior, and localization requirements.

Representing them as a dedicated quantity provides typed conversions between the related scales while keeping their convention separate from a generic Ratio.

Design

The new quantity is named JapaneseHydrometerScale, with the following units:

  • ReciprocalSpecificGravity
  • DegreeBaumeHeavy
  • DegreeBaumeLight
  • SakeMeterValue

Reciprocal specific gravity is used as the base unit because all three scale conversions are affine functions of it.

The implementation also provides:

  • ToSpecificGravity(), returning a Ratio
  • ToDensity(), returning an equivalent Density

ToDensity() uses a water density of 999.974950 kg/m³ at 4 °C:

$$ \rho_{\mathrm{sample}}=\frac{\rho_{\mathrm{water},,4,^\circ\mathrm{C}}}{R} $$

The resulting density therefore depends on that explicit reference condition. Reciprocal specific gravity is not treated as density itself.

Implementation

  • Add the JapaneseHydrometerScale quantity definition.
  • Use ReciprocalSpecificGravity as its base unit.
  • Add heavy Baumé, light Baumé, and Sake Meter Value conversions.
  • Add English and Japanese abbreviations:
    • 1/SG
    • °Bé heavy / °Bh
    • °Bé light / °Bl
    • SMV / 日本酒度
  • Add ToSpecificGravity() and ToDensity() conversion methods.
  • Generate the quantity type, unit enum, parsing and formatting support, number extensions, localization resources, and generated tests.

Tests

The generated tests cover:

  • Conversion of one reciprocal-specific-gravity base unit to every supported scale
  • Conversion through As() and ToUnit()
  • Round trips between the base unit and each scale
  • Parsing and formatting of English and Japanese abbreviations
  • Number extension methods
  • Standard quantity operations and metadata

The custom conversion expectations verify that $R = 1$ gives:

  • Heavy Baumé: 0
  • Light Baumé: 10
  • Sake Meter Value: 0

Scope

This PR implements the Japanese hydrometer convention represented by the formulas above.

It does not attempt to provide a generic or internationally interchangeable DegreeBaume unit. Other Baumé conventions, API gravity, and Twaddell scales may use different constants or reference conditions and remain outside the scope of this change.

References

[- JIS Z 8804 : 2012 液体の密度及び比重の測定方法] (https://kikakurui.com/z8/Z8804-2012-01.html)
- Authoritative reference for the Sake Meter Value formula.

- Introduced a new quantity `JapaneseHydrometerScale` with methods for converting to density.
- Generated code for `JapaneseHydrometerScale` including unit definitions and conversion functions.
- Added localization resources for Japanese and English, including unit abbreviations.
- Defined units for `JapaneseHydrometerScale`: Degree Baumé Heavy, Degree Baumé Light, Reciprocal Specific Gravity, and Sake Meter Value.

@lipchev lipchev left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for documenting the Japanese conventions. The Baumé and Sake Meter Value formulas agree with the published references, and the focused tests passed on .NET 10 and .NET Framework 4.8. JIS Z 8804 · Japan National Tax Agency measurement method

Does this belong in the core catalog? Sake Meter Value and heavy Baumé have established uses in brewing. UnitsNet’s contributor guide favors quantities with wide use, preferably across domains, and suggests Ratio for dimensionless values. Could you explain what makes this quantity a good fit for core UnitsNet and what other applications would benefit from having it built in? UnitsNet v6 also simplifies the IQuantity interface and exposes quantity lookup, making it easier for applications to define and register their own types. Contributor criteria · Custom quantity guide · v6 interface changes · v6 quantity lookup

Issues to resolve before merging

  • Use a common scale for comparisons and define the arithmetic. Both 0 Bh > +10 SMV and +10 SMV > 0 Bh returned true. Multiplying the same reading by two also gave different results in heavy Baumé and reciprocal specific gravity. Please test both cases and define which arithmetic operations the type should expose. Comparison · Arithmetic
  • Define the valid range and density reference. A default reading produces infinite density, and some out-of-range readings produce negative density. Please define how the helpers handle those inputs and document that ToDensity() gives equivalent sample density at 15 °C using water at 4 °C as the reference. Conversion helpers
  • Accept the standard Baumé symbols. Japanese parsing rejects Bh, Béh, Bl, and Bél. Please accept these unambiguous JIS symbols and test them as literal inputs. Unit definitions · JIS Z 8804

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants