Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Math functions not compatible with percent #328

Open
StefanoD opened this issue Jan 19, 2024 · 1 comment
Open

Math functions not compatible with percent #328

StefanoD opened this issue Jan 19, 2024 · 1 comment

Comments

@StefanoD
Copy link

Please include the following information in your issue:

  1. Which version of units you are using
    Branch v3.x, Commit da6dd91

  2. Which compiler exhibited the problem (including compiler version)
    GCC 11.4.0

The math function don't work for dimensionless units like percent

using units::concentration::percent;

percent<double> pct1 = 100_pct;
percent<double> pct2 = 70_pct;

percent<double> delta = fabs(pct1 - pct2); // Results into percent<double>(0.3)
percent<double> maxValue = fmax(pct1, pct2); // Results into percent<double>(1.0)
percent<double> minValue = fmin(pct1, pct2);  // Results into percent<double>(0.7)

// Following tests are failing:

EXPECT_EQ(delta, 30_pct);
EXPECT_EQ(maxValue, pct1);
EXPECT_EQ(minValue, pct2);

The problem lies in core.h where the said functions use .value() instead of .raw()

@StefanoD StefanoD changed the title Math functions not compatible with dimensionless units Math functions not compatible with percent Jan 19, 2024
@chiphogg
Copy link

Seems very highly related to #276. Although I wouldn't go so far as to call this one a duplicate, I think some of the discussion there can be helpful.

Same for this comment on #275.

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

No branches or pull requests

2 participants