https://github.com/akramarenkov/safe
Library that provides to detect and avoid overflows in operations with integer numbers
https://github.com/akramarenkov/safe
go golang integer overflow
Last synced: 9 months ago
JSON representation
Library that provides to detect and avoid overflows in operations with integer numbers
- Host: GitHub
- URL: https://github.com/akramarenkov/safe
- Owner: akramarenkov
- License: mit
- Created: 2023-07-08T22:23:47.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2025-04-03T02:44:59.000Z (9 months ago)
- Last Synced: 2025-04-03T03:27:28.239Z (9 months ago)
- Topics: go, golang, integer, overflow
- Language: Go
- Homepage:
- Size: 1.76 MB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: COPYING
Awesome Lists containing this project
README
# Safe
[](https://pkg.go.dev/github.com/akramarenkov/safe)
[](https://goreportcard.com/report/github.com/akramarenkov/safe)
[](https://coveralls.io/github/akramarenkov/safe)
## Purpose
Library that provides to detect and avoid overflows in operations with integer numbers
## Usage
Example:
```go
package main
import (
"fmt"
"github.com/akramarenkov/safe"
)
func main() {
sum, err := safe.Add[int8](124, 3)
fmt.Println(err)
fmt.Println(sum)
sum, err = safe.Add[int8](125, 3)
fmt.Println(err)
fmt.Println(sum)
// Output:
//
// 127
// integer overflow
// 0
}
```