Skip to content

Promotion rules #49

Open
Open
@EricForgy

Description

@EricForgy
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> 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> one/3
FixedDecimal{Int64,2}(0.33)

and

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

> 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
  2. 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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions