Skip to content

Support full precision of all numbers #337

Open
@Urgau

Description

@Urgau

When using fluent inside the Rust compiler we came across an unfortunate limitation, fluent and more precisely FluentNumber doesn't support the full precision of all numbers it accepts.

#[derive(Debug, PartialEq, Clone)]
pub struct FluentNumber {
pub value: f64,
pub options: FluentNumberOptions,
}

This is due to the internal representation of number which uses a f64 which can't fully represent a i64 and u64. For example i64::MAX (9223372036854775807) would be 92233720368547760000, notice the last 4 character 5807 != 0000.

This is particularly a problem for rustc because we print the limits of numbers, which would be off if done using f64. We workaround it using a string for numbers between -100..=100 (to still be able to select on them); but this isn't a solution.


One way I could see fluent fix this issue would be to use a representation like this:

#[derive(Debug, PartialEq, Clone)]
pub enum FluentNumberValue {
    Float(f64),
    SignedInteger(i128),
    UnsignedInteger(u128),
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions