Skip to content

Quantity: dunder methods #5

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

Closed
lucascolley opened this issue Feb 7, 2025 · 3 comments · Fixed by #8
Closed

Quantity: dunder methods #5

lucascolley opened this issue Feb 7, 2025 · 3 comments · Fixed by #8

Comments

@lucascolley
Copy link
Member

Initial discussion at https://github.com/quantity-dev/quantity-api/pull/1/files#r1943441155

@nstarman
Copy link
Contributor

nstarman commented Feb 9, 2025

To help the transfer, this was the Q

What are the other dunder methods we should provide?

__ne__, __lt__, __le__, __gt__, __ge__, __add__, __sub__, __mul__, __matmul__, __truediv__, __floordiv__, __mod__, __divmod__, __pow__, shifts, &, ^, |, ...

@lucascolley lucascolley changed the title Dunder methods Quantity: dunder methods Mar 12, 2025
@lucascolley lucascolley transferred this issue from quantity-dev/quantity-api Mar 12, 2025
@lucascolley lucascolley linked a pull request Mar 17, 2025 that will close this issue
@andrewgsavage
Copy link
Contributor

I'm in agreement with @mhvk https://github.com/quantity-dev/quantity-api/pull/1/files#r1943523289

Required would seem comparisons, negation/pos. (+q and -q), addition/subtraction, multiplication/division, power, and absolute value.

In a minimal API, floor division and modulo should probably be optional, as they're little used and not all that obvious, since integers have not that much meaning (conversely, if we include them, we have to define precisely what they are supposed to do [including perhaps what it means to floor divide by a unit]; we then should also include divmod and maybe round, floor, and trunc).

Shifts and bitwise operators should definitely not be required.

Anyway, is there anything wrong with doing what float has except removing things that have to do with integers like floor division, modulo, rounding, etc.? (Just to be sure, I mean remove from the required dunder methods for protocol purposes; we could list them as preferably present, though as I noted, then we have to be sure we agree on how they should be implemented too.)

@nstarman
Copy link
Contributor

nstarman commented Mar 28, 2025

Agree on the necessity of __ne__, __lt__, __le__, __gt__, __ge__, __add__, __sub__, __mul__, __matmul__, __truediv__, __pow__!

And on shifts and bitwise operators. For ArrayQuantity we can look to the set of methods defined on the Array API.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants