Add set of full-precision UDL#2243
Add set of full-precision UDL#2243esseivaju wants to merge 1 commit intoceleritas-project:developfrom
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ 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
🚀 New features to boost your workflow:
|
Test summary 5 913 files 9 451 suites 18m 26s ⏱️ Results for commit 9fee262. |
sethrj
left a comment
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
This should be EXPECT_EQ if fp is "full precision" right?
|
@esseivaju Any more thoughts on this one? Is there a way to simplify/un-complicate things by defining a Is this correct as implemented:
And if we returned Constant:
|
|
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
has unexpected promotion compared to the |
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 in2.5_cm * floatwhich would previously promote to double.For cases where we'd still like full-precision, introduce an extra set of udl with a
_fpsuffix returning aConstant. 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_floatwas performed in, and returned double precision regardless ofCELERITAS_REAL_TYPE, now2.5_cm * runtime_floatmatchesreal_type