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

Numeric trait #6572

Closed
olehmisar opened this issue Nov 21, 2024 · 1 comment
Closed

Numeric trait #6572

olehmisar opened this issue Nov 21, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@olehmisar
Copy link

Problem

For some generic functions, it is useful to accept any numeric value(u8, u32, u64, U128 etc). E.g.,

fn add_2<T>(x: T) -> T where T: Numeric {
    let TWO = T::one() + T::one();
    x + TWO
}

A real world use case is nodash::sqrt: https://github.com/olehmisar/nodash/blob/727116ea69261d9e91454d93af36f0851df5c35c/src/math/sqrt.nr#L5-L8

I implemented a Numeric trait inside nodash for that but it would be nice to have this trait in the Noir std lib.

https://github.com/olehmisar/nodash/blob/727116ea69261d9e91454d93af36f0851df5c35c/src/math/numeric.nr

trait Numeric {
    fn zero() -> Self;
    fn one() -> Self;
}

Happy Case

Add Numeric trait to Noir std lib. The name is not final.

Workaround

None

Workaround Description

No response

Additional Context

No response

Project Impact

Nice-to-have

Blocker Context

No response

Would you like to submit a PR for this Issue?

Maybe

Support Needs

No response

@olehmisar olehmisar added the enhancement New feature or request label Nov 21, 2024
@github-project-automation github-project-automation bot moved this to 📋 Backlog in Noir Nov 21, 2024
@TomAFrench
Copy link
Member

Hey Oleh, we're currently looking to reduce the size of the stdlib as mentioned in #1258 so we're probably not going to include this. I think it would be best to have a num-traits crate similar to rust as this can then change without it being a breaking change to the language as a whole.

@TomAFrench TomAFrench closed this as not planned Won't fix, can't repro, duplicate, stale Nov 21, 2024
@github-project-automation github-project-automation bot moved this from 📋 Backlog to ✅ Done in Noir Nov 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Archived in project
Development

No branches or pull requests

2 participants