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

Divide function returning zero when denominator is zero #9484

Open
rcichota opened this issue Dec 1, 2024 · 1 comment · May be fixed by #9485
Open

Divide function returning zero when denominator is zero #9484

rcichota opened this issue Dec 1, 2024 · 1 comment · May be fixed by #9485
Labels

Comments

@rcichota
Copy link
Contributor

rcichota commented Dec 1, 2024

What happened?

The divide function has a test for when the denominator is zero, but it is returning zero it the test is true. This is wrong, it should be expected to return an error or infinity. To avoid crashes, the function could return the maximum value for a double (double.MaxValue). This is a much more sensible value than returning zero...

What Operating System are you on?

Windows

@par456
Copy link
Collaborator

par456 commented Dec 1, 2024

This was actually done by design to stop NaN and infinity values from cascading through apsim models which is both very hard to track down, and is normally the result of using or storing a value before it is ready to be calculated. With the DivideFunction model in particular, it's difficult to handle if the values it is acting on have been modified yet, and the default for most values is going to be a 0.

For example, if you are using DivideFunction to produce a percentage based on the leaf area for example, it needs to still be able to produce a sensible number when there are no leaves, which we found is normally a 0.

If you have a specific us case where when the denominator is 0 and the value it returns should be something other than 0, then you'd need to think about wrapping the model in further checks for handling it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Backlog
Development

Successfully merging a pull request may close this issue.

2 participants