llnl / llnl/units

Power dropped in format of user defined unit

Open
#467 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C++
Stars
171
Forks
35
Avg merge
2d 5h
Merged PRs (30d)
3

Description

Given the unit `Å^2/barn^2`, `to_string` correctly formats this as `"1/am^2"`. However, when defining custom units for "Å" and "barn", `Å^2/barn^2` is rendered as `"Å/barn^2"`. That is, the square on Å is lost.

Also, `am` is now incorrectly rendered as `"1/Å/barn"`.

The custom units are defined as
```cpp
units::addUserDefinedUnit("Å", units::unit_from_string("Å", units::strict_si));
units::addUserDefinedUnit("barn", units::unit_from_string("barn", units::strict_si));
```

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the Å^2/barn^2 and am cases with the C++ example in the issue, then trace custom-unit registration and the to_string formatting path. Add a regression test for both expressions; done means the exponent on Å is preserved and am is rendered correctly after defining the custom units.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.