JuliaMath / JuliaMath/FixedPointDecimals.jl

Eliminate/mitigate overflow (and rounding)

Open
#81 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Julia
Stars
37
Forks
23
PR merge metrics
No merged PRs in 30d

Description

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.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.