Skip to content

isprime(n) allocates #125

@stevengj

Description

@stevengj

See this discourse comment.

It seems like this could be fixed with a little refactoring. Instead of having witnesses(n) return a variably sized tuple (which is not type stable), it would be better to inline this into isprime and do something like:

return n < 4294967296  ? checkwitnesses(n, _witnesses(UInt64(n))) :
        n < 2152302898747   ? checkwitnesses(n, (2, 3, 5, 7, 11)) :
        n < 3474749660383   ? checkwitnesses(n, (2, 3, 5, 7, 11, 13)):
                              checkwitnesses(n, (2, 325, 9375, 28178, 450775, 9780504, 1795265022))

where checkwitnesses(n, witnesses) is simply this loop refactored into a function.

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