Skip to content

Fix floating-point precision artifacts in longitude normalization - #360

Merged
mortenwh merged 1 commit into
masterfrom
issue358_float-precision
May 9, 2026
Merged

Fix floating-point precision artifacts in longitude normalization#360
mortenwh merged 1 commit into
masterfrom
issue358_float-precision

Conversation

@mortenwh

@mortenwh mortenwh commented May 9, 2026

Copy link
Copy Markdown
Collaborator

When normalizing longitudes to ±180°, float arithmetic produced representation artifacts (e.g. '41.76' → '41.75999999999999'). Fix by rounding back to the original number of decimal places.

Also handles numpy.float64 inputs by converting to str before inspecting decimal places.

Summary: closes #358

Related issue: #358

Suggested reviewer(s):

Reviewer checklist:

  • The headers of all files contain a reference to the repository license (i.e., "License: This file is part of py-mmd-tools, licensed under the Apache License 2.0 (https://www.apache.org/licenses/LICENSE-2.0)")
  • 100% test coverage of new code - meaning:
    • The overall test coverage increased or remained the same as before
    • Every function is accompanied with a test suite
    • Tests are both positive (testing that the function work as intended with valid data) and negative (testing that the function behaves as expected with invalid data, e.g., that correct exceptions are thrown)
    • Functions with optional arguments have separate tests for all options
  • Examples are supported by doctests
  • All tests are passing
  • All names (e.g., files, classes, functions, variables) are explicit
  • Documentation (as docstrings) is complete and understandable

The checklist is based on the S-ENDA conventions and definition of done (see https://s-enda-documentation.readthedocs.io/en/latest/general_conventions.html). The above points are not necessarily relevant to all contributions. In that case, please add a short explanation to help the reviewer.

When normalizing longitudes to ±180°, float arithmetic produced
representation artifacts (e.g. '41.76' → '41.75999999999999').
Fix by rounding back to the original number of decimal places.

Also handles numpy.float64 inputs by converting to str before
inspecting decimal places.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@mortenwh
mortenwh merged commit 20d0045 into master May 9, 2026
7 checks passed
@mortenwh
mortenwh deleted the issue358_float-precision branch May 9, 2026 14:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Geographic Coordinates - Precision Artifacts from Float Normalization

1 participant