Add error handling for NaN and invalid values in calculations: #53
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR introduces error handling for invalid and edge-case values (like NaN, zero, and negative numbers), for example those in issue #7, to improve the stability and robustness of various calculation functions in the codebase. These checks ensure that invalid calculations (such as taking the square root of a negative number or dividing by zero) are caught and result in meaningful error messages, preventing runtime failures.
Changes
Error Handling for Spherical Coordinates Calculation
get_sphCoord_axes:r2orx2y2is zero.Mass and Moment of Inertia Checks in Force and Torque Calculation:
get_weighted_forcesto ensure it is positive before performing calculations.get_weighted_torquesto check for zero or invalid values in the moment of inertia tensor before performing any calculations, preventing invalid sqrt operations.Negative Values Handling in Distance and Angle Calculations:
Frequency Calculation Safety Checks:
frequency_calculationto check for negative eigenvalues, which would have caused issues in calculating frequencies.Impact