Skip to content

Add set of full-precision UDL#2243

Open
esseivaju wants to merge 1 commit intoceleritas-project:developfrom
esseivaju:fp-udl
Open

Add set of full-precision UDL#2243
esseivaju wants to merge 1 commit intoceleritas-project:developfrom
esseivaju:fp-udl

Conversation

@esseivaju
Copy link
Member

@esseivaju esseivaju commented Feb 6, 2026

Following-up discussions in #2235

This update should improve the previously introduced UDL to meet the requirements stated in Constants.hh. floating-point udl will now by default perform operation in, and return real_type, avoiding accidental promotion such as in 2.5_cm * float which would previously promote to double.

For cases where we'd still like full-precision, introduce an extra set of udl with a _fp suffix returning a Constant. This setup should meet the two requirements, preventing accidental promotion, while still allowing explicit full-precision as needed with minimal boilerplate in user code.

Note that there is a small difference compared to before, where 2.5 * units::cm * runtime_float was performed in, and returned double precision regardless of CELERITAS_REAL_TYPE, now 2.5_cm * runtime_float matches real_type

@esseivaju esseivaju requested a review from sethrj February 6, 2026 22:44
@esseivaju esseivaju added core Software engineering infrastructure (corecel) minor Refactoring or minor internal changes/fixes labels Feb 6, 2026
@codecov
Copy link

codecov bot commented Feb 6, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.87%. Comparing base (599cdbc) to head (9fee262).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff            @@
##           develop    #2243    +/-   ##
=========================================
  Coverage    86.87%   86.87%            
=========================================
  Files         1331     1331            
  Lines        42102    42102            
  Branches     12951    13405   +454     
=========================================
  Hits         36578    36578            
- Misses        4319     4508   +189     
+ Partials      1205     1016   -189     
Files with missing lines Coverage Δ
src/celeritas/Units.hh 100.00% <ø> (ø)

... and 118 files with indirect coverage changes

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

@github-actions
Copy link

github-actions bot commented Feb 6, 2026

Test summary

 5 913 files   9 451 suites   18m 26s ⏱️
 2 151 tests  2 123 ✅  28 💤 0 ❌
32 338 runs  32 180 ✅ 158 💤 0 ❌

Results for commit 9fee262.

Copy link
Member

@sethrj sethrj left a comment

Choose a reason for hiding this comment

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

I think we're in danger of overcomplicating the macros: especially because fp could be "full precision" or "floating point" (more common abbreviation for fp right?)

And honestly, we should have everyone prefer Quantity and its conversions...

EXPECT_REAL_EQ(17 * units::femtometer, 17_fm);
EXPECT_REAL_EQ(Constant{2.5} * units::centimeter, 2.5_cm_fp);
EXPECT_REAL_EQ(Constant{2.5} * units::centimeter, 2.5_centimeter_fp);
EXPECT_REAL_EQ(Constant{2} * units::meter, 2_m_fp);
Copy link
Member

Choose a reason for hiding this comment

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

This should be EXPECT_EQ if fp is "full precision" right?

@sethrj
Copy link
Member

sethrj commented Feb 26, 2026

@esseivaju Any more thoughts on this one? Is there a way to simplify/un-complicate things by defining a _C to make a Constant from a literal? I think we could use a little table of use cases and desired behaviors/undesirable gotchas.

Is this correct as implemented:

CELER_REAL_TYPE expression result
double 1.2_cm double
double 3 * 1.2_cm double
float 1.2_cm double
float 3 * 1.2_cm double
float 3.1 * 1.2_cm double
float 3.1f * 1.2_cm double
either 123_cm Constant
double UniformZField{3.4_T} ok
float UniformZField{3.4_T} ok
either UniformZField{3_T} error: can't implicitly cast Constant to real_type

And if we returned Constant:

CELER_REAL_TYPE expression result type
either 1.2_cm Constant
either 3 * 1.2_cm Constant
float 3.1 * 1.2_cm double
float 3.1f* 1.2_cm float
either 123_cm Constant
either UniformZField{3.4_T} error (implicit cast)
either UniformZField{3_T} error (implicit)

@esseivaju
Copy link
Member Author

Apologize for the late reply. The behavior you listed is matching what is current in develop. What I was trying to do with the PR was to follow the Constant design's goal of avoiding accidental promotions. In your table, this scenario

CELER_REAL_TYPE expression result
float 3.1f * 1.2_cm double

has unexpected promotion compared to the Constant API. I don't have a strong opinion on what would be the best behavior as I don't work on the physics part of Celeritas. So, if you want a specific behavior I'll let you choose.

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

Labels

core Software engineering infrastructure (corecel) minor Refactoring or minor internal changes/fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants