Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/thetardigrade/golang-prime
Go utility package for working with prime numbers
https://github.com/thetardigrade/golang-prime
go golang math mathematics maths numbers prime-number-generation prime-numbers primes
Last synced: about 3 hours ago
JSON representation
Go utility package for working with prime numbers
- Host: GitHub
- URL: https://github.com/thetardigrade/golang-prime
- Owner: theTardigrade
- License: gpl-3.0
- Created: 2022-05-20T21:01:12.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-02-22T01:06:44.000Z (over 1 year ago)
- Last Synced: 2024-06-20T17:51:55.552Z (5 months ago)
- Topics: go, golang, math, mathematics, maths, numbers, prime-number-generation, prime-numbers, primes
- Language: Go
- Homepage:
- Size: 24.4 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# golang-prime
This package provides some functions for working with prime numbers.
[![Go Reference](https://pkg.go.dev/badge/github.com/theTardigrade/golang-prime.svg)](https://pkg.go.dev/github.com/theTardigrade/golang-prime) [![Go Report Card](https://goreportcard.com/badge/github.com/theTardigrade/golang-prime)](https://goreportcard.com/report/github.com/theTardigrade/golang-prime)
## Example
```golang
package mainimport (
"fmt"prime "github.com/theTardigrade/golang-prime"
)func main() {
var magicNumber int64 = 3fmt.Println(prime.Is(magicNumber)) // true
fmt.Println(prime.Next(magicNumber)) // 5, true
fmt.Println(prime.Prev(magicNumber)) // 2, truefmt.Println("*****")
magicNumber = 120
fmt.Println(prime.Is(magicNumber)) // false
fmt.Println(prime.Next(magicNumber)) // 127, true
fmt.Println(prime.Prev(magicNumber)) // 113, truefmt.Println("*****")
magicNumber = 2
fmt.Println(prime.Is(magicNumber)) // true
fmt.Println(prime.Next(magicNumber)) // 3, true
fmt.Println(prime.Prev(magicNumber)) // 0, falsefmt.Println("*****")
magicNumber = 1_000_000_000_000
fmt.Println(prime.Is(magicNumber)) // false
fmt.Println(prime.Next(magicNumber)) // 1000000000001, true
fmt.Println(prime.Prev(magicNumber)) // 999999999997, true
}
```## Support
If you use this package, or find any value in it, please consider donating:
[![ko-fi](https://ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/S6S2EIRL0)