-
Notifications
You must be signed in to change notification settings - Fork 18
Description
Bug Description
When writing new floating point numbers, MontePy reverse-engineers the formatting string in order to preserve formatting. It does not appropriately consider how much of a relative change this is.
To Reproduce
import montepy
surf = montepy.Surface("1 SO 3.0")
surf._surface_constants[0].value = 1.249
print(surf.format_for_mcnp_input((6,3,0))[0])Results in
1 SO 1.2
Describe the solution you'd like
MontePy should consider the relative difference that the user is willing to tolerate. There should be a small default number; eps=1e-5 is probably too large. MontePy should check whether the rounded number varies from the true number by more than eps. If so, it should find the maximum amount of rounding that will satisfy the threshold (i.e., determine the number of digits such that true*(1 - eps) >= rounded >= true*(1 + eps).
Describe alternatives you've considered
Alternatively, write the unrounded true number raising a LineExpansionWarning.
There are also a few ways to make the threshold user-configurable:
- Global constant that the user can change.
- Argument to all
write()andformat()functions - Setting in Formatter class: see Idea: Formatter class #103
I think option 1 should be implemented immediately as a stopgap and option 3 long-term.
Another option could be an absolute threshold.
Version
- I suspect 0.2.0 but haven't verified
Additional context
This is a critical issue.