JuliaMath / JuliaMath/FixedPointDecimals.jl

Promotion rules

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

Description

```julia
julia> one = FixedDecimal{Int,2}(1)
FixedDecimal{Int64,2}(1.00)

julia> one/3
FixedDecimal{Int64,2}(0.33)

julia> one/3.0
0.3333333333333333
```

Intuitively, I would expect `one/3 === one/3.0` since

```julia
julia> 1/3 === 1/3.0
true
```

Strictly speaking, `one/3` should probably also be a `Float64`, BUT...

I think users of this package might reasonably expect both

```julia
julia> one/3
FixedDecimal{Int64,2}(0.33)
```

and

```julia
julia> one/3.0
FixedDecimal{Int64,2}(0.33)
```

Otherwise, there would need to be a lot of conversion in the code that would kind of defeat its purpose. For example, if you wanted the result of `one/3.0` to remain a `FixedDecimal`, you'd need to do something like

```julia
> onethird = FixedDecimal{Int,2}(one/3.0)
```

I think we should either:

1. Make `one/3` also a `Float64` so `one/3 === one/3.0` or
1. Make `one/3.0` also a `FixedDecimal` so `one/3 === one/3.0`

I kind of prefer the latter, but in any case it currently seems inconsistent.

What do you think?

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.