Skip to content

Changing rounding mode of "mul" (*) for Fixed to RoundNearest #173

Closed
@kimikage

Description

@kimikage

The current rounding mode of "mul"(*) for Fixed is RoundNearestTiesUp. (The comment "rounding up" is ambiguous, though.) In addition, the implementation with RoundDown is commented out. (The comment "truncation" is also ambiguous, though.)

# with truncation:
#*(x::Fixed{T,f}, y::Fixed{T,f}) = Fixed{T,f}(Base.widemul(x.i,y.i)>>f,0)
# with rounding up:
*(x::Fixed{T,f}, y::Fixed{T,f}) where {T,f} = Fixed{T,f}((Base.widemul(x.i,y.i) + (one(widen(T)) << (f-1)))>>f,0)

However, considering the future addition of checked_mul, I think it would be better to change the rounding mode to the default (i.e. RoundNearest) for consistency.

On the other hand, I would also like to have the interfaces to implementations with other rounding modes, for speed. The problem is that there is no official interface that takes a rounding mode as an argument. The third argument of Base.*() collides with z in x * y * z (Of course, there are no arithmetic operations for RoundingMode, though).

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