Skip to content

Is pow2 of negative exponentials supported? #1252

Open
@Timmmm

Description

@Timmmm

The 2 ^ operator is mapped to pow2, and for the C backend at least, it treats negative exponents as positive, so 2 ^ -3 is 8. _builtin_pow2 has this comment:

/* Below we need the fact that 2 ^ 'n >= 0, so we axiomatise it in the return
   type of pow2, as SMT solvers tend to have problems with exponentiation. */
val _builtin_pow2 = pure "pow2" : forall 'n, 'n >= 0. int('n) -> {'m, 'm == 2 ^ 'n & 'm >= 0. int('m)}

That suggests it is intentional. However with the OCaml backend you get a runtime error:

Exiting due to uncaught exception:
Invalid_argument("power_big_int_positive_int")

Feels like this should either be totally disallowed, or at least it should work with OCaml and should be documented because it's pretty surprising! Disallowing it may be a reasonable option - I can't really see why you'd ever need it tbh.

Not blocking or anything but a colleague asked about it and I was curious why it is like this. I think you might have explained it a long time ago but if so I've forgotten the reason.

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