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

Add a BigFloat with const generic precision #25

Open
tgross35 opened this issue Apr 5, 2024 · 0 comments
Open

Add a BigFloat with const generic precision #25

tgross35 opened this issue Apr 5, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@tgross35
Copy link

tgross35 commented Apr 5, 2024

A lot of the time, needed precision might be known ahead of runtime. Const generics might be able to make use of something like this:

struct KnownBigFloat<const WORDS: usize = 2> {
    inner: KnownFlavor<WORDS>,
}

#[derive(Debug)]
enum KnownFlavor<const WORDS: usize> {
    Value(KnownBigFloatNumber<WORDS>),
    NaN(Option<Error>),
    Inf(Sign), // signed Inf
}

pub(crate) struct KnownBigFloatNumber<const WORDS: usize> {
    e: Exponent,
    s: Sign,
    m: KnownMantissa<WORDS>,
    inexact: bool,
}

pub(crate) struct KnownMantissa<const WORDS: usize> {
    m: [Word; WORDS],
}

I expect this would have a noticeable performance increase as well - mantissa is smaller for <= 128 bits of precision, allocation-free, no indirection, and probably some nicer optimizations.

A downside is this isn't as elegant as it could be with the unstbale generic_const_exprs - ideally you could specify BITS in the const generic and store m: [Word; BITS / WORD_BIT_SIZE], but that won't be stable for a while.

@stencillogic stencillogic added the enhancement New feature or request label Apr 6, 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
None yet
Development

No branches or pull requests

2 participants