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

cyclus_large constant #1746

Open
bennibbelink opened this issue May 8, 2024 · 6 comments · May be fixed by #1757
Open

cyclus_large constant #1746

bennibbelink opened this issue May 8, 2024 · 6 comments · May be fixed by #1757
Assignees

Comments

@bennibbelink
Copy link
Contributor

Many places throughout the codebase 1e299 is used to represent "a very large number". This is not best practice and I suspect it could lead to overflow errors

@bennibbelink bennibbelink self-assigned this May 8, 2024
@bennibbelink
Copy link
Contributor Author

Turns out we already have constants for this in cyc_limits.h:

/// maximum (+ or -) value for an integer variable
static const int kIntBoundLimit = std::numeric_limits<int>::max();

/// maximum (+ or -) value for a linear variable
static const double kLinBoundLimit = std::numeric_limits<double>::max();

@gonuke
Copy link
Member

gonuke commented May 8, 2024

I found those recently, too, but they seemed to be named in a way that was intended for some specific purpose. Perhaps we can revisit their naming so that it is more clear how they can/should be used.

@bennibbelink
Copy link
Contributor Author

They're not used anywhere in cyclus/cyclus or cyclus/cycamore. Based on their names it sounds like they might be intended for this specific purpose (specifying an upper/lower bound) but I agree that we could use more intuitive names. What do you think about changing them to something more generic like:

  • cy_max_int
  • cy_min_int
  • cy_max_double
  • cy_min_double

Looking at the rest of this file:

  • There are also no instances of kConstraintEps anywhere else in the code, and I'm unsure of the use case for it vs. cy_eps.
  • kModifierLimit is used only in commodity_producer.h (and a test). It is describe as maximum value for a function modifier (i.e., a_i for variable x_i) in a comment, but its not clear to me whether this is how it's being used in CommodityProducer

@bennibbelink
Copy link
Contributor Author

bennibbelink commented May 15, 2024

Trying to clean up places in cyclus and cycamore where we use 1e299 and running into overflow issues in the Enrichment class when calculating enrichment parameters. It appears that by using std::numeric_limits::max() instead of 1e299 there are some calculations that push us over the edge. @gonuke do you know if 1e299 was picked arbitrarily or is it meant to be an intentional upper bound on some parameters?

Many of the places it is used in cycamore can be found here

@gonuke
Copy link
Member

gonuke commented May 15, 2024

I don't recall how we chose 1e299. Any idea how different it is from the IEEE max double?

@bennibbelink
Copy link
Contributor Author

bennibbelink commented May 15, 2024

The IEEE max double is the same as std::numeric_limits<double>::max() - roughly 1.8e+308. I will continue exploring...

@bennibbelink bennibbelink linked a pull request May 18, 2024 that will close this issue
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: In Progress
Development

Successfully merging a pull request may close this issue.

2 participants