Skip to content

Feature Request: Support 05Up RoundingMode #159

Description

@LambdaAlpha

According to wikipedia, there are many rounding modes which are not included in RoundingMode. There is a special rounding mode which is used to avoid getting a potentially wrong result after multiple roundings. Python has provided this rounding mode in its decimal library and called it ROUND_05UP. I request adding 05Up to RoundingMode, because this mode enables users to implement their custom rounding strategies, by rounding result with 05Up mode and with precision target_precision + 1 and then doing a custom rounding again to target_precision.

The RoundingMode has a round_pair method

fn round_pair(&self, sign: Sign, (d0, d1): (u8, u8), trailing_zeros: bool) -> u8;

The 05Up mode implementation of this method is like

fn round_pair(sign: Sign, (d0, d1): (u8, u8), trailing_zeros: bool) -> u8 {
    if d0 != 0 && d0 != 5 {
        return d0;
    }
    if d1 == 0 && trailing_zeros {
        return d0;
    }
    return d0 + 1;
}

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions