Skip to content
This repository was archived by the owner on Dec 23, 2025. It is now read-only.

jotaen/safemath

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

safemath

Go library for basic arithmetics with protection against integer overflow.

Example

package main

import (
	"fmt"
	"github.com/jotaen/safemath/safemath"
)

func main() {
	// Ok:
	res, err := safemath.Add(1, 2)
	if err != nil {
		fmt.Println("Overflow!")
	} else {
		fmt.Println(res) // <---- Prints "3"
	}

	// Overflow (on 64-bit systems):
	res, err = safemath.Add(9223372036854775807, 1)
	if err != nil {
		fmt.Println("Overflow!")   // <---- Prints "Overflow!"
	} else {
		fmt.Println(res)
	}
}

About

Go library for basic arithmetics with protection against integer overflow

Resources

License

Stars

0 stars

Watchers

1 watching

Forks

Contributors