Skip to content

Library that allows you to detect overflows in operations with integer numbers

License

Notifications You must be signed in to change notification settings

akramarenkov/safe

Repository files navigation

Safe

Go Reference Go Report Card codecov

Purpose

Library that allows you to detect overflows in operations with integer numbers

Usage

Example:

package main

import (
    "fmt"

    "github.com/akramarenkov/safe"
)

func main() {
    sum, err := safe.Add[int8](124, 3)
    if err != nil {
        panic(err)
    }

    fmt.Println(sum)

    _, err = safe.Add[int8](125, 3)
    if err == nil {
        panic("expected overflow")
    }

    // Output: 127
}

About

Library that allows you to detect overflows in operations with integer numbers

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages