interval

package module
v0.0.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 1, 2021 License: MIT Imports: 2 Imported by: 1

README

github.com/zzwx/interval

Interval

An almost useless utility for normalizing a numeric range, with a wrapping function for polar coordinates, implemented using go generate.

It is a golang clone of a JavaScript project by James Talmage.

For dealing with the strict typing in Go, functions were auto-generated for all of the following types:

  • int
  • int64
  • int32
  • int16
  • int8
  • uint
  • uint64
  • uint32
  • uint16
  • uint8
  • float32
  • float64

Motivation

This approach is inspired by Rob Pike's article on code generation. Until generics are implemented, this is simply an example of code generation, exploiting templates in this case.

Installation

go get -u github.com/zzwx/interval

Usage

package main

import (
	"fmt"

	"github.com/zzwx/interval"
)

func main() {
	fmt.Println(interval.WrapInt(0, 360, 400))  //=> 40
	fmt.Println(interval.WrapInt(0, 360, -90))  //=> 270
	fmt.Println(interval.ClampInt(0, 100, 500)) //=> 100
	fmt.Println(interval.ClampInt(0, 100, -20)) //=> 0

	r := interval.NewRangeFloat64(0, 100, false, false)
	fmt.Println(r.Wrap(120))     //=> 20
	fmt.Println(r.Validate(120)) //=> 0, error(120 is outside of range [0,100])
	fmt.Println(r.Test(120))     //=> false
	fmt.Println(r)               //=> [0,100] (uses Stringer interface)
}

Go Playground

API

https://pkg.go.dev/github.com/zzwx/interval

License

Original JavaScript author: James Talmage

MIT © Anton Veretennikov

Documentation

Overview

Package interval provides functions to work with the ranges, both inclusive and exclusive. All functions are auto-generated for every built-in numeric type in Go.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClampFloat32

func ClampFloat32(min, max, value float32) float32

ClampFloat32 returns value capped to [min,max] range. Both ends of this range are inclusive.

Example
fmt.Printf("%v\n", ClampFloat32(0, 100, 120)) //=> 100
fmt.Printf("%v\n", ClampFloat32(0, 100, -20)) //=> 0
fmt.Printf("%v\n", ClampFloat32(100, 0, -20)) //=> 0 (even though min & max are swapped)
Output:

100
0
0

func ClampFloat64

func ClampFloat64(min, max, value float64) float64

ClampFloat64 returns value capped to [min,max] range. Both ends of this range are inclusive.

Example
fmt.Printf("%v\n", ClampFloat64(0, 100, 120)) //=> 100
fmt.Printf("%v\n", ClampFloat64(0, 100, -20)) //=> 0
fmt.Printf("%v\n", ClampFloat64(100, 0, -20)) //=> 0 (even though min & max are swapped)
Output:

100
0
0

func ClampInt

func ClampInt(min, max, value int) int

ClampInt returns value capped to [min,max] range. Both ends of this range are inclusive.

Example
fmt.Printf("%v\n", ClampInt(0, 100, 120)) //=> 100
fmt.Printf("%v\n", ClampInt(0, 100, -20)) //=> 0
fmt.Printf("%v\n", ClampInt(100, 0, -20)) //=> 0 (even though min & max are swapped)
Output:

100
0
0

func ClampInt16

func ClampInt16(min, max, value int16) int16

ClampInt16 returns value capped to [min,max] range. Both ends of this range are inclusive.

Example
fmt.Printf("%v\n", ClampInt16(0, 100, 120)) //=> 100
fmt.Printf("%v\n", ClampInt16(0, 100, -20)) //=> 0
fmt.Printf("%v\n", ClampInt16(100, 0, -20)) //=> 0 (even though min & max are swapped)
Output:

100
0
0

func ClampInt32

func ClampInt32(min, max, value int32) int32

ClampInt32 returns value capped to [min,max] range. Both ends of this range are inclusive.

Example
fmt.Printf("%v\n", ClampInt32(0, 100, 120)) //=> 100
fmt.Printf("%v\n", ClampInt32(0, 100, -20)) //=> 0
fmt.Printf("%v\n", ClampInt32(100, 0, -20)) //=> 0 (even though min & max are swapped)
Output:

100
0
0

func ClampInt64

func ClampInt64(min, max, value int64) int64

ClampInt64 returns value capped to [min,max] range. Both ends of this range are inclusive.

Example
fmt.Printf("%v\n", ClampInt64(0, 100, 120)) //=> 100
fmt.Printf("%v\n", ClampInt64(0, 100, -20)) //=> 0
fmt.Printf("%v\n", ClampInt64(100, 0, -20)) //=> 0 (even though min & max are swapped)
Output:

100
0
0

func ClampInt8

func ClampInt8(min, max, value int8) int8

ClampInt8 returns value capped to [min,max] range. Both ends of this range are inclusive.

Example
fmt.Printf("%v\n", ClampInt8(0, 100, 120)) //=> 100
fmt.Printf("%v\n", ClampInt8(0, 100, -20)) //=> 0
fmt.Printf("%v\n", ClampInt8(100, 0, -20)) //=> 0 (even though min & max are swapped)
Output:

100
0
0

func ClampUint

func ClampUint(min, max, value uint) uint

ClampUint returns value capped to [min,max] range. Both ends of this range are inclusive.

Example
fmt.Printf("%v\n", ClampUint(0, 100, 120)) //=> 100
Output:

100

func ClampUint16

func ClampUint16(min, max, value uint16) uint16

ClampUint16 returns value capped to [min,max] range. Both ends of this range are inclusive.

Example
fmt.Printf("%v\n", ClampUint16(0, 100, 120)) //=> 100
Output:

100

func ClampUint32

func ClampUint32(min, max, value uint32) uint32

ClampUint32 returns value capped to [min,max] range. Both ends of this range are inclusive.

Example
fmt.Printf("%v\n", ClampUint32(0, 100, 120)) //=> 100
Output:

100

func ClampUint64

func ClampUint64(min, max, value uint64) uint64

ClampUint64 returns value capped to [min,max] range. Both ends of this range are inclusive.

Example
fmt.Printf("%v\n", ClampUint64(0, 100, 120)) //=> 100
Output:

100

func ClampUint8

func ClampUint8(min, max, value uint8) uint8

ClampUint8 returns value capped to [min,max] range. Both ends of this range are inclusive.

Example
fmt.Printf("%v\n", ClampUint8(0, 100, 120)) //=> 100
Output:

100

func MaxFloat32

func MaxFloat32(x, y float32) float32

MaxFloat32 returns the bigger of two numbers.

func MaxFloat64

func MaxFloat64(x, y float64) float64

MaxFloat64 returns the bigger of two numbers.

func MaxInt

func MaxInt(x, y int) int

MaxInt returns the bigger of two numbers.

func MaxInt16

func MaxInt16(x, y int16) int16

MaxInt16 returns the bigger of two numbers.

func MaxInt32

func MaxInt32(x, y int32) int32

MaxInt32 returns the bigger of two numbers.

func MaxInt64

func MaxInt64(x, y int64) int64

MaxInt64 returns the bigger of two numbers.

func MaxInt8

func MaxInt8(x, y int8) int8

MaxInt8 returns the bigger of two numbers.

func MaxUint

func MaxUint(x, y uint) uint

MaxUint returns the bigger of two numbers.

func MaxUint16

func MaxUint16(x, y uint16) uint16

MaxUint16 returns the bigger of two numbers.

func MaxUint32

func MaxUint32(x, y uint32) uint32

MaxUint32 returns the bigger of two numbers.

func MaxUint64

func MaxUint64(x, y uint64) uint64

MaxUint64 returns the bigger of two numbers.

func MaxUint8

func MaxUint8(x, y uint8) uint8

MaxUint8 returns the bigger of two numbers.

func MinFloat32

func MinFloat32(x, y float32) float32

MinFloat32 returns the smaller of two numbers.

func MinFloat64

func MinFloat64(x, y float64) float64

MinFloat64 returns the smaller of two numbers.

func MinInt

func MinInt(x, y int) int

MinInt returns the smaller of two numbers.

func MinInt16

func MinInt16(x, y int16) int16

MinInt16 returns the smaller of two numbers.

func MinInt32

func MinInt32(x, y int32) int32

MinInt32 returns the smaller of two numbers.

func MinInt64

func MinInt64(x, y int64) int64

MinInt64 returns the smaller of two numbers.

func MinInt8

func MinInt8(x, y int8) int8

MinInt8 returns the smaller of two numbers.

func MinMaxExclusiveFloat32

func MinMaxExclusiveFloat32(min, max float32, minExclusive, maxExclusive bool) (float32, float32, bool, bool)

MinMaxExclusiveFloat32 swaps min and max as well as minExclusive, maxExclusive correspondingly to assure that min < max together with the interval endings. It is automatically called for all the rest of the functions that expect minExclusive or maxExclusive.

Example
x, y, xe, ye := MinMaxExclusiveFloat32(0, 100, true, false)
fmt.Printf("%v %v %v %v\n", x, y, xe, ye)                  //=> 0 100 true false
x, y, xe, ye = MinMaxExclusiveFloat32(100, 0, false, true) // swapped
fmt.Printf("%v %v %v %v\n", x, y, xe, ye)                  //=> 0 100 true false
Output:

0 100 true false
0 100 true false

func MinMaxExclusiveFloat64

func MinMaxExclusiveFloat64(min, max float64, minExclusive, maxExclusive bool) (float64, float64, bool, bool)

MinMaxExclusiveFloat64 swaps min and max as well as minExclusive, maxExclusive correspondingly to assure that min < max together with the interval endings. It is automatically called for all the rest of the functions that expect minExclusive or maxExclusive.

Example
x, y, xe, ye := MinMaxExclusiveFloat64(0, 100, true, false)
fmt.Printf("%v %v %v %v\n", x, y, xe, ye)                  //=> 0 100 true false
x, y, xe, ye = MinMaxExclusiveFloat64(100, 0, false, true) // swapped
fmt.Printf("%v %v %v %v\n", x, y, xe, ye)                  //=> 0 100 true false
Output:

0 100 true false
0 100 true false

func MinMaxExclusiveInt

func MinMaxExclusiveInt(min, max int, minExclusive, maxExclusive bool) (int, int, bool, bool)

MinMaxExclusiveInt swaps min and max as well as minExclusive, maxExclusive correspondingly to assure that min < max together with the interval endings. It is automatically called for all the rest of the functions that expect minExclusive or maxExclusive.

Example
x, y, xe, ye := MinMaxExclusiveInt(0, 100, true, false)
fmt.Printf("%v %v %v %v\n", x, y, xe, ye)              //=> 0 100 true false
x, y, xe, ye = MinMaxExclusiveInt(100, 0, false, true) // swapped
fmt.Printf("%v %v %v %v\n", x, y, xe, ye)              //=> 0 100 true false
Output:

0 100 true false
0 100 true false

func MinMaxExclusiveInt16

func MinMaxExclusiveInt16(min, max int16, minExclusive, maxExclusive bool) (int16, int16, bool, bool)

MinMaxExclusiveInt16 swaps min and max as well as minExclusive, maxExclusive correspondingly to assure that min < max together with the interval endings. It is automatically called for all the rest of the functions that expect minExclusive or maxExclusive.

Example
x, y, xe, ye := MinMaxExclusiveInt16(0, 100, true, false)
fmt.Printf("%v %v %v %v\n", x, y, xe, ye)                //=> 0 100 true false
x, y, xe, ye = MinMaxExclusiveInt16(100, 0, false, true) // swapped
fmt.Printf("%v %v %v %v\n", x, y, xe, ye)                //=> 0 100 true false
Output:

0 100 true false
0 100 true false

func MinMaxExclusiveInt32

func MinMaxExclusiveInt32(min, max int32, minExclusive, maxExclusive bool) (int32, int32, bool, bool)

MinMaxExclusiveInt32 swaps min and max as well as minExclusive, maxExclusive correspondingly to assure that min < max together with the interval endings. It is automatically called for all the rest of the functions that expect minExclusive or maxExclusive.

Example
x, y, xe, ye := MinMaxExclusiveInt32(0, 100, true, false)
fmt.Printf("%v %v %v %v\n", x, y, xe, ye)                //=> 0 100 true false
x, y, xe, ye = MinMaxExclusiveInt32(100, 0, false, true) // swapped
fmt.Printf("%v %v %v %v\n", x, y, xe, ye)                //=> 0 100 true false
Output:

0 100 true false
0 100 true false

func MinMaxExclusiveInt64

func MinMaxExclusiveInt64(min, max int64, minExclusive, maxExclusive bool) (int64, int64, bool, bool)

MinMaxExclusiveInt64 swaps min and max as well as minExclusive, maxExclusive correspondingly to assure that min < max together with the interval endings. It is automatically called for all the rest of the functions that expect minExclusive or maxExclusive.

Example
x, y, xe, ye := MinMaxExclusiveInt64(0, 100, true, false)
fmt.Printf("%v %v %v %v\n", x, y, xe, ye)                //=> 0 100 true false
x, y, xe, ye = MinMaxExclusiveInt64(100, 0, false, true) // swapped
fmt.Printf("%v %v %v %v\n", x, y, xe, ye)                //=> 0 100 true false
Output:

0 100 true false
0 100 true false

func MinMaxExclusiveInt8

func MinMaxExclusiveInt8(min, max int8, minExclusive, maxExclusive bool) (int8, int8, bool, bool)

MinMaxExclusiveInt8 swaps min and max as well as minExclusive, maxExclusive correspondingly to assure that min < max together with the interval endings. It is automatically called for all the rest of the functions that expect minExclusive or maxExclusive.

Example
x, y, xe, ye := MinMaxExclusiveInt8(0, 100, true, false)
fmt.Printf("%v %v %v %v\n", x, y, xe, ye)               //=> 0 100 true false
x, y, xe, ye = MinMaxExclusiveInt8(100, 0, false, true) // swapped
fmt.Printf("%v %v %v %v\n", x, y, xe, ye)               //=> 0 100 true false
Output:

0 100 true false
0 100 true false

func MinMaxExclusiveUint

func MinMaxExclusiveUint(min, max uint, minExclusive, maxExclusive bool) (uint, uint, bool, bool)

MinMaxExclusiveUint swaps min and max as well as minExclusive, maxExclusive correspondingly to assure that min < max together with the interval endings. It is automatically called for all the rest of the functions that expect minExclusive or maxExclusive.

Example
x, y, xe, ye := MinMaxExclusiveUint(0, 100, true, false)
fmt.Printf("%v %v %v %v\n", x, y, xe, ye)               //=> 0 100 true false
x, y, xe, ye = MinMaxExclusiveUint(100, 0, false, true) // swapped
fmt.Printf("%v %v %v %v\n", x, y, xe, ye)               //=> 0 100 true false
Output:

0 100 true false
0 100 true false

func MinMaxExclusiveUint16

func MinMaxExclusiveUint16(min, max uint16, minExclusive, maxExclusive bool) (uint16, uint16, bool, bool)

MinMaxExclusiveUint16 swaps min and max as well as minExclusive, maxExclusive correspondingly to assure that min < max together with the interval endings. It is automatically called for all the rest of the functions that expect minExclusive or maxExclusive.

Example
x, y, xe, ye := MinMaxExclusiveUint16(0, 100, true, false)
fmt.Printf("%v %v %v %v\n", x, y, xe, ye)                 //=> 0 100 true false
x, y, xe, ye = MinMaxExclusiveUint16(100, 0, false, true) // swapped
fmt.Printf("%v %v %v %v\n", x, y, xe, ye)                 //=> 0 100 true false
Output:

0 100 true false
0 100 true false

func MinMaxExclusiveUint32

func MinMaxExclusiveUint32(min, max uint32, minExclusive, maxExclusive bool) (uint32, uint32, bool, bool)

MinMaxExclusiveUint32 swaps min and max as well as minExclusive, maxExclusive correspondingly to assure that min < max together with the interval endings. It is automatically called for all the rest of the functions that expect minExclusive or maxExclusive.

Example
x, y, xe, ye := MinMaxExclusiveUint32(0, 100, true, false)
fmt.Printf("%v %v %v %v\n", x, y, xe, ye)                 //=> 0 100 true false
x, y, xe, ye = MinMaxExclusiveUint32(100, 0, false, true) // swapped
fmt.Printf("%v %v %v %v\n", x, y, xe, ye)                 //=> 0 100 true false
Output:

0 100 true false
0 100 true false

func MinMaxExclusiveUint64

func MinMaxExclusiveUint64(min, max uint64, minExclusive, maxExclusive bool) (uint64, uint64, bool, bool)

MinMaxExclusiveUint64 swaps min and max as well as minExclusive, maxExclusive correspondingly to assure that min < max together with the interval endings. It is automatically called for all the rest of the functions that expect minExclusive or maxExclusive.

Example
x, y, xe, ye := MinMaxExclusiveUint64(0, 100, true, false)
fmt.Printf("%v %v %v %v\n", x, y, xe, ye)                 //=> 0 100 true false
x, y, xe, ye = MinMaxExclusiveUint64(100, 0, false, true) // swapped
fmt.Printf("%v %v %v %v\n", x, y, xe, ye)                 //=> 0 100 true false
Output:

0 100 true false
0 100 true false

func MinMaxExclusiveUint8

func MinMaxExclusiveUint8(min, max uint8, minExclusive, maxExclusive bool) (uint8, uint8, bool, bool)

MinMaxExclusiveUint8 swaps min and max as well as minExclusive, maxExclusive correspondingly to assure that min < max together with the interval endings. It is automatically called for all the rest of the functions that expect minExclusive or maxExclusive.

Example
x, y, xe, ye := MinMaxExclusiveUint8(0, 100, true, false)
fmt.Printf("%v %v %v %v\n", x, y, xe, ye)                //=> 0 100 true false
x, y, xe, ye = MinMaxExclusiveUint8(100, 0, false, true) // swapped
fmt.Printf("%v %v %v %v\n", x, y, xe, ye)                //=> 0 100 true false
Output:

0 100 true false
0 100 true false

func MinMaxFloat32

func MinMaxFloat32(min, max float32) (float32, float32)

MinMaxFloat32 swaps min and max to assure that min < max. It is automatically called for all the rest of the functions that do not expect minExclusive or maxExclusive.

Example
x, y := MinMaxFloat32(0, 100)
fmt.Printf("%v %v\n", x, y)  //=> 0 100
x, y = MinMaxFloat32(100, 0) // swapped
fmt.Printf("%v %v\n", x, y)  //=> 0 100
Output:

0 100
0 100

func MinMaxFloat64

func MinMaxFloat64(min, max float64) (float64, float64)

MinMaxFloat64 swaps min and max to assure that min < max. It is automatically called for all the rest of the functions that do not expect minExclusive or maxExclusive.

Example
x, y := MinMaxFloat64(0, 100)
fmt.Printf("%v %v\n", x, y)  //=> 0 100
x, y = MinMaxFloat64(100, 0) // swapped
fmt.Printf("%v %v\n", x, y)  //=> 0 100
Output:

0 100
0 100

func MinMaxInt

func MinMaxInt(min, max int) (int, int)

MinMaxInt swaps min and max to assure that min < max. It is automatically called for all the rest of the functions that do not expect minExclusive or maxExclusive.

Example
x, y := MinMaxInt(0, 100)
fmt.Printf("%v %v\n", x, y) //=> 0 100
x, y = MinMaxInt(100, 0)    // swapped
fmt.Printf("%v %v\n", x, y) //=> 0 100
Output:

0 100
0 100

func MinMaxInt16

func MinMaxInt16(min, max int16) (int16, int16)

MinMaxInt16 swaps min and max to assure that min < max. It is automatically called for all the rest of the functions that do not expect minExclusive or maxExclusive.

Example
x, y := MinMaxInt16(0, 100)
fmt.Printf("%v %v\n", x, y) //=> 0 100
x, y = MinMaxInt16(100, 0)  // swapped
fmt.Printf("%v %v\n", x, y) //=> 0 100
Output:

0 100
0 100

func MinMaxInt32

func MinMaxInt32(min, max int32) (int32, int32)

MinMaxInt32 swaps min and max to assure that min < max. It is automatically called for all the rest of the functions that do not expect minExclusive or maxExclusive.

Example
x, y := MinMaxInt32(0, 100)
fmt.Printf("%v %v\n", x, y) //=> 0 100
x, y = MinMaxInt32(100, 0)  // swapped
fmt.Printf("%v %v\n", x, y) //=> 0 100
Output:

0 100
0 100

func MinMaxInt64

func MinMaxInt64(min, max int64) (int64, int64)

MinMaxInt64 swaps min and max to assure that min < max. It is automatically called for all the rest of the functions that do not expect minExclusive or maxExclusive.

Example
x, y := MinMaxInt64(0, 100)
fmt.Printf("%v %v\n", x, y) //=> 0 100
x, y = MinMaxInt64(100, 0)  // swapped
fmt.Printf("%v %v\n", x, y) //=> 0 100
Output:

0 100
0 100

func MinMaxInt8

func MinMaxInt8(min, max int8) (int8, int8)

MinMaxInt8 swaps min and max to assure that min < max. It is automatically called for all the rest of the functions that do not expect minExclusive or maxExclusive.

Example
x, y := MinMaxInt8(0, 100)
fmt.Printf("%v %v\n", x, y) //=> 0 100
x, y = MinMaxInt8(100, 0)   // swapped
fmt.Printf("%v %v\n", x, y) //=> 0 100
Output:

0 100
0 100

func MinMaxUint

func MinMaxUint(min, max uint) (uint, uint)

MinMaxUint swaps min and max to assure that min < max. It is automatically called for all the rest of the functions that do not expect minExclusive or maxExclusive.

Example
x, y := MinMaxUint(0, 100)
fmt.Printf("%v %v\n", x, y) //=> 0 100
x, y = MinMaxUint(100, 0)   // swapped
fmt.Printf("%v %v\n", x, y) //=> 0 100
Output:

0 100
0 100

func MinMaxUint16

func MinMaxUint16(min, max uint16) (uint16, uint16)

MinMaxUint16 swaps min and max to assure that min < max. It is automatically called for all the rest of the functions that do not expect minExclusive or maxExclusive.

Example
x, y := MinMaxUint16(0, 100)
fmt.Printf("%v %v\n", x, y) //=> 0 100
x, y = MinMaxUint16(100, 0) // swapped
fmt.Printf("%v %v\n", x, y) //=> 0 100
Output:

0 100
0 100

func MinMaxUint32

func MinMaxUint32(min, max uint32) (uint32, uint32)

MinMaxUint32 swaps min and max to assure that min < max. It is automatically called for all the rest of the functions that do not expect minExclusive or maxExclusive.

Example
x, y := MinMaxUint32(0, 100)
fmt.Printf("%v %v\n", x, y) //=> 0 100
x, y = MinMaxUint32(100, 0) // swapped
fmt.Printf("%v %v\n", x, y) //=> 0 100
Output:

0 100
0 100

func MinMaxUint64

func MinMaxUint64(min, max uint64) (uint64, uint64)

MinMaxUint64 swaps min and max to assure that min < max. It is automatically called for all the rest of the functions that do not expect minExclusive or maxExclusive.

Example
x, y := MinMaxUint64(0, 100)
fmt.Printf("%v %v\n", x, y) //=> 0 100
x, y = MinMaxUint64(100, 0) // swapped
fmt.Printf("%v %v\n", x, y) //=> 0 100
Output:

0 100
0 100

func MinMaxUint8

func MinMaxUint8(min, max uint8) (uint8, uint8)

MinMaxUint8 swaps min and max to assure that min < max. It is automatically called for all the rest of the functions that do not expect minExclusive or maxExclusive.

Example
x, y := MinMaxUint8(0, 100)
fmt.Printf("%v %v\n", x, y) //=> 0 100
x, y = MinMaxUint8(100, 0)  // swapped
fmt.Printf("%v %v\n", x, y) //=> 0 100
Output:

0 100
0 100

func MinUint

func MinUint(x, y uint) uint

MinUint returns the smaller of two numbers.

func MinUint16

func MinUint16(x, y uint16) uint16

MinUint16 returns the smaller of two numbers.

func MinUint32

func MinUint32(x, y uint32) uint32

MinUint32 returns the smaller of two numbers.

func MinUint64

func MinUint64(x, y uint64) uint64

MinUint64 returns the smaller of two numbers.

func MinUint8

func MinUint8(x, y uint8) uint8

MinUint8 returns the smaller of two numbers.

func TestFloat32

func TestFloat32(min, max, value float32, minExclusive, maxExclusive bool) bool

TestFloat32 returns true if the value is within [(min,max)] range (depending on minExclusive and maxExclusive).

Example
fmt.Printf("%v\n", TestFloat32(0, 100, 0, false, false))  //=> true
fmt.Printf("%v\n", TestFloat32(0, 100, 0, true, false))   //=> false
fmt.Printf("%v\n", TestFloat32(0, 100, 100, true, false)) //=> true
fmt.Printf("%v\n", TestFloat32(100, 0, 100, false, true)) //=> true
Output:

true
false
true
true

func TestFloat64

func TestFloat64(min, max, value float64, minExclusive, maxExclusive bool) bool

TestFloat64 returns true if the value is within [(min,max)] range (depending on minExclusive and maxExclusive).

Example
fmt.Printf("%v\n", TestFloat64(0, 100, 0, false, false))  //=> true
fmt.Printf("%v\n", TestFloat64(0, 100, 0, true, false))   //=> false
fmt.Printf("%v\n", TestFloat64(0, 100, 100, true, false)) //=> true
fmt.Printf("%v\n", TestFloat64(100, 0, 100, false, true)) //=> true
Output:

true
false
true
true

func TestInt

func TestInt(min, max, value int, minExclusive, maxExclusive bool) bool

TestInt returns true if the value is within [(min,max)] range (depending on minExclusive and maxExclusive).

Example
fmt.Printf("%v\n", TestInt(0, 100, 0, false, false))  //=> true
fmt.Printf("%v\n", TestInt(0, 100, 0, true, false))   //=> false
fmt.Printf("%v\n", TestInt(0, 100, 100, true, false)) //=> true
fmt.Printf("%v\n", TestInt(100, 0, 100, false, true)) //=> true
Output:

true
false
true
true

func TestInt16

func TestInt16(min, max, value int16, minExclusive, maxExclusive bool) bool

TestInt16 returns true if the value is within [(min,max)] range (depending on minExclusive and maxExclusive).

Example
fmt.Printf("%v\n", TestInt16(0, 100, 0, false, false))  //=> true
fmt.Printf("%v\n", TestInt16(0, 100, 0, true, false))   //=> false
fmt.Printf("%v\n", TestInt16(0, 100, 100, true, false)) //=> true
fmt.Printf("%v\n", TestInt16(100, 0, 100, false, true)) //=> true
Output:

true
false
true
true

func TestInt32

func TestInt32(min, max, value int32, minExclusive, maxExclusive bool) bool

TestInt32 returns true if the value is within [(min,max)] range (depending on minExclusive and maxExclusive).

Example
fmt.Printf("%v\n", TestInt32(0, 100, 0, false, false))  //=> true
fmt.Printf("%v\n", TestInt32(0, 100, 0, true, false))   //=> false
fmt.Printf("%v\n", TestInt32(0, 100, 100, true, false)) //=> true
fmt.Printf("%v\n", TestInt32(100, 0, 100, false, true)) //=> true
Output:

true
false
true
true

func TestInt64

func TestInt64(min, max, value int64, minExclusive, maxExclusive bool) bool

TestInt64 returns true if the value is within [(min,max)] range (depending on minExclusive and maxExclusive).

Example
fmt.Printf("%v\n", TestInt64(0, 100, 0, false, false))  //=> true
fmt.Printf("%v\n", TestInt64(0, 100, 0, true, false))   //=> false
fmt.Printf("%v\n", TestInt64(0, 100, 100, true, false)) //=> true
fmt.Printf("%v\n", TestInt64(100, 0, 100, false, true)) //=> true
Output:

true
false
true
true

func TestInt8

func TestInt8(min, max, value int8, minExclusive, maxExclusive bool) bool

TestInt8 returns true if the value is within [(min,max)] range (depending on minExclusive and maxExclusive).

Example
fmt.Printf("%v\n", TestInt8(0, 100, 0, false, false))  //=> true
fmt.Printf("%v\n", TestInt8(0, 100, 0, true, false))   //=> false
fmt.Printf("%v\n", TestInt8(0, 100, 100, true, false)) //=> true
fmt.Printf("%v\n", TestInt8(100, 0, 100, false, true)) //=> true
Output:

true
false
true
true

func TestUint

func TestUint(min, max, value uint, minExclusive, maxExclusive bool) bool

TestUint returns true if the value is within [(min,max)] range (depending on minExclusive and maxExclusive).

Example
fmt.Printf("%v\n", TestUint(0, 100, 0, false, false))  //=> true
fmt.Printf("%v\n", TestUint(0, 100, 0, true, false))   //=> false
fmt.Printf("%v\n", TestUint(0, 100, 100, true, false)) //=> true
fmt.Printf("%v\n", TestUint(100, 0, 100, false, true)) //=> true
Output:

true
false
true
true

func TestUint16

func TestUint16(min, max, value uint16, minExclusive, maxExclusive bool) bool

TestUint16 returns true if the value is within [(min,max)] range (depending on minExclusive and maxExclusive).

Example
fmt.Printf("%v\n", TestUint16(0, 100, 0, false, false))  //=> true
fmt.Printf("%v\n", TestUint16(0, 100, 0, true, false))   //=> false
fmt.Printf("%v\n", TestUint16(0, 100, 100, true, false)) //=> true
fmt.Printf("%v\n", TestUint16(100, 0, 100, false, true)) //=> true
Output:

true
false
true
true

func TestUint32

func TestUint32(min, max, value uint32, minExclusive, maxExclusive bool) bool

TestUint32 returns true if the value is within [(min,max)] range (depending on minExclusive and maxExclusive).

Example
fmt.Printf("%v\n", TestUint32(0, 100, 0, false, false))  //=> true
fmt.Printf("%v\n", TestUint32(0, 100, 0, true, false))   //=> false
fmt.Printf("%v\n", TestUint32(0, 100, 100, true, false)) //=> true
fmt.Printf("%v\n", TestUint32(100, 0, 100, false, true)) //=> true
Output:

true
false
true
true

func TestUint64

func TestUint64(min, max, value uint64, minExclusive, maxExclusive bool) bool

TestUint64 returns true if the value is within [(min,max)] range (depending on minExclusive and maxExclusive).

Example
fmt.Printf("%v\n", TestUint64(0, 100, 0, false, false))  //=> true
fmt.Printf("%v\n", TestUint64(0, 100, 0, true, false))   //=> false
fmt.Printf("%v\n", TestUint64(0, 100, 100, true, false)) //=> true
fmt.Printf("%v\n", TestUint64(100, 0, 100, false, true)) //=> true
Output:

true
false
true
true

func TestUint8

func TestUint8(min, max, value uint8, minExclusive, maxExclusive bool) bool

TestUint8 returns true if the value is within [(min,max)] range (depending on minExclusive and maxExclusive).

Example
fmt.Printf("%v\n", TestUint8(0, 100, 0, false, false))  //=> true
fmt.Printf("%v\n", TestUint8(0, 100, 0, true, false))   //=> false
fmt.Printf("%v\n", TestUint8(0, 100, 100, true, false)) //=> true
fmt.Printf("%v\n", TestUint8(100, 0, 100, false, true)) //=> true
Output:

true
false
true
true

func ToStringFloat32

func ToStringFloat32(min, max float32, minExclusive, maxExclusive bool) string

ToStringFloat32 returns a string representation of the range using range notation (https://en.wikipedia.org/wiki/Interval_(mathematics)#Classification_of_intervals).

Example
fmt.Printf("%v\n", ToStringFloat32(0, 100, true, true))   //=> (0,100)
fmt.Printf("%v\n", ToStringFloat32(0, 100, false, false)) //=> [0,100]
fmt.Printf("%v\n", ToStringFloat32(0, 100, true, false))  //=> (0,100]
fmt.Printf("%v\n", ToStringFloat32(0, 100, false, true))  //=> [0,100)
Output:

(0,100)
[0,100]
(0,100]
[0,100)

func ToStringFloat64

func ToStringFloat64(min, max float64, minExclusive, maxExclusive bool) string

ToStringFloat64 returns a string representation of the range using range notation (https://en.wikipedia.org/wiki/Interval_(mathematics)#Classification_of_intervals).

Example
fmt.Printf("%v\n", ToStringFloat64(0, 100, true, true))   //=> (0,100)
fmt.Printf("%v\n", ToStringFloat64(0, 100, false, false)) //=> [0,100]
fmt.Printf("%v\n", ToStringFloat64(0, 100, true, false))  //=> (0,100]
fmt.Printf("%v\n", ToStringFloat64(0, 100, false, true))  //=> [0,100)
Output:

(0,100)
[0,100]
(0,100]
[0,100)

func ToStringInt

func ToStringInt(min, max int, minExclusive, maxExclusive bool) string

ToStringInt returns a string representation of the range using range notation (https://en.wikipedia.org/wiki/Interval_(mathematics)#Classification_of_intervals).

Example
fmt.Printf("%v\n", ToStringInt(0, 100, true, true))   //=> (0,100)
fmt.Printf("%v\n", ToStringInt(0, 100, false, false)) //=> [0,100]
fmt.Printf("%v\n", ToStringInt(0, 100, true, false))  //=> (0,100]
fmt.Printf("%v\n", ToStringInt(0, 100, false, true))  //=> [0,100)
Output:

(0,100)
[0,100]
(0,100]
[0,100)

func ToStringInt16

func ToStringInt16(min, max int16, minExclusive, maxExclusive bool) string

ToStringInt16 returns a string representation of the range using range notation (https://en.wikipedia.org/wiki/Interval_(mathematics)#Classification_of_intervals).

Example
fmt.Printf("%v\n", ToStringInt16(0, 100, true, true))   //=> (0,100)
fmt.Printf("%v\n", ToStringInt16(0, 100, false, false)) //=> [0,100]
fmt.Printf("%v\n", ToStringInt16(0, 100, true, false))  //=> (0,100]
fmt.Printf("%v\n", ToStringInt16(0, 100, false, true))  //=> [0,100)
Output:

(0,100)
[0,100]
(0,100]
[0,100)

func ToStringInt32

func ToStringInt32(min, max int32, minExclusive, maxExclusive bool) string

ToStringInt32 returns a string representation of the range using range notation (https://en.wikipedia.org/wiki/Interval_(mathematics)#Classification_of_intervals).

Example
fmt.Printf("%v\n", ToStringInt32(0, 100, true, true))   //=> (0,100)
fmt.Printf("%v\n", ToStringInt32(0, 100, false, false)) //=> [0,100]
fmt.Printf("%v\n", ToStringInt32(0, 100, true, false))  //=> (0,100]
fmt.Printf("%v\n", ToStringInt32(0, 100, false, true))  //=> [0,100)
Output:

(0,100)
[0,100]
(0,100]
[0,100)

func ToStringInt64

func ToStringInt64(min, max int64, minExclusive, maxExclusive bool) string

ToStringInt64 returns a string representation of the range using range notation (https://en.wikipedia.org/wiki/Interval_(mathematics)#Classification_of_intervals).

Example
fmt.Printf("%v\n", ToStringInt64(0, 100, true, true))   //=> (0,100)
fmt.Printf("%v\n", ToStringInt64(0, 100, false, false)) //=> [0,100]
fmt.Printf("%v\n", ToStringInt64(0, 100, true, false))  //=> (0,100]
fmt.Printf("%v\n", ToStringInt64(0, 100, false, true))  //=> [0,100)
Output:

(0,100)
[0,100]
(0,100]
[0,100)

func ToStringInt8

func ToStringInt8(min, max int8, minExclusive, maxExclusive bool) string

ToStringInt8 returns a string representation of the range using range notation (https://en.wikipedia.org/wiki/Interval_(mathematics)#Classification_of_intervals).

Example
fmt.Printf("%v\n", ToStringInt8(0, 100, true, true))   //=> (0,100)
fmt.Printf("%v\n", ToStringInt8(0, 100, false, false)) //=> [0,100]
fmt.Printf("%v\n", ToStringInt8(0, 100, true, false))  //=> (0,100]
fmt.Printf("%v\n", ToStringInt8(0, 100, false, true))  //=> [0,100)
Output:

(0,100)
[0,100]
(0,100]
[0,100)

func ToStringUint

func ToStringUint(min, max uint, minExclusive, maxExclusive bool) string

ToStringUint returns a string representation of the range using range notation (https://en.wikipedia.org/wiki/Interval_(mathematics)#Classification_of_intervals).

Example
fmt.Printf("%v\n", ToStringUint(0, 100, true, true))   //=> (0,100)
fmt.Printf("%v\n", ToStringUint(0, 100, false, false)) //=> [0,100]
fmt.Printf("%v\n", ToStringUint(0, 100, true, false))  //=> (0,100]
fmt.Printf("%v\n", ToStringUint(0, 100, false, true))  //=> [0,100)
Output:

(0,100)
[0,100]
(0,100]
[0,100)

func ToStringUint16

func ToStringUint16(min, max uint16, minExclusive, maxExclusive bool) string

ToStringUint16 returns a string representation of the range using range notation (https://en.wikipedia.org/wiki/Interval_(mathematics)#Classification_of_intervals).

Example
fmt.Printf("%v\n", ToStringUint16(0, 100, true, true))   //=> (0,100)
fmt.Printf("%v\n", ToStringUint16(0, 100, false, false)) //=> [0,100]
fmt.Printf("%v\n", ToStringUint16(0, 100, true, false))  //=> (0,100]
fmt.Printf("%v\n", ToStringUint16(0, 100, false, true))  //=> [0,100)
Output:

(0,100)
[0,100]
(0,100]
[0,100)

func ToStringUint32

func ToStringUint32(min, max uint32, minExclusive, maxExclusive bool) string

ToStringUint32 returns a string representation of the range using range notation (https://en.wikipedia.org/wiki/Interval_(mathematics)#Classification_of_intervals).

Example
fmt.Printf("%v\n", ToStringUint32(0, 100, true, true))   //=> (0,100)
fmt.Printf("%v\n", ToStringUint32(0, 100, false, false)) //=> [0,100]
fmt.Printf("%v\n", ToStringUint32(0, 100, true, false))  //=> (0,100]
fmt.Printf("%v\n", ToStringUint32(0, 100, false, true))  //=> [0,100)
Output:

(0,100)
[0,100]
(0,100]
[0,100)

func ToStringUint64

func ToStringUint64(min, max uint64, minExclusive, maxExclusive bool) string

ToStringUint64 returns a string representation of the range using range notation (https://en.wikipedia.org/wiki/Interval_(mathematics)#Classification_of_intervals).

Example
fmt.Printf("%v\n", ToStringUint64(0, 100, true, true))   //=> (0,100)
fmt.Printf("%v\n", ToStringUint64(0, 100, false, false)) //=> [0,100]
fmt.Printf("%v\n", ToStringUint64(0, 100, true, false))  //=> (0,100]
fmt.Printf("%v\n", ToStringUint64(0, 100, false, true))  //=> [0,100)
Output:

(0,100)
[0,100]
(0,100]
[0,100)

func ToStringUint8

func ToStringUint8(min, max uint8, minExclusive, maxExclusive bool) string

ToStringUint8 returns a string representation of the range using range notation (https://en.wikipedia.org/wiki/Interval_(mathematics)#Classification_of_intervals).

Example
fmt.Printf("%v\n", ToStringUint8(0, 100, true, true))   //=> (0,100)
fmt.Printf("%v\n", ToStringUint8(0, 100, false, false)) //=> [0,100]
fmt.Printf("%v\n", ToStringUint8(0, 100, true, false))  //=> (0,100]
fmt.Printf("%v\n", ToStringUint8(0, 100, false, true))  //=> [0,100)
Output:

(0,100)
[0,100]
(0,100]
[0,100)

func ValidateFloat32

func ValidateFloat32(min, max, value float32, minExclusive, maxExclusive bool) (float32, error)

ValidateFloat32 tests whether the value is within [(min,max)] range (depending on minExclusive and maxExclusive). It returns the value if it is within the range, otherwise returns 0 and error.

Example
fmt.Println(ValidateFloat32(0, 100, 0, false, false))   //=> 0 <nil>
fmt.Println(ValidateFloat32(0, 100, 0, true, false))    //=> 0 0 is outside of range [0, 100)
fmt.Println(ValidateFloat32(0, 100, 100, true, false))  //=> 100 <nil>
fmt.Println(ValidateFloat32(0, 100, 101, false, false)) //=> 0 101 is outside of range [0,100]
fmt.Println(ValidateFloat32(0, 100, 100, true, true))   //=> 0 100 is outside of range (0,100)
Output:

0 <nil>
0 0 is outside of range (0,100]
100 <nil>
0 101 is outside of range [0,100]
0 100 is outside of range (0,100)

func ValidateFloat64

func ValidateFloat64(min, max, value float64, minExclusive, maxExclusive bool) (float64, error)

ValidateFloat64 tests whether the value is within [(min,max)] range (depending on minExclusive and maxExclusive). It returns the value if it is within the range, otherwise returns 0 and error.

Example
fmt.Println(ValidateFloat64(0, 100, 0, false, false))   //=> 0 <nil>
fmt.Println(ValidateFloat64(0, 100, 0, true, false))    //=> 0 0 is outside of range [0, 100)
fmt.Println(ValidateFloat64(0, 100, 100, true, false))  //=> 100 <nil>
fmt.Println(ValidateFloat64(0, 100, 101, false, false)) //=> 0 101 is outside of range [0,100]
fmt.Println(ValidateFloat64(0, 100, 100, true, true))   //=> 0 100 is outside of range (0,100)
Output:

0 <nil>
0 0 is outside of range (0,100]
100 <nil>
0 101 is outside of range [0,100]
0 100 is outside of range (0,100)

func ValidateInt

func ValidateInt(min, max, value int, minExclusive, maxExclusive bool) (int, error)

ValidateInt tests whether the value is within [(min,max)] range (depending on minExclusive and maxExclusive). It returns the value if it is within the range, otherwise returns 0 and error.

Example
fmt.Println(ValidateInt(0, 100, 0, false, false))   //=> 0 <nil>
fmt.Println(ValidateInt(0, 100, 0, true, false))    //=> 0 0 is outside of range [0, 100)
fmt.Println(ValidateInt(0, 100, 100, true, false))  //=> 100 <nil>
fmt.Println(ValidateInt(0, 100, 101, false, false)) //=> 0 101 is outside of range [0,100]
fmt.Println(ValidateInt(0, 100, 100, true, true))   //=> 0 100 is outside of range (0,100)
Output:

0 <nil>
0 0 is outside of range (0,100]
100 <nil>
0 101 is outside of range [0,100]
0 100 is outside of range (0,100)

func ValidateInt16

func ValidateInt16(min, max, value int16, minExclusive, maxExclusive bool) (int16, error)

ValidateInt16 tests whether the value is within [(min,max)] range (depending on minExclusive and maxExclusive). It returns the value if it is within the range, otherwise returns 0 and error.

Example
fmt.Println(ValidateInt16(0, 100, 0, false, false))   //=> 0 <nil>
fmt.Println(ValidateInt16(0, 100, 0, true, false))    //=> 0 0 is outside of range [0, 100)
fmt.Println(ValidateInt16(0, 100, 100, true, false))  //=> 100 <nil>
fmt.Println(ValidateInt16(0, 100, 101, false, false)) //=> 0 101 is outside of range [0,100]
fmt.Println(ValidateInt16(0, 100, 100, true, true))   //=> 0 100 is outside of range (0,100)
Output:

0 <nil>
0 0 is outside of range (0,100]
100 <nil>
0 101 is outside of range [0,100]
0 100 is outside of range (0,100)

func ValidateInt32

func ValidateInt32(min, max, value int32, minExclusive, maxExclusive bool) (int32, error)

ValidateInt32 tests whether the value is within [(min,max)] range (depending on minExclusive and maxExclusive). It returns the value if it is within the range, otherwise returns 0 and error.

Example
fmt.Println(ValidateInt32(0, 100, 0, false, false))   //=> 0 <nil>
fmt.Println(ValidateInt32(0, 100, 0, true, false))    //=> 0 0 is outside of range [0, 100)
fmt.Println(ValidateInt32(0, 100, 100, true, false))  //=> 100 <nil>
fmt.Println(ValidateInt32(0, 100, 101, false, false)) //=> 0 101 is outside of range [0,100]
fmt.Println(ValidateInt32(0, 100, 100, true, true))   //=> 0 100 is outside of range (0,100)
Output:

0 <nil>
0 0 is outside of range (0,100]
100 <nil>
0 101 is outside of range [0,100]
0 100 is outside of range (0,100)

func ValidateInt64

func ValidateInt64(min, max, value int64, minExclusive, maxExclusive bool) (int64, error)

ValidateInt64 tests whether the value is within [(min,max)] range (depending on minExclusive and maxExclusive). It returns the value if it is within the range, otherwise returns 0 and error.

Example
fmt.Println(ValidateInt64(0, 100, 0, false, false))   //=> 0 <nil>
fmt.Println(ValidateInt64(0, 100, 0, true, false))    //=> 0 0 is outside of range [0, 100)
fmt.Println(ValidateInt64(0, 100, 100, true, false))  //=> 100 <nil>
fmt.Println(ValidateInt64(0, 100, 101, false, false)) //=> 0 101 is outside of range [0,100]
fmt.Println(ValidateInt64(0, 100, 100, true, true))   //=> 0 100 is outside of range (0,100)
Output:

0 <nil>
0 0 is outside of range (0,100]
100 <nil>
0 101 is outside of range [0,100]
0 100 is outside of range (0,100)

func ValidateInt8

func ValidateInt8(min, max, value int8, minExclusive, maxExclusive bool) (int8, error)

ValidateInt8 tests whether the value is within [(min,max)] range (depending on minExclusive and maxExclusive). It returns the value if it is within the range, otherwise returns 0 and error.

Example
fmt.Println(ValidateInt8(0, 100, 0, false, false))   //=> 0 <nil>
fmt.Println(ValidateInt8(0, 100, 0, true, false))    //=> 0 0 is outside of range [0, 100)
fmt.Println(ValidateInt8(0, 100, 100, true, false))  //=> 100 <nil>
fmt.Println(ValidateInt8(0, 100, 101, false, false)) //=> 0 101 is outside of range [0,100]
fmt.Println(ValidateInt8(0, 100, 100, true, true))   //=> 0 100 is outside of range (0,100)
Output:

0 <nil>
0 0 is outside of range (0,100]
100 <nil>
0 101 is outside of range [0,100]
0 100 is outside of range (0,100)

func ValidateUint

func ValidateUint(min, max, value uint, minExclusive, maxExclusive bool) (uint, error)

ValidateUint tests whether the value is within [(min,max)] range (depending on minExclusive and maxExclusive). It returns the value if it is within the range, otherwise returns 0 and error.

Example
fmt.Println(ValidateUint(0, 100, 0, false, false))   //=> 0 <nil>
fmt.Println(ValidateUint(0, 100, 0, true, false))    //=> 0 0 is outside of range [0, 100)
fmt.Println(ValidateUint(0, 100, 100, true, false))  //=> 100 <nil>
fmt.Println(ValidateUint(0, 100, 101, false, false)) //=> 0 101 is outside of range [0,100]
fmt.Println(ValidateUint(0, 100, 100, true, true))   //=> 0 100 is outside of range (0,100)
Output:

0 <nil>
0 0 is outside of range (0,100]
100 <nil>
0 101 is outside of range [0,100]
0 100 is outside of range (0,100)

func ValidateUint16

func ValidateUint16(min, max, value uint16, minExclusive, maxExclusive bool) (uint16, error)

ValidateUint16 tests whether the value is within [(min,max)] range (depending on minExclusive and maxExclusive). It returns the value if it is within the range, otherwise returns 0 and error.

Example
fmt.Println(ValidateUint16(0, 100, 0, false, false))   //=> 0 <nil>
fmt.Println(ValidateUint16(0, 100, 0, true, false))    //=> 0 0 is outside of range [0, 100)
fmt.Println(ValidateUint16(0, 100, 100, true, false))  //=> 100 <nil>
fmt.Println(ValidateUint16(0, 100, 101, false, false)) //=> 0 101 is outside of range [0,100]
fmt.Println(ValidateUint16(0, 100, 100, true, true))   //=> 0 100 is outside of range (0,100)
Output:

0 <nil>
0 0 is outside of range (0,100]
100 <nil>
0 101 is outside of range [0,100]
0 100 is outside of range (0,100)

func ValidateUint32

func ValidateUint32(min, max, value uint32, minExclusive, maxExclusive bool) (uint32, error)

ValidateUint32 tests whether the value is within [(min,max)] range (depending on minExclusive and maxExclusive). It returns the value if it is within the range, otherwise returns 0 and error.

Example
fmt.Println(ValidateUint32(0, 100, 0, false, false))   //=> 0 <nil>
fmt.Println(ValidateUint32(0, 100, 0, true, false))    //=> 0 0 is outside of range [0, 100)
fmt.Println(ValidateUint32(0, 100, 100, true, false))  //=> 100 <nil>
fmt.Println(ValidateUint32(0, 100, 101, false, false)) //=> 0 101 is outside of range [0,100]
fmt.Println(ValidateUint32(0, 100, 100, true, true))   //=> 0 100 is outside of range (0,100)
Output:

0 <nil>
0 0 is outside of range (0,100]
100 <nil>
0 101 is outside of range [0,100]
0 100 is outside of range (0,100)

func ValidateUint64

func ValidateUint64(min, max, value uint64, minExclusive, maxExclusive bool) (uint64, error)

ValidateUint64 tests whether the value is within [(min,max)] range (depending on minExclusive and maxExclusive). It returns the value if it is within the range, otherwise returns 0 and error.

Example
fmt.Println(ValidateUint64(0, 100, 0, false, false))   //=> 0 <nil>
fmt.Println(ValidateUint64(0, 100, 0, true, false))    //=> 0 0 is outside of range [0, 100)
fmt.Println(ValidateUint64(0, 100, 100, true, false))  //=> 100 <nil>
fmt.Println(ValidateUint64(0, 100, 101, false, false)) //=> 0 101 is outside of range [0,100]
fmt.Println(ValidateUint64(0, 100, 100, true, true))   //=> 0 100 is outside of range (0,100)
Output:

0 <nil>
0 0 is outside of range (0,100]
100 <nil>
0 101 is outside of range [0,100]
0 100 is outside of range (0,100)

func ValidateUint8

func ValidateUint8(min, max, value uint8, minExclusive, maxExclusive bool) (uint8, error)

ValidateUint8 tests whether the value is within [(min,max)] range (depending on minExclusive and maxExclusive). It returns the value if it is within the range, otherwise returns 0 and error.

Example
fmt.Println(ValidateUint8(0, 100, 0, false, false))   //=> 0 <nil>
fmt.Println(ValidateUint8(0, 100, 0, true, false))    //=> 0 0 is outside of range [0, 100)
fmt.Println(ValidateUint8(0, 100, 100, true, false))  //=> 100 <nil>
fmt.Println(ValidateUint8(0, 100, 101, false, false)) //=> 0 101 is outside of range [0,100]
fmt.Println(ValidateUint8(0, 100, 100, true, true))   //=> 0 100 is outside of range (0,100)
Output:

0 <nil>
0 0 is outside of range (0,100]
100 <nil>
0 101 is outside of range [0,100]
0 100 is outside of range (0,100)

func WrapFloat32

func WrapFloat32(min, max, value float32) float32

WrapFloat32 normalizes the value that "wraps around" within the [min,max) range. WrapFloat32 always assumes that `min` is [inclusive, and `max` is exclusive).

Example
fmt.Printf("%v\n", WrapFloat32(0, 100, 120))   //=> 20
fmt.Printf("%v\n", WrapFloat32(100, 0, 120))   //=> 20 (swapped range is fine)
fmt.Printf("%v\n", WrapFloat32(0, 100, 0))     //=> 0
fmt.Printf("%v\n", WrapFloat32(0, 100, 100))   //=> 0
fmt.Printf("%v\n", WrapFloat32(0, 100, 101))   //=> 1
fmt.Printf("%v\n", WrapFloat32(50, 100, 120))  //=> 70
fmt.Printf("%v\n", WrapFloat32(50, 100, 10))   //=> 60
fmt.Printf("%v\n", WrapFloat32(0, 100, -10))   //=> 90
fmt.Printf("%v\n", WrapFloat32(0, 360, 361.5)) //=> 1.5
fmt.Printf("%v\n", WrapFloat32(0, 360, -100))  //=> 260
fmt.Printf("%v\n", WrapFloat32(0, 360, -720))  //=> 0
fmt.Printf("%v\n", WrapFloat32(0, 360, 720.5)) //=> 0.5
Output:

20
20
0
0
1
70
60
90
1.5
260
0
0.5

func WrapFloat64

func WrapFloat64(min, max, value float64) float64

WrapFloat64 normalizes the value that "wraps around" within the [min,max) range. WrapFloat64 always assumes that `min` is [inclusive, and `max` is exclusive).

Example
fmt.Printf("%v\n", WrapFloat64(0, 100, 120))   //=> 20
fmt.Printf("%v\n", WrapFloat64(100, 0, 120))   //=> 20 (swapped range is fine)
fmt.Printf("%v\n", WrapFloat64(0, 100, 0))     //=> 0
fmt.Printf("%v\n", WrapFloat64(0, 100, 100))   //=> 0
fmt.Printf("%v\n", WrapFloat64(0, 100, 101))   //=> 1
fmt.Printf("%v\n", WrapFloat64(50, 100, 120))  //=> 70
fmt.Printf("%v\n", WrapFloat64(50, 100, 10))   //=> 60
fmt.Printf("%v\n", WrapFloat64(0, 100, -10))   //=> 90
fmt.Printf("%v\n", WrapFloat64(0, 360, 361.5)) //=> 1.5
fmt.Printf("%v\n", WrapFloat64(0, 360, -100))  //=> 260
fmt.Printf("%v\n", WrapFloat64(0, 360, -720))  //=> 0
fmt.Printf("%v\n", WrapFloat64(0, 360, 720.5)) //=> 0.5
Output:

20
20
0
0
1
70
60
90
1.5
260
0
0.5

func WrapInt

func WrapInt(min, max, value int) int

WrapInt normalizes the value that "wraps around" within the [min,max) range. WrapInt always assumes that `min` is [inclusive, and `max` is exclusive).

Example
fmt.Printf("%v\n", WrapInt(0, 100, 120))  //=> 20
fmt.Printf("%v\n", WrapInt(100, 0, 120))  //=> 20 (swapped range is fine)
fmt.Printf("%v\n", WrapInt(0, 100, 0))    //=> 0
fmt.Printf("%v\n", WrapInt(0, 100, 100))  //=> 0
fmt.Printf("%v\n", WrapInt(0, 100, 101))  //=> 1
fmt.Printf("%v\n", WrapInt(50, 100, 120)) //=> 70
fmt.Printf("%v\n", WrapInt(50, 100, 10))  //=> 60
fmt.Printf("%v\n", WrapInt(0, 100, -10))  //=> 90
Output:

20
20
0
0
1
70
60
90

func WrapInt16

func WrapInt16(min, max, value int16) int16

WrapInt16 normalizes the value that "wraps around" within the [min,max) range. WrapInt16 always assumes that `min` is [inclusive, and `max` is exclusive).

Example
fmt.Printf("%v\n", WrapInt16(0, 100, 120))  //=> 20
fmt.Printf("%v\n", WrapInt16(100, 0, 120))  //=> 20 (swapped range is fine)
fmt.Printf("%v\n", WrapInt16(0, 100, 0))    //=> 0
fmt.Printf("%v\n", WrapInt16(0, 100, 100))  //=> 0
fmt.Printf("%v\n", WrapInt16(0, 100, 101))  //=> 1
fmt.Printf("%v\n", WrapInt16(50, 100, 120)) //=> 70
fmt.Printf("%v\n", WrapInt16(50, 100, 10))  //=> 60
fmt.Printf("%v\n", WrapInt16(0, 100, -10))  //=> 90
Output:

20
20
0
0
1
70
60
90

func WrapInt32

func WrapInt32(min, max, value int32) int32

WrapInt32 normalizes the value that "wraps around" within the [min,max) range. WrapInt32 always assumes that `min` is [inclusive, and `max` is exclusive).

Example
fmt.Printf("%v\n", WrapInt32(0, 100, 120))  //=> 20
fmt.Printf("%v\n", WrapInt32(100, 0, 120))  //=> 20 (swapped range is fine)
fmt.Printf("%v\n", WrapInt32(0, 100, 0))    //=> 0
fmt.Printf("%v\n", WrapInt32(0, 100, 100))  //=> 0
fmt.Printf("%v\n", WrapInt32(0, 100, 101))  //=> 1
fmt.Printf("%v\n", WrapInt32(50, 100, 120)) //=> 70
fmt.Printf("%v\n", WrapInt32(50, 100, 10))  //=> 60
fmt.Printf("%v\n", WrapInt32(0, 100, -10))  //=> 90
Output:

20
20
0
0
1
70
60
90

func WrapInt64

func WrapInt64(min, max, value int64) int64

WrapInt64 normalizes the value that "wraps around" within the [min,max) range. WrapInt64 always assumes that `min` is [inclusive, and `max` is exclusive).

Example
fmt.Printf("%v\n", WrapInt64(0, 100, 120))  //=> 20
fmt.Printf("%v\n", WrapInt64(100, 0, 120))  //=> 20 (swapped range is fine)
fmt.Printf("%v\n", WrapInt64(0, 100, 0))    //=> 0
fmt.Printf("%v\n", WrapInt64(0, 100, 100))  //=> 0
fmt.Printf("%v\n", WrapInt64(0, 100, 101))  //=> 1
fmt.Printf("%v\n", WrapInt64(50, 100, 120)) //=> 70
fmt.Printf("%v\n", WrapInt64(50, 100, 10))  //=> 60
fmt.Printf("%v\n", WrapInt64(0, 100, -10))  //=> 90
Output:

20
20
0
0
1
70
60
90

func WrapInt8

func WrapInt8(min, max, value int8) int8

WrapInt8 normalizes the value that "wraps around" within the [min,max) range. WrapInt8 always assumes that `min` is [inclusive, and `max` is exclusive).

Example
fmt.Printf("%v\n", WrapInt8(0, 100, 120))  //=> 20
fmt.Printf("%v\n", WrapInt8(100, 0, 120))  //=> 20 (swapped range is fine)
fmt.Printf("%v\n", WrapInt8(0, 100, 0))    //=> 0
fmt.Printf("%v\n", WrapInt8(0, 100, 100))  //=> 0
fmt.Printf("%v\n", WrapInt8(0, 100, 101))  //=> 1
fmt.Printf("%v\n", WrapInt8(50, 100, 120)) //=> 70
fmt.Printf("%v\n", WrapInt8(50, 100, 10))  //=> 60
fmt.Printf("%v\n", WrapInt8(0, 100, -10))  //=> 90
Output:

20
20
0
0
1
70
60
90

func WrapUint

func WrapUint(min, max, value uint) uint

WrapUint normalizes the value that "wraps around" within the [min,max) range. WrapUint always assumes that `min` is [inclusive, and `max` is exclusive).

Example
fmt.Printf("%v\n", WrapUint(0, 100, 120))  //=> 20
fmt.Printf("%v\n", WrapUint(100, 0, 120))  //=> 20 (swapped range is fine)
fmt.Printf("%v\n", WrapUint(0, 100, 0))    //=> 0
fmt.Printf("%v\n", WrapUint(0, 100, 100))  //=> 0
fmt.Printf("%v\n", WrapUint(0, 100, 101))  //=> 1
fmt.Printf("%v\n", WrapUint(50, 100, 120)) //=> 70
fmt.Printf("%v\n", WrapUint(50, 100, 10))  //=> 60
Output:

20
20
0
0
1
70
60

func WrapUint16

func WrapUint16(min, max, value uint16) uint16

WrapUint16 normalizes the value that "wraps around" within the [min,max) range. WrapUint16 always assumes that `min` is [inclusive, and `max` is exclusive).

Example
fmt.Printf("%v\n", WrapUint16(0, 100, 120))  //=> 20
fmt.Printf("%v\n", WrapUint16(100, 0, 120))  //=> 20 (swapped range is fine)
fmt.Printf("%v\n", WrapUint16(0, 100, 0))    //=> 0
fmt.Printf("%v\n", WrapUint16(0, 100, 100))  //=> 0
fmt.Printf("%v\n", WrapUint16(0, 100, 101))  //=> 1
fmt.Printf("%v\n", WrapUint16(50, 100, 120)) //=> 70
fmt.Printf("%v\n", WrapUint16(50, 100, 10))  //=> 60
Output:

20
20
0
0
1
70
60

func WrapUint32

func WrapUint32(min, max, value uint32) uint32

WrapUint32 normalizes the value that "wraps around" within the [min,max) range. WrapUint32 always assumes that `min` is [inclusive, and `max` is exclusive).

Example
fmt.Printf("%v\n", WrapUint32(0, 100, 120))  //=> 20
fmt.Printf("%v\n", WrapUint32(100, 0, 120))  //=> 20 (swapped range is fine)
fmt.Printf("%v\n", WrapUint32(0, 100, 0))    //=> 0
fmt.Printf("%v\n", WrapUint32(0, 100, 100))  //=> 0
fmt.Printf("%v\n", WrapUint32(0, 100, 101))  //=> 1
fmt.Printf("%v\n", WrapUint32(50, 100, 120)) //=> 70
fmt.Printf("%v\n", WrapUint32(50, 100, 10))  //=> 60
Output:

20
20
0
0
1
70
60

func WrapUint64

func WrapUint64(min, max, value uint64) uint64

WrapUint64 normalizes the value that "wraps around" within the [min,max) range. WrapUint64 always assumes that `min` is [inclusive, and `max` is exclusive).

Example
fmt.Printf("%v\n", WrapUint64(0, 100, 120))  //=> 20
fmt.Printf("%v\n", WrapUint64(100, 0, 120))  //=> 20 (swapped range is fine)
fmt.Printf("%v\n", WrapUint64(0, 100, 0))    //=> 0
fmt.Printf("%v\n", WrapUint64(0, 100, 100))  //=> 0
fmt.Printf("%v\n", WrapUint64(0, 100, 101))  //=> 1
fmt.Printf("%v\n", WrapUint64(50, 100, 120)) //=> 70
fmt.Printf("%v\n", WrapUint64(50, 100, 10))  //=> 60
Output:

20
20
0
0
1
70
60

func WrapUint8

func WrapUint8(min, max, value uint8) uint8

WrapUint8 normalizes the value that "wraps around" within the [min,max) range. WrapUint8 always assumes that `min` is [inclusive, and `max` is exclusive).

Example
fmt.Printf("%v\n", WrapUint8(0, 100, 120))  //=> 20
fmt.Printf("%v\n", WrapUint8(100, 0, 120))  //=> 20 (swapped range is fine)
fmt.Printf("%v\n", WrapUint8(0, 100, 0))    //=> 0
fmt.Printf("%v\n", WrapUint8(0, 100, 100))  //=> 0
fmt.Printf("%v\n", WrapUint8(0, 100, 101))  //=> 1
fmt.Printf("%v\n", WrapUint8(50, 100, 120)) //=> 70
fmt.Printf("%v\n", WrapUint8(50, 100, 10))  //=> 60
Output:

20
20
0
0
1
70
60

Types

type RangeFloat32

type RangeFloat32 struct {
	// contains filtered or unexported fields
}

RangeFloat32 represents a struct containing all the fields defining a range.

Example
r := NewRangeFloat32(10, 100, false, false)
fmt.Println(r.Wrap(120))                  //=> 30
fmt.Println(r.Validate(120))              //=> (0, error(120 is outside of range [0,100]))
fmt.Println(r.Test(120))                  //=> false
fmt.Println(r)                            //=> [0,100] (uses Stringer interface)
r = NewRangeFloat32(100, 10, false, true) // swapped
fmt.Println(r.Wrap(120))                  //=> 30
fmt.Println(r.Validate(120))              //=> (0, error(120 is outside of range (0,100]))
fmt.Println(r.Test(120))                  //=> false
fmt.Println(r.Clamp(120))                 //=> 100
fmt.Println(r.Clamp(0))                   //=> 10
fmt.Println(r)                            //=> (0,100] (uses Stringer interface)
Output:

30
0 120 is outside of range [10,100]
false
[10,100]
30
0 120 is outside of range (10,100]
false
100
10
(10,100]

func NewRangeFloat32

func NewRangeFloat32(min float32, max float32, minExclusive bool, maxExclusive bool) *RangeFloat32

NewRangeFloat32 makes a new Range and returns its pointer. RangeFloat32 can also be created with a RangeFloat32{...} literal or new(RangeFloat32).

func (RangeFloat32) Clamp

func (v RangeFloat32) Clamp(value float32) float32

Clamp does not obey minExclusive and maxExclusive and always assumes [min,max] range.

func (RangeFloat32) String added in v0.0.2

func (v RangeFloat32) String() string

String returns a string representation of the range using range notation (https://en.wikipedia.org/wiki/Interval_(mathematics)#Classification_of_intervals). String implements Stringer interface.

func (RangeFloat32) Test

func (v RangeFloat32) Test(value float32) bool

Test returns true if the value is within [(min,max)] range (depending on minExclusive and maxExclusive).

func (RangeFloat32) Validate

func (v RangeFloat32) Validate(value float32) (float32, error)

Validate tests whether the value is within [(min,max)] range (depending on minExclusive and maxExclusive). It returns the value if it is within the range, otherwise returns 0 and error.

func (RangeFloat32) Wrap

func (v RangeFloat32) Wrap(value float32) float32

Wrap does not obey minExclusive and maxExclusive and always assumes [min,max) range.

type RangeFloat64

type RangeFloat64 struct {
	// contains filtered or unexported fields
}

RangeFloat64 represents a struct containing all the fields defining a range.

Example
r := NewRangeFloat64(10, 100, false, false)
fmt.Println(r.Wrap(120))                  //=> 30
fmt.Println(r.Validate(120))              //=> (0, error(120 is outside of range [0,100]))
fmt.Println(r.Test(120))                  //=> false
fmt.Println(r)                            //=> [0,100] (uses Stringer interface)
r = NewRangeFloat64(100, 10, false, true) // swapped
fmt.Println(r.Wrap(120))                  //=> 30
fmt.Println(r.Validate(120))              //=> (0, error(120 is outside of range (0,100]))
fmt.Println(r.Test(120))                  //=> false
fmt.Println(r.Clamp(120))                 //=> 100
fmt.Println(r.Clamp(0))                   //=> 10
fmt.Println(r)                            //=> (0,100] (uses Stringer interface)
Output:

30
0 120 is outside of range [10,100]
false
[10,100]
30
0 120 is outside of range (10,100]
false
100
10
(10,100]

func NewRangeFloat64

func NewRangeFloat64(min float64, max float64, minExclusive bool, maxExclusive bool) *RangeFloat64

NewRangeFloat64 makes a new Range and returns its pointer. RangeFloat64 can also be created with a RangeFloat64{...} literal or new(RangeFloat64).

func (RangeFloat64) Clamp

func (v RangeFloat64) Clamp(value float64) float64

Clamp does not obey minExclusive and maxExclusive and always assumes [min,max] range.

func (RangeFloat64) String added in v0.0.2

func (v RangeFloat64) String() string

String returns a string representation of the range using range notation (https://en.wikipedia.org/wiki/Interval_(mathematics)#Classification_of_intervals). String implements Stringer interface.

func (RangeFloat64) Test

func (v RangeFloat64) Test(value float64) bool

Test returns true if the value is within [(min,max)] range (depending on minExclusive and maxExclusive).

func (RangeFloat64) Validate

func (v RangeFloat64) Validate(value float64) (float64, error)

Validate tests whether the value is within [(min,max)] range (depending on minExclusive and maxExclusive). It returns the value if it is within the range, otherwise returns 0 and error.

func (RangeFloat64) Wrap

func (v RangeFloat64) Wrap(value float64) float64

Wrap does not obey minExclusive and maxExclusive and always assumes [min,max) range.

type RangeInt

type RangeInt struct {
	// contains filtered or unexported fields
}

RangeInt represents a struct containing all the fields defining a range.

Example
r := NewRangeInt(10, 100, false, false)
fmt.Println(r.Wrap(120))              //=> 30
fmt.Println(r.Validate(120))          //=> (0, error(120 is outside of range [0,100]))
fmt.Println(r.Test(120))              //=> false
fmt.Println(r)                        //=> [0,100] (uses Stringer interface)
r = NewRangeInt(100, 10, false, true) // swapped
fmt.Println(r.Wrap(120))              //=> 30
fmt.Println(r.Validate(120))          //=> (0, error(120 is outside of range (0,100]))
fmt.Println(r.Test(120))              //=> false
fmt.Println(r.Clamp(120))             //=> 100
fmt.Println(r.Clamp(0))               //=> 10
fmt.Println(r)                        //=> (0,100] (uses Stringer interface)
Output:

30
0 120 is outside of range [10,100]
false
[10,100]
30
0 120 is outside of range (10,100]
false
100
10
(10,100]

func NewRangeInt

func NewRangeInt(min int, max int, minExclusive bool, maxExclusive bool) *RangeInt

NewRangeInt makes a new Range and returns its pointer. RangeInt can also be created with a RangeInt{...} literal or new(RangeInt).

func (RangeInt) Clamp

func (v RangeInt) Clamp(value int) int

Clamp does not obey minExclusive and maxExclusive and always assumes [min,max] range.

func (RangeInt) String added in v0.0.2

func (v RangeInt) String() string

String returns a string representation of the range using range notation (https://en.wikipedia.org/wiki/Interval_(mathematics)#Classification_of_intervals). String implements Stringer interface.

func (RangeInt) Test

func (v RangeInt) Test(value int) bool

Test returns true if the value is within [(min,max)] range (depending on minExclusive and maxExclusive).

func (RangeInt) Validate

func (v RangeInt) Validate(value int) (int, error)

Validate tests whether the value is within [(min,max)] range (depending on minExclusive and maxExclusive). It returns the value if it is within the range, otherwise returns 0 and error.

func (RangeInt) Wrap

func (v RangeInt) Wrap(value int) int

Wrap does not obey minExclusive and maxExclusive and always assumes [min,max) range.

type RangeInt16

type RangeInt16 struct {
	// contains filtered or unexported fields
}

RangeInt16 represents a struct containing all the fields defining a range.

Example
r := NewRangeInt16(10, 100, false, false)
fmt.Println(r.Wrap(120))                //=> 30
fmt.Println(r.Validate(120))            //=> (0, error(120 is outside of range [0,100]))
fmt.Println(r.Test(120))                //=> false
fmt.Println(r)                          //=> [0,100] (uses Stringer interface)
r = NewRangeInt16(100, 10, false, true) // swapped
fmt.Println(r.Wrap(120))                //=> 30
fmt.Println(r.Validate(120))            //=> (0, error(120 is outside of range (0,100]))
fmt.Println(r.Test(120))                //=> false
fmt.Println(r.Clamp(120))               //=> 100
fmt.Println(r.Clamp(0))                 //=> 10
fmt.Println(r)                          //=> (0,100] (uses Stringer interface)
Output:

30
0 120 is outside of range [10,100]
false
[10,100]
30
0 120 is outside of range (10,100]
false
100
10
(10,100]

func NewRangeInt16

func NewRangeInt16(min int16, max int16, minExclusive bool, maxExclusive bool) *RangeInt16

NewRangeInt16 makes a new Range and returns its pointer. RangeInt16 can also be created with a RangeInt16{...} literal or new(RangeInt16).

func (RangeInt16) Clamp

func (v RangeInt16) Clamp(value int16) int16

Clamp does not obey minExclusive and maxExclusive and always assumes [min,max] range.

func (RangeInt16) String added in v0.0.2

func (v RangeInt16) String() string

String returns a string representation of the range using range notation (https://en.wikipedia.org/wiki/Interval_(mathematics)#Classification_of_intervals). String implements Stringer interface.

func (RangeInt16) Test

func (v RangeInt16) Test(value int16) bool

Test returns true if the value is within [(min,max)] range (depending on minExclusive and maxExclusive).

func (RangeInt16) Validate

func (v RangeInt16) Validate(value int16) (int16, error)

Validate tests whether the value is within [(min,max)] range (depending on minExclusive and maxExclusive). It returns the value if it is within the range, otherwise returns 0 and error.

func (RangeInt16) Wrap

func (v RangeInt16) Wrap(value int16) int16

Wrap does not obey minExclusive and maxExclusive and always assumes [min,max) range.

type RangeInt32

type RangeInt32 struct {
	// contains filtered or unexported fields
}

RangeInt32 represents a struct containing all the fields defining a range.

Example
r := NewRangeInt32(10, 100, false, false)
fmt.Println(r.Wrap(120))                //=> 30
fmt.Println(r.Validate(120))            //=> (0, error(120 is outside of range [0,100]))
fmt.Println(r.Test(120))                //=> false
fmt.Println(r)                          //=> [0,100] (uses Stringer interface)
r = NewRangeInt32(100, 10, false, true) // swapped
fmt.Println(r.Wrap(120))                //=> 30
fmt.Println(r.Validate(120))            //=> (0, error(120 is outside of range (0,100]))
fmt.Println(r.Test(120))                //=> false
fmt.Println(r.Clamp(120))               //=> 100
fmt.Println(r.Clamp(0))                 //=> 10
fmt.Println(r)                          //=> (0,100] (uses Stringer interface)
Output:

30
0 120 is outside of range [10,100]
false
[10,100]
30
0 120 is outside of range (10,100]
false
100
10
(10,100]

func NewRangeInt32

func NewRangeInt32(min int32, max int32, minExclusive bool, maxExclusive bool) *RangeInt32

NewRangeInt32 makes a new Range and returns its pointer. RangeInt32 can also be created with a RangeInt32{...} literal or new(RangeInt32).

func (RangeInt32) Clamp

func (v RangeInt32) Clamp(value int32) int32

Clamp does not obey minExclusive and maxExclusive and always assumes [min,max] range.

func (RangeInt32) String added in v0.0.2

func (v RangeInt32) String() string

String returns a string representation of the range using range notation (https://en.wikipedia.org/wiki/Interval_(mathematics)#Classification_of_intervals). String implements Stringer interface.

func (RangeInt32) Test

func (v RangeInt32) Test(value int32) bool

Test returns true if the value is within [(min,max)] range (depending on minExclusive and maxExclusive).

func (RangeInt32) Validate

func (v RangeInt32) Validate(value int32) (int32, error)

Validate tests whether the value is within [(min,max)] range (depending on minExclusive and maxExclusive). It returns the value if it is within the range, otherwise returns 0 and error.

func (RangeInt32) Wrap

func (v RangeInt32) Wrap(value int32) int32

Wrap does not obey minExclusive and maxExclusive and always assumes [min,max) range.

type RangeInt64

type RangeInt64 struct {
	// contains filtered or unexported fields
}

RangeInt64 represents a struct containing all the fields defining a range.

Example
r := NewRangeInt64(10, 100, false, false)
fmt.Println(r.Wrap(120))                //=> 30
fmt.Println(r.Validate(120))            //=> (0, error(120 is outside of range [0,100]))
fmt.Println(r.Test(120))                //=> false
fmt.Println(r)                          //=> [0,100] (uses Stringer interface)
r = NewRangeInt64(100, 10, false, true) // swapped
fmt.Println(r.Wrap(120))                //=> 30
fmt.Println(r.Validate(120))            //=> (0, error(120 is outside of range (0,100]))
fmt.Println(r.Test(120))                //=> false
fmt.Println(r.Clamp(120))               //=> 100
fmt.Println(r.Clamp(0))                 //=> 10
fmt.Println(r)                          //=> (0,100] (uses Stringer interface)
Output:

30
0 120 is outside of range [10,100]
false
[10,100]
30
0 120 is outside of range (10,100]
false
100
10
(10,100]

func NewRangeInt64

func NewRangeInt64(min int64, max int64, minExclusive bool, maxExclusive bool) *RangeInt64

NewRangeInt64 makes a new Range and returns its pointer. RangeInt64 can also be created with a RangeInt64{...} literal or new(RangeInt64).

func (RangeInt64) Clamp

func (v RangeInt64) Clamp(value int64) int64

Clamp does not obey minExclusive and maxExclusive and always assumes [min,max] range.

func (RangeInt64) String added in v0.0.2

func (v RangeInt64) String() string

String returns a string representation of the range using range notation (https://en.wikipedia.org/wiki/Interval_(mathematics)#Classification_of_intervals). String implements Stringer interface.

func (RangeInt64) Test

func (v RangeInt64) Test(value int64) bool

Test returns true if the value is within [(min,max)] range (depending on minExclusive and maxExclusive).

func (RangeInt64) Validate

func (v RangeInt64) Validate(value int64) (int64, error)

Validate tests whether the value is within [(min,max)] range (depending on minExclusive and maxExclusive). It returns the value if it is within the range, otherwise returns 0 and error.

func (RangeInt64) Wrap

func (v RangeInt64) Wrap(value int64) int64

Wrap does not obey minExclusive and maxExclusive and always assumes [min,max) range.

type RangeInt8

type RangeInt8 struct {
	// contains filtered or unexported fields
}

RangeInt8 represents a struct containing all the fields defining a range.

Example
r := NewRangeInt8(10, 100, false, false)
fmt.Println(r.Wrap(120))               //=> 30
fmt.Println(r.Validate(120))           //=> (0, error(120 is outside of range [0,100]))
fmt.Println(r.Test(120))               //=> false
fmt.Println(r)                         //=> [0,100] (uses Stringer interface)
r = NewRangeInt8(100, 10, false, true) // swapped
fmt.Println(r.Wrap(120))               //=> 30
fmt.Println(r.Validate(120))           //=> (0, error(120 is outside of range (0,100]))
fmt.Println(r.Test(120))               //=> false
fmt.Println(r.Clamp(120))              //=> 100
fmt.Println(r.Clamp(0))                //=> 10
fmt.Println(r)                         //=> (0,100] (uses Stringer interface)
Output:

30
0 120 is outside of range [10,100]
false
[10,100]
30
0 120 is outside of range (10,100]
false
100
10
(10,100]

func NewRangeInt8

func NewRangeInt8(min int8, max int8, minExclusive bool, maxExclusive bool) *RangeInt8

NewRangeInt8 makes a new Range and returns its pointer. RangeInt8 can also be created with a RangeInt8{...} literal or new(RangeInt8).

func (RangeInt8) Clamp

func (v RangeInt8) Clamp(value int8) int8

Clamp does not obey minExclusive and maxExclusive and always assumes [min,max] range.

func (RangeInt8) String added in v0.0.2

func (v RangeInt8) String() string

String returns a string representation of the range using range notation (https://en.wikipedia.org/wiki/Interval_(mathematics)#Classification_of_intervals). String implements Stringer interface.

func (RangeInt8) Test

func (v RangeInt8) Test(value int8) bool

Test returns true if the value is within [(min,max)] range (depending on minExclusive and maxExclusive).

func (RangeInt8) Validate

func (v RangeInt8) Validate(value int8) (int8, error)

Validate tests whether the value is within [(min,max)] range (depending on minExclusive and maxExclusive). It returns the value if it is within the range, otherwise returns 0 and error.

func (RangeInt8) Wrap

func (v RangeInt8) Wrap(value int8) int8

Wrap does not obey minExclusive and maxExclusive and always assumes [min,max) range.

type RangeUint

type RangeUint struct {
	// contains filtered or unexported fields
}

RangeUint represents a struct containing all the fields defining a range.

Example
r := NewRangeUint(10, 100, false, false)
fmt.Println(r.Wrap(120))               //=> 30
fmt.Println(r.Validate(120))           //=> (0, error(120 is outside of range [0,100]))
fmt.Println(r.Test(120))               //=> false
fmt.Println(r)                         //=> [0,100] (uses Stringer interface)
r = NewRangeUint(100, 10, false, true) // swapped
fmt.Println(r.Wrap(120))               //=> 30
fmt.Println(r.Validate(120))           //=> (0, error(120 is outside of range (0,100]))
fmt.Println(r.Test(120))               //=> false
fmt.Println(r.Clamp(120))              //=> 100
fmt.Println(r.Clamp(0))                //=> 10
fmt.Println(r)                         //=> (0,100] (uses Stringer interface)
Output:

30
0 120 is outside of range [10,100]
false
[10,100]
30
0 120 is outside of range (10,100]
false
100
10
(10,100]

func NewRangeUint

func NewRangeUint(min uint, max uint, minExclusive bool, maxExclusive bool) *RangeUint

NewRangeUint makes a new Range and returns its pointer. RangeUint can also be created with a RangeUint{...} literal or new(RangeUint).

func (RangeUint) Clamp

func (v RangeUint) Clamp(value uint) uint

Clamp does not obey minExclusive and maxExclusive and always assumes [min,max] range.

func (RangeUint) String added in v0.0.2

func (v RangeUint) String() string

String returns a string representation of the range using range notation (https://en.wikipedia.org/wiki/Interval_(mathematics)#Classification_of_intervals). String implements Stringer interface.

func (RangeUint) Test

func (v RangeUint) Test(value uint) bool

Test returns true if the value is within [(min,max)] range (depending on minExclusive and maxExclusive).

func (RangeUint) Validate

func (v RangeUint) Validate(value uint) (uint, error)

Validate tests whether the value is within [(min,max)] range (depending on minExclusive and maxExclusive). It returns the value if it is within the range, otherwise returns 0 and error.

func (RangeUint) Wrap

func (v RangeUint) Wrap(value uint) uint

Wrap does not obey minExclusive and maxExclusive and always assumes [min,max) range.

type RangeUint16

type RangeUint16 struct {
	// contains filtered or unexported fields
}

RangeUint16 represents a struct containing all the fields defining a range.

Example
r := NewRangeUint16(10, 100, false, false)
fmt.Println(r.Wrap(120))                 //=> 30
fmt.Println(r.Validate(120))             //=> (0, error(120 is outside of range [0,100]))
fmt.Println(r.Test(120))                 //=> false
fmt.Println(r)                           //=> [0,100] (uses Stringer interface)
r = NewRangeUint16(100, 10, false, true) // swapped
fmt.Println(r.Wrap(120))                 //=> 30
fmt.Println(r.Validate(120))             //=> (0, error(120 is outside of range (0,100]))
fmt.Println(r.Test(120))                 //=> false
fmt.Println(r.Clamp(120))                //=> 100
fmt.Println(r.Clamp(0))                  //=> 10
fmt.Println(r)                           //=> (0,100] (uses Stringer interface)
Output:

30
0 120 is outside of range [10,100]
false
[10,100]
30
0 120 is outside of range (10,100]
false
100
10
(10,100]

func NewRangeUint16

func NewRangeUint16(min uint16, max uint16, minExclusive bool, maxExclusive bool) *RangeUint16

NewRangeUint16 makes a new Range and returns its pointer. RangeUint16 can also be created with a RangeUint16{...} literal or new(RangeUint16).

func (RangeUint16) Clamp

func (v RangeUint16) Clamp(value uint16) uint16

Clamp does not obey minExclusive and maxExclusive and always assumes [min,max] range.

func (RangeUint16) String added in v0.0.2

func (v RangeUint16) String() string

String returns a string representation of the range using range notation (https://en.wikipedia.org/wiki/Interval_(mathematics)#Classification_of_intervals). String implements Stringer interface.

func (RangeUint16) Test

func (v RangeUint16) Test(value uint16) bool

Test returns true if the value is within [(min,max)] range (depending on minExclusive and maxExclusive).

func (RangeUint16) Validate

func (v RangeUint16) Validate(value uint16) (uint16, error)

Validate tests whether the value is within [(min,max)] range (depending on minExclusive and maxExclusive). It returns the value if it is within the range, otherwise returns 0 and error.

func (RangeUint16) Wrap

func (v RangeUint16) Wrap(value uint16) uint16

Wrap does not obey minExclusive and maxExclusive and always assumes [min,max) range.

type RangeUint32

type RangeUint32 struct {
	// contains filtered or unexported fields
}

RangeUint32 represents a struct containing all the fields defining a range.

Example
r := NewRangeUint32(10, 100, false, false)
fmt.Println(r.Wrap(120))                 //=> 30
fmt.Println(r.Validate(120))             //=> (0, error(120 is outside of range [0,100]))
fmt.Println(r.Test(120))                 //=> false
fmt.Println(r)                           //=> [0,100] (uses Stringer interface)
r = NewRangeUint32(100, 10, false, true) // swapped
fmt.Println(r.Wrap(120))                 //=> 30
fmt.Println(r.Validate(120))             //=> (0, error(120 is outside of range (0,100]))
fmt.Println(r.Test(120))                 //=> false
fmt.Println(r.Clamp(120))                //=> 100
fmt.Println(r.Clamp(0))                  //=> 10
fmt.Println(r)                           //=> (0,100] (uses Stringer interface)
Output:

30
0 120 is outside of range [10,100]
false
[10,100]
30
0 120 is outside of range (10,100]
false
100
10
(10,100]

func NewRangeUint32

func NewRangeUint32(min uint32, max uint32, minExclusive bool, maxExclusive bool) *RangeUint32

NewRangeUint32 makes a new Range and returns its pointer. RangeUint32 can also be created with a RangeUint32{...} literal or new(RangeUint32).

func (RangeUint32) Clamp

func (v RangeUint32) Clamp(value uint32) uint32

Clamp does not obey minExclusive and maxExclusive and always assumes [min,max] range.

func (RangeUint32) String added in v0.0.2

func (v RangeUint32) String() string

String returns a string representation of the range using range notation (https://en.wikipedia.org/wiki/Interval_(mathematics)#Classification_of_intervals). String implements Stringer interface.

func (RangeUint32) Test

func (v RangeUint32) Test(value uint32) bool

Test returns true if the value is within [(min,max)] range (depending on minExclusive and maxExclusive).

func (RangeUint32) Validate

func (v RangeUint32) Validate(value uint32) (uint32, error)

Validate tests whether the value is within [(min,max)] range (depending on minExclusive and maxExclusive). It returns the value if it is within the range, otherwise returns 0 and error.

func (RangeUint32) Wrap

func (v RangeUint32) Wrap(value uint32) uint32

Wrap does not obey minExclusive and maxExclusive and always assumes [min,max) range.

type RangeUint64

type RangeUint64 struct {
	// contains filtered or unexported fields
}

RangeUint64 represents a struct containing all the fields defining a range.

Example
r := NewRangeUint64(10, 100, false, false)
fmt.Println(r.Wrap(120))                 //=> 30
fmt.Println(r.Validate(120))             //=> (0, error(120 is outside of range [0,100]))
fmt.Println(r.Test(120))                 //=> false
fmt.Println(r)                           //=> [0,100] (uses Stringer interface)
r = NewRangeUint64(100, 10, false, true) // swapped
fmt.Println(r.Wrap(120))                 //=> 30
fmt.Println(r.Validate(120))             //=> (0, error(120 is outside of range (0,100]))
fmt.Println(r.Test(120))                 //=> false
fmt.Println(r.Clamp(120))                //=> 100
fmt.Println(r.Clamp(0))                  //=> 10
fmt.Println(r)                           //=> (0,100] (uses Stringer interface)
Output:

30
0 120 is outside of range [10,100]
false
[10,100]
30
0 120 is outside of range (10,100]
false
100
10
(10,100]

func NewRangeUint64

func NewRangeUint64(min uint64, max uint64, minExclusive bool, maxExclusive bool) *RangeUint64

NewRangeUint64 makes a new Range and returns its pointer. RangeUint64 can also be created with a RangeUint64{...} literal or new(RangeUint64).

func (RangeUint64) Clamp

func (v RangeUint64) Clamp(value uint64) uint64

Clamp does not obey minExclusive and maxExclusive and always assumes [min,max] range.

func (RangeUint64) String added in v0.0.2

func (v RangeUint64) String() string

String returns a string representation of the range using range notation (https://en.wikipedia.org/wiki/Interval_(mathematics)#Classification_of_intervals). String implements Stringer interface.

func (RangeUint64) Test

func (v RangeUint64) Test(value uint64) bool

Test returns true if the value is within [(min,max)] range (depending on minExclusive and maxExclusive).

func (RangeUint64) Validate

func (v RangeUint64) Validate(value uint64) (uint64, error)

Validate tests whether the value is within [(min,max)] range (depending on minExclusive and maxExclusive). It returns the value if it is within the range, otherwise returns 0 and error.

func (RangeUint64) Wrap

func (v RangeUint64) Wrap(value uint64) uint64

Wrap does not obey minExclusive and maxExclusive and always assumes [min,max) range.

type RangeUint8

type RangeUint8 struct {
	// contains filtered or unexported fields
}

RangeUint8 represents a struct containing all the fields defining a range.

Example
r := NewRangeUint8(10, 100, false, false)
fmt.Println(r.Wrap(120))                //=> 30
fmt.Println(r.Validate(120))            //=> (0, error(120 is outside of range [0,100]))
fmt.Println(r.Test(120))                //=> false
fmt.Println(r)                          //=> [0,100] (uses Stringer interface)
r = NewRangeUint8(100, 10, false, true) // swapped
fmt.Println(r.Wrap(120))                //=> 30
fmt.Println(r.Validate(120))            //=> (0, error(120 is outside of range (0,100]))
fmt.Println(r.Test(120))                //=> false
fmt.Println(r.Clamp(120))               //=> 100
fmt.Println(r.Clamp(0))                 //=> 10
fmt.Println(r)                          //=> (0,100] (uses Stringer interface)
Output:

30
0 120 is outside of range [10,100]
false
[10,100]
30
0 120 is outside of range (10,100]
false
100
10
(10,100]

func NewRangeUint8

func NewRangeUint8(min uint8, max uint8, minExclusive bool, maxExclusive bool) *RangeUint8

NewRangeUint8 makes a new Range and returns its pointer. RangeUint8 can also be created with a RangeUint8{...} literal or new(RangeUint8).

func (RangeUint8) Clamp

func (v RangeUint8) Clamp(value uint8) uint8

Clamp does not obey minExclusive and maxExclusive and always assumes [min,max] range.

func (RangeUint8) String added in v0.0.2

func (v RangeUint8) String() string

String returns a string representation of the range using range notation (https://en.wikipedia.org/wiki/Interval_(mathematics)#Classification_of_intervals). String implements Stringer interface.

func (RangeUint8) Test

func (v RangeUint8) Test(value uint8) bool

Test returns true if the value is within [(min,max)] range (depending on minExclusive and maxExclusive).

func (RangeUint8) Validate

func (v RangeUint8) Validate(value uint8) (uint8, error)

Validate tests whether the value is within [(min,max)] range (depending on minExclusive and maxExclusive). It returns the value if it is within the range, otherwise returns 0 and error.

func (RangeUint8) Wrap

func (v RangeUint8) Wrap(value uint8) uint8

Wrap does not obey minExclusive and maxExclusive and always assumes [min,max) range.

Directories

Path Synopsis
Package main performs actual generation of the interval package functions for all built-in numeric types in Go.
Package main performs actual generation of the interval package functions for all built-in numeric types in Go.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL