Skip to content

Q.mul_2exp and Q.div_2exp fail with negative exponent #171

Description

@JanBeh

Using zarith 1.14, I get:

utop # #require "zarith";;
utop # Q.mul_2exp Q.one (-1);;
Exception: Invalid_argument "Z.shift_left: count argument must be positive".
utop # Q.div_2exp Q.one (-1);;
Exception: Invalid_argument "Z.shift_left: count argument must be positive".

I.e. Q.mul_2exp and Q.div_2exp fail when the exponent is negative with a confusing error message.

There is a workaround by checking whether the exponent is negative and then using div_2exp instead of mul_2exp and vice versa.

The functions should be fixed to work with negative exponents too (or the error message should be more meaningful and the behavior documented).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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