Documentation ¶
Index ¶
- Variables
- func FloatToInt[Float constraints.Float, Integer constraints.Integer](float Float) (Integer, error)
- func Invert[Type constraints.Signed](number Type) (Type, error)
- func IsMaxNegative[Type constraints.Integer](number Type) bool
- func IsMaxPositive[Type constraints.Integer](number Type) bool
- func PowUnsigned[Type constraints.Unsigned](base Type, exponent Type) (Type, error)
- func ProductInt[Type constraints.Integer](first Type, second Type) (Type, error)
- func SumInt[Type constraints.Integer](first Type, second Type) (Type, error)
- func UnsignedToSigned[Unsigned constraints.Unsigned, Signed constraints.Signed](number Unsigned) (Signed, error)
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var (
ErrValueOverflow = errors.New("value overflow")
)
Functions ¶
func FloatToInt ¶
func FloatToInt[ Float constraints.Float, Integer constraints.Integer, ](float Float) (Integer, error)
func Invert ¶
func Invert[Type constraints.Signed](number Type) (Type, error)
func IsMaxNegative ¶
func IsMaxNegative[Type constraints.Integer](number Type) bool
func IsMaxPositive ¶
func IsMaxPositive[Type constraints.Integer](number Type) bool
func PowUnsigned ¶
func PowUnsigned[Type constraints.Unsigned](base Type, exponent Type) (Type, error)
func ProductInt ¶
func ProductInt[Type constraints.Integer](first Type, second Type) (Type, error)
func SumInt ¶
func SumInt[Type constraints.Integer](first Type, second Type) (Type, error)
Example ¶
package main import ( "fmt" "github.com/akramarenkov/safe" ) func main() { sum, err := safe.SumInt[int8](3, 124) if err != nil { panic(err) } fmt.Println(sum) _, err = safe.SumInt[int8](3, 125) if err == nil { panic("expected overflow") } }
Output: 127
func UnsignedToSigned ¶
func UnsignedToSigned[ Unsigned constraints.Unsigned, Signed constraints.Signed, ](number Unsigned) (Signed, error)
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.