Skip to content

Commit

Permalink
fix: decimal not handled with modulus (#136)
Browse files Browse the repository at this point in the history
Fix a bug where the decimals for the longitude wouldn't be considered properly for the check of bounds
  • Loading branch information
renaudjester committed Oct 28, 2024
1 parent 0cd9b5e commit f87d44b
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions copernicusmarine/download_functions/subset_xarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -554,11 +554,11 @@ def longitude_modulus(longitude: float) -> float:
Returns the equivalent longitude in [-180, 180[
"""
# We are using Decimal to avoid issue with rounding
modulus = float(Decimal(str(longitude + 180)) % 360)
modulus = (Decimal(str(longitude)) + 180) % 360
# Modulus with python return a negative value if the denominator is negative
# To counteract that, we add 360 if the result is < 0
modulus = modulus if modulus >= 0 else modulus + 360
return modulus - 180
return float(modulus - 180)


def longitude_modulus_upper_bound(longitude: float) -> float:
Expand Down

0 comments on commit f87d44b

Please sign in to comment.