Skip to content

Add traits for distinguished 0 without Add and 1 without Mul - #383

Closed
mikwielgus wants to merge 1 commit into
rust-num:mainfrom
mikwielgus:main
Closed

Add traits for distinguished 0 without Add and 1 without Mul#383
mikwielgus wants to merge 1 commit into
rust-num:mainfrom
mikwielgus:main

Conversation

@mikwielgus

@mikwielgus mikwielgus commented Aug 19, 2026

Copy link
Copy Markdown

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 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 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 #364

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
@frozenspider

Copy link
Copy Markdown

Personally I think introducing PartialZero/PartialOne just complicates things for no real benefit.
I would prefer just dropping Add/Mul requirements on the Zero/One traits.

Comment thread src/float.rs
///
/// let inf: f32 = Float::infinity();
/// let zero: f32 = Zero::zero();
/// let zero: f32 = f32::zero();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// let zero: f32 = f32::zero();
/// let zero: f32 = PartialZero::zero();

Comment thread src/identities.rs

/// Defines an associated constant representing the additive identity element
/// for `Self`.
pub trait ConstZero: Zero {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't the same be done for ConstZero, ConstOne?

@cuviper

cuviper commented Aug 19, 2026

Copy link
Copy Markdown
Member

We have no plans for making breaking changes. Let's keep further discussion on the issue.

@cuviper cuviper closed this Aug 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Why does One require Mul?

4 participants