Skip to content

[RFC] Promotion rules for overflow reduction #167

Closed
@kimikage

Description

@kimikage

We plan to implement the overflow-checked arithmetic to mitigate the overflow problem (cf. #41, #152).

The checked arithmetic prevents numerical errors which the users do not intend, but it is up to the users to correct them. There are two major issues.

  1. The current Normed cannot represent negative numbers, so we will easily encounter OverflowError in subtraction.
  2. The return type of addition/subtraction is the same as the input type, so it needs to convert values into wider type (e.g. Float32) to avoid overflow.

To solve the former, signed Normed is proposed in PR #143.
I don't agree with the introducing Normed{<:Signed} because of the huge impact on compatibility. However, I think signed Normed is not so bad unless it breaks the existing Normed.

For the latter, PR #143 also proposes type promotions.
I don't consider the latter a fatal problem, as it's up to the users what operations and types they want. On the other hand, the type promotion has some problems.

Perhaps you might think that the type promotion frees you from the overflow problems.
But I think it is an illusion. To turn and face reality, let's decide the promotion rules.

Of course, the preferred promotion rule for me is "not to promote".

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