Add traits for distinguished 0 without Add and 1 without Mul - #383
Closed
mikwielgus wants to merge 1 commit into
Closed
Add traits for distinguished 0 without Add and 1 without Mul#383mikwielgus wants to merge 1 commit into
Add and 1 without Mul#383mikwielgus wants to merge 1 commit into
Conversation
This commit splits out functions defined in `Zero` into a trait called `PartialZero`. `Zero` is now `PartialZero`'s supertrait with additional requirement for `Add<Output = Self>`. Same for `One` and `PartialOne`: `One` is now `PartialOne`'s supertrait with additional requirement for `Mul<Output = Self>`. This is useful because some implementations have distinct 0 and 1 elements but can't implement closed multiplication. There seems to be a considerable demand for that because issue rust-num#364 requesting that for `One` has 6 upvotes. The names `PartialZero` and `PartialOne` are in analogy to `PartialEq` and `PartialOrd`. "partial zero" and "partial one" themselves are not mathematical terms. (if you disagree with this naming choice, let me know if you have a better name!) Closes rust-num#364
|
Personally I think introducing |
fogti
reviewed
Aug 19, 2026
| /// | ||
| /// let inf: f32 = Float::infinity(); | ||
| /// let zero: f32 = Zero::zero(); | ||
| /// let zero: f32 = f32::zero(); |
There was a problem hiding this comment.
Suggested change
| /// let zero: f32 = f32::zero(); | |
| /// let zero: f32 = PartialZero::zero(); |
|
|
||
| /// Defines an associated constant representing the additive identity element | ||
| /// for `Self`. | ||
| pub trait ConstZero: Zero { |
There was a problem hiding this comment.
Shouldn't the same be done for ConstZero, ConstOne?
Member
|
We have no plans for making breaking changes. Let's keep further discussion on the issue. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This commit splits out functions defined in
Zerointo a trait calledPartialZero.Zerois nowPartialZero's supertrait with additional requirement forAdd<Output = Self>.Same for
OneandPartialOne:Oneis nowPartialOne's supertrait with additional requirement forMul<Output = Self>.This is useful because some implementations have distinguished 0 and 1 elements but can't implement closed multiplication. There seems to be a considerable demand for that because issue #364 requesting that for
Onehas 6 upvotes.The names
PartialZeroandPartialOneare in analogy toPartialEqandPartialOrd. "partial zero" and "partial one" themselves are not mathematical terms. (if you disagree with this naming choice, let me know if you have a better name!)Closes #364