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

Modulo fails on negative numbers #1689

Closed
bededict-cumberbach opened this issue Jan 2, 2023 · 2 comments
Closed

Modulo fails on negative numbers #1689

bededict-cumberbach opened this issue Jan 2, 2023 · 2 comments

Comments

@bededict-cumberbach
Copy link

Problem:

pint returns a wrong value for modulo of a negative number.

Minimal Example:

from pint import UnitRegistry
u = UnitRegistry()

foo = -180 % 360
print(foo)
>> 180
bar = -180 * u.deg % 360
print(bar)
>> 20446.480624709635 degree

Versions:

python = 3.9.0
pint = 0.20.1

@jules-ch
Copy link
Collaborator

jules-ch commented Jan 3, 2023

You should use :

bar = -180 * u.deg % 360 * u.deg

Or use the magnitude for your operation, pint assume dimensionless as radians so it will basically be equivalent to :

-180 degree % 360 radians

@jules-ch
Copy link
Collaborator

jules-ch commented Jan 3, 2023

See #1344 (comment)

@jules-ch jules-ch closed this as completed Jan 4, 2023
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

No branches or pull requests

2 participants