An open API service indexing awesome lists of open source software.

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

Awesome Lists containing this project

README

          

# Safe

[![Go Reference](https://pkg.go.dev/badge/github.com/akramarenkov/safe.svg)](https://pkg.go.dev/github.com/akramarenkov/safe)
[![Go Report Card](https://goreportcard.com/badge/github.com/akramarenkov/safe)](https://goreportcard.com/report/github.com/akramarenkov/safe)
[![Coverage Status](https://coveralls.io/repos/github/akramarenkov/safe/badge.svg)](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
}
```