Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

math/big: ProbablyPrime accepts nonpositive integers as rounds count #9509

Closed
ALTree opened this issue Jan 5, 2015 · 4 comments
Closed

math/big: ProbablyPrime accepts nonpositive integers as rounds count #9509

ALTree opened this issue Jan 5, 2015 · 4 comments

Comments

@ALTree
Copy link
Member

ALTree commented Jan 5, 2015

Even though only positive integers make sense, ProbablyPrime accepts null and negative integers for the "number of Miller-Rabin rounds" parameter, and happily output true (i.e prime) when given n < 1.

package main

import "math/big"

func main() {
    n := new(big.Int)
    n.SetString("5041", 10) // 71 * 71
    println(n.ProbablyPrime(0)) // true
}

http://play.golang.org/p/vLwhlt3xsC

@griesemer griesemer added this to the Go1.5 milestone Jan 5, 2015
@griesemer griesemer self-assigned this Jan 5, 2015
@griesemer
Copy link
Contributor

Easy to add an extra test if that's desired and documentation is not good enough.

@ALTree
Copy link
Member Author

ALTree commented Jan 5, 2015

Easy to patch but I'm not sure whether

  • Leave the code, change documentation ("no Miller-Rabin test is done when n < 1")
  • Panic on n < 1
  • Ignore the given n and set a custom nice value (i.e. 25) on n < 1

@griesemer griesemer reopened this Jan 5, 2015
@griesemer
Copy link
Contributor

I'd document that n must be > 0 and panic with an appropriate message if it's not. That makes it clear and prevents surprises.

@minux
Copy link
Member

minux commented Jan 5, 2015

Sent https://golang.org/cl/2313

@minux minux closed this as completed in 4317869 Jan 5, 2015
@golang golang locked and limited conversation to collaborators Jun 25, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants