Skip to content

fix: clamp lower bound of arcsin argument in get_apparent_wind() to prevent silent NaN#171

Open
abhinavsudhik wants to merge 1 commit into52North:mainfrom
abhinavsudhik:fix/arcsin-lower-bound-clamp
Open

fix: clamp lower bound of arcsin argument in get_apparent_wind() to prevent silent NaN#171
abhinavsudhik wants to merge 1 commit into52North:mainfrom
abhinavsudhik:fix/arcsin-lower-bound-clamp

Conversation

@abhinavsudhik
Copy link
Copy Markdown

@abhinavsudhik abhinavsudhik commented Mar 11, 2026

Related Issue / Discussion:

Fixes Issue #170

Changes:

  • Modified direct_power_boat.py — added lower-bound clamp for arg_arcsin
    in get_apparent_wind() (lines 235–241)

Further Details:

Summary:

The get_apparent_wind() method computes arg_arcsin as the argument for np.arcsin(),
which requires its input to be within [-1, 1]. Due to floating-point rounding, arg_arcsin
can produce slightly below -1 (e.g. -1.0000000001).
To rectify this error , the values of arg_arcsin are clamped back to the bound.

Before: Only the upper bound (arg_arcsin > 1) was clamped. The lower bound
(arg_arcsin < -1) was unhandled, causing np.arcsin() to silently return NaN,
corrupting apparent wind angle, power, and fuel calculations.

After: A symmetric elif branch now clamps the lower bound to -1 when the
violation is within rounding tolerance (< 0.000001), consistent with the existing
upper-bound logic.

Dependencies:

No new dependencies required.

PR Checklist:

In the context of this PR, I:

  • have (already previously) filled the 52North Contributor License Agreement
    and received positive feedback on this matter
  • have filled the 52North Contributor License Agreement
    and am waiting for feedback
  • provide unit tests embedded in the WRT test framework
    (WeatherRoutingTool/tests) that allow the simple testing of the
    new/modified functionalities. All (previous and new) unit tests
    execute without new error messages.
  • ensure that the code formatter runs without errors/warnings
  • ensure that my changes follow the WRT's guidelines for contributing
    at the time of the contribution

@kdemmich kdemmich added the bug Something isn't working label Mar 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants