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

Eliminate/mitigate overflow (and rounding) #81

Open
PallHaraldsson opened this issue Sep 12, 2023 · 0 comments
Open

Eliminate/mitigate overflow (and rounding) #81

PallHaraldsson opened this issue Sep 12, 2023 · 0 comments

Comments

@PallHaraldsson
Copy link

It seems you always need to specify how many decimals, e.g. with FixedDecimal{Int8, 2} and that type which is far from optional. Most likely it's not useful enough for money, and when you want to base on Int8 otherwise likely binary fixed point better.

I suggest as a happy medium for your docs, instead of (or have both):

For example, FixedDecimal{Int8, 2} allows you [to a] decimal number with up to 2 fractional digits.

const FixedSafeDecimal = FixedDecimal{Int32, 3}

I intentionally didn't go with Int64, since then you multiply two such numbers you could get FixedDecimal{Int64, 6} and you don't need to check for overflows nor round, and I would like that type to do it by default. It's just an idea for your package, I've been thinking of making my own, and I could do that and wrap yours, in case you don't want to implement this.

You can add and subtract, and then there is a possibility of one extra bit, this overflow, in case you want to check for that, or just go to FixedDecimal{Int64, 3}, note not there ,6. The division is the problem, then I would argue for going to a rational rather than Float64 or either these types.

Because in that case and at least for multiplying you want to put the "genie-back-into-the bottle", and I suggest a round back to FixedSafeDecimal with overflow check postponed until then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant