Skip to content

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

License

Notifications You must be signed in to change notification settings

akramarenkov/safe

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Safe

Go Reference Go Report Card Coverage Status

Purpose

Library that allows you to detect and avoid 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)
    fmt.Println(err)
    fmt.Println(sum)

    sum, err = safe.Add[int8](125, 3)
    fmt.Println(err)
    fmt.Println(sum)
    // Output:
    // <nil>
    // 127
    // integer overflow
    // 0
}

About

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

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages