Skip to content

math/big: ModInverse doesn't support negative numbers #16984

@stefan-sakalik

Description

@stefan-sakalik

What version of Go are you using (go version)?

go version go1.7rc3 linux/amd64

What operating system and processor architecture are you using (go env)?

amd64

What did you do?

I tried computing inverse modulo of a negative number using this snippet:

package main                                                                                                                                                              

import (                                                                                                                                                                  
        "fmt"                                                                                                                                                             
        "math/big"                                                                                                                                                        
)                                                                                                                                                                         

func main() {                                                                                                                                                             
        res := big.NewInt(0).ModInverse(big.NewInt(-10), big.NewInt(13)).Int64()                                                                                          
        fmt.Println(res)                                                                                                                                                  
}            

What did you expect to see?

9

What did you see instead?

0

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions