Skip to content

broken nextpow functions #4819

Closed
Closed
@stevengj

Description

I've been looking at the prevpow/nextpow functions, and they seem somewhat broken to me:

  • nextpow2(n) != nextpow2(2, n): the former returns the power-of-2 value, and the latter returns the exponent. e.g. nextpow2(9) is 16, but nextpow(2, 9) is 4. Similarly for prevpow.
  • nextpow2(0) == prevpow2(0) == 0. I can only understand this behavior under the theory that zero is 2^–∞, but that seems questionable to me. nextpow(2, 0) and prevpow(2, 0) raise an InexactError (I would have expected a DomainError, maybe?).
  • prevpow(2, 1) correctly returns 0 (1 == 2^0, see first point), but nextpow(2, 1) throws a DomainError, which is certainly wrong.
  • nextpow(2, -7) and prevpow(2, -7) raise DomainErrors, but nextpow2(-7) gives -8 and prevpow2(-7) gives -4.
  • The documentation for these functions does not clarify any of the above behaviors.

Activity

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

Metadata

Assignees

No one assigned

    Labels

    bugIndicates an unexpected problem or unintended behaviorneeds decisionA decision on this change is needed

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions