Skip to content

Ensure that all unsigned arithmetic never underflows #1

@TysonRayJones

Description

@TysonRayJones

The use of the Nat (unsigned) primitive makes subtraction dangerous. Even if a + b > c, the expression

a + b - c

might see an underflow (because b < c, and ergo b-c underflows) and an erroneous result.

A simple caution is to group (and perform first) addition, i.e.

(a + b) - c

An example of such expressions occur when calculating whether the target qubit lies in the prefix qubit subsets (see densitymatrix_oneQubitDepolarising()).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions