Skip to content

Adding operators like +ᶜᵏᵈ in opt-in #10

@kimikage

Description

@kimikage

I have suggested the idea of defining saturation operators in the past (as a joke).
https://discourse.julialang.org/t/rfc-what-should-the-arithmetic-within-the-fixedpointnumbers-be/46697/41

I am beginning to think that as long as such operators are not exported by default, it is not a bad idea to provide them.

julia> const +ᶜᵏᵈ = Base.Checked.checked_add
checked_add (generic function with 11 methods)

julia> Int8(127) +ᶜᵏᵈ Int8(1)
ERROR: OverflowError: 127 + 1 overflowed for type Int8

The biggest concern was the rendering and input of minor Unicode characters, but with the emergence of JuliaMono, the situation has greatly improved over the past three years.

Another concern was that checked is too long as a suffix. In the so-called C23, it is proposed to use the ckd prefix for checked arithmetic functions. This gave some justification for the use of the abbreviation ckd.

I believe that no matter what decision we make regarding issue #9, there is a demand to override the context on a per-operator basis.

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