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 ¶
- func ClampFloat32(min, max, value float32) float32
- func ClampFloat64(min, max, value float64) float64
- func ClampInt(min, max, value int) int
- func ClampInt16(min, max, value int16) int16
- func ClampInt32(min, max, value int32) int32
- func ClampInt64(min, max, value int64) int64
- func ClampInt8(min, max, value int8) int8
- func ClampUint(min, max, value uint) uint
- func ClampUint16(min, max, value uint16) uint16
- func ClampUint32(min, max, value uint32) uint32
- func ClampUint64(min, max, value uint64) uint64
- func ClampUint8(min, max, value uint8) uint8
- func MaxFloat32(x, y float32) float32
- func MaxFloat64(x, y float64) float64
- func MaxInt(x, y int) int
- func MaxInt16(x, y int16) int16
- func MaxInt32(x, y int32) int32
- func MaxInt64(x, y int64) int64
- func MaxInt8(x, y int8) int8
- func MaxUint(x, y uint) uint
- func MaxUint16(x, y uint16) uint16
- func MaxUint32(x, y uint32) uint32
- func MaxUint64(x, y uint64) uint64
- func MaxUint8(x, y uint8) uint8
- func MinFloat32(x, y float32) float32
- func MinFloat64(x, y float64) float64
- func MinInt(x, y int) int
- func MinInt16(x, y int16) int16
- func MinInt32(x, y int32) int32
- func MinInt64(x, y int64) int64
- func MinInt8(x, y int8) int8
- func MinMaxExclusiveFloat32(min, max float32, minExclusive, maxExclusive bool) (float32, float32, bool, bool)
- func MinMaxExclusiveFloat64(min, max float64, minExclusive, maxExclusive bool) (float64, float64, bool, bool)
- func MinMaxExclusiveInt(min, max int, minExclusive, maxExclusive bool) (int, int, bool, bool)
- func MinMaxExclusiveInt16(min, max int16, minExclusive, maxExclusive bool) (int16, int16, bool, bool)
- func MinMaxExclusiveInt32(min, max int32, minExclusive, maxExclusive bool) (int32, int32, bool, bool)
- func MinMaxExclusiveInt64(min, max int64, minExclusive, maxExclusive bool) (int64, int64, bool, bool)
- func MinMaxExclusiveInt8(min, max int8, minExclusive, maxExclusive bool) (int8, int8, bool, bool)
- func MinMaxExclusiveUint(min, max uint, minExclusive, maxExclusive bool) (uint, uint, bool, bool)
- func MinMaxExclusiveUint16(min, max uint16, minExclusive, maxExclusive bool) (uint16, uint16, bool, bool)
- func MinMaxExclusiveUint32(min, max uint32, minExclusive, maxExclusive bool) (uint32, uint32, bool, bool)
- func MinMaxExclusiveUint64(min, max uint64, minExclusive, maxExclusive bool) (uint64, uint64, bool, bool)
- func MinMaxExclusiveUint8(min, max uint8, minExclusive, maxExclusive bool) (uint8, uint8, bool, bool)
- func MinMaxFloat32(min, max float32) (float32, float32)
- func MinMaxFloat64(min, max float64) (float64, float64)
- func MinMaxInt(min, max int) (int, int)
- func MinMaxInt16(min, max int16) (int16, int16)
- func MinMaxInt32(min, max int32) (int32, int32)
- func MinMaxInt64(min, max int64) (int64, int64)
- func MinMaxInt8(min, max int8) (int8, int8)
- func MinMaxUint(min, max uint) (uint, uint)
- func MinMaxUint16(min, max uint16) (uint16, uint16)
- func MinMaxUint32(min, max uint32) (uint32, uint32)
- func MinMaxUint64(min, max uint64) (uint64, uint64)
- func MinMaxUint8(min, max uint8) (uint8, uint8)
- func MinUint(x, y uint) uint
- func MinUint16(x, y uint16) uint16
- func MinUint32(x, y uint32) uint32
- func MinUint64(x, y uint64) uint64
- func MinUint8(x, y uint8) uint8
- func TestFloat32(min, max, value float32, minExclusive, maxExclusive bool) bool
- func TestFloat64(min, max, value float64, minExclusive, maxExclusive bool) bool
- func TestInt(min, max, value int, minExclusive, maxExclusive bool) bool
- func TestInt16(min, max, value int16, minExclusive, maxExclusive bool) bool
- func TestInt32(min, max, value int32, minExclusive, maxExclusive bool) bool
- func TestInt64(min, max, value int64, minExclusive, maxExclusive bool) bool
- func TestInt8(min, max, value int8, minExclusive, maxExclusive bool) bool
- func TestUint(min, max, value uint, minExclusive, maxExclusive bool) bool
- func TestUint16(min, max, value uint16, minExclusive, maxExclusive bool) bool
- func TestUint32(min, max, value uint32, minExclusive, maxExclusive bool) bool
- func TestUint64(min, max, value uint64, minExclusive, maxExclusive bool) bool
- func TestUint8(min, max, value uint8, minExclusive, maxExclusive bool) bool
- func ToStringFloat32(min, max float32, minExclusive, maxExclusive bool) string
- func ToStringFloat64(min, max float64, minExclusive, maxExclusive bool) string
- func ToStringInt(min, max int, minExclusive, maxExclusive bool) string
- func ToStringInt16(min, max int16, minExclusive, maxExclusive bool) string
- func ToStringInt32(min, max int32, minExclusive, maxExclusive bool) string
- func ToStringInt64(min, max int64, minExclusive, maxExclusive bool) string
- func ToStringInt8(min, max int8, minExclusive, maxExclusive bool) string
- func ToStringUint(min, max uint, minExclusive, maxExclusive bool) string
- func ToStringUint16(min, max uint16, minExclusive, maxExclusive bool) string
- func ToStringUint32(min, max uint32, minExclusive, maxExclusive bool) string
- func ToStringUint64(min, max uint64, minExclusive, maxExclusive bool) string
- func ToStringUint8(min, max uint8, minExclusive, maxExclusive bool) string
- func ValidateFloat32(min, max, value float32, minExclusive, maxExclusive bool) (float32, error)
- func ValidateFloat64(min, max, value float64, minExclusive, maxExclusive bool) (float64, error)
- func ValidateInt(min, max, value int, minExclusive, maxExclusive bool) (int, error)
- func ValidateInt16(min, max, value int16, minExclusive, maxExclusive bool) (int16, error)
- func ValidateInt32(min, max, value int32, minExclusive, maxExclusive bool) (int32, error)
- func ValidateInt64(min, max, value int64, minExclusive, maxExclusive bool) (int64, error)
- func ValidateInt8(min, max, value int8, minExclusive, maxExclusive bool) (int8, error)
- func ValidateUint(min, max, value uint, minExclusive, maxExclusive bool) (uint, error)
- func ValidateUint16(min, max, value uint16, minExclusive, maxExclusive bool) (uint16, error)
- func ValidateUint32(min, max, value uint32, minExclusive, maxExclusive bool) (uint32, error)
- func ValidateUint64(min, max, value uint64, minExclusive, maxExclusive bool) (uint64, error)
- func ValidateUint8(min, max, value uint8, minExclusive, maxExclusive bool) (uint8, error)
- func WrapFloat32(min, max, value float32) float32
- func WrapFloat64(min, max, value float64) float64
- func WrapInt(min, max, value int) int
- func WrapInt16(min, max, value int16) int16
- func WrapInt32(min, max, value int32) int32
- func WrapInt64(min, max, value int64) int64
- func WrapInt8(min, max, value int8) int8
- func WrapUint(min, max, value uint) uint
- func WrapUint16(min, max, value uint16) uint16
- func WrapUint32(min, max, value uint32) uint32
- func WrapUint64(min, max, value uint64) uint64
- func WrapUint8(min, max, value uint8) uint8
- type RangeFloat32
- type RangeFloat64
- type RangeInt
- type RangeInt16
- type RangeInt32
- type RangeInt64
- type RangeInt8
- type RangeUint
- type RangeUint16
- type RangeUint32
- type RangeUint64
- type RangeUint8
Examples ¶
- ClampFloat32
- ClampFloat64
- ClampInt
- ClampInt16
- ClampInt32
- ClampInt64
- ClampInt8
- ClampUint
- ClampUint16
- ClampUint32
- ClampUint64
- ClampUint8
- MinMaxExclusiveFloat32
- MinMaxExclusiveFloat64
- MinMaxExclusiveInt
- MinMaxExclusiveInt16
- MinMaxExclusiveInt32
- MinMaxExclusiveInt64
- MinMaxExclusiveInt8
- MinMaxExclusiveUint
- MinMaxExclusiveUint16
- MinMaxExclusiveUint32
- MinMaxExclusiveUint64
- MinMaxExclusiveUint8
- MinMaxFloat32
- MinMaxFloat64
- MinMaxInt
- MinMaxInt16
- MinMaxInt32
- MinMaxInt64
- MinMaxInt8
- MinMaxUint
- MinMaxUint16
- MinMaxUint32
- MinMaxUint64
- MinMaxUint8
- RangeFloat32
- RangeFloat64
- RangeInt
- RangeInt16
- RangeInt32
- RangeInt64
- RangeInt8
- RangeUint
- RangeUint16
- RangeUint32
- RangeUint64
- RangeUint8
- TestFloat32
- TestFloat64
- TestInt
- TestInt16
- TestInt32
- TestInt64
- TestInt8
- TestUint
- TestUint16
- TestUint32
- TestUint64
- TestUint8
- ToStringFloat32
- ToStringFloat64
- ToStringInt
- ToStringInt16
- ToStringInt32
- ToStringInt64
- ToStringInt8
- ToStringUint
- ToStringUint16
- ToStringUint32
- ToStringUint64
- ToStringUint8
- ValidateFloat32
- ValidateFloat64
- ValidateInt
- ValidateInt16
- ValidateInt32
- ValidateInt64
- ValidateInt8
- ValidateUint
- ValidateUint16
- ValidateUint32
- ValidateUint64
- ValidateUint8
- WrapFloat32
- WrapFloat64
- WrapInt
- WrapInt16
- WrapInt32
- WrapInt64
- WrapInt8
- WrapUint
- WrapUint16
- WrapUint32
- WrapUint64
- WrapUint8
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ClampFloat32 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
MaxFloat32 returns the bigger of two numbers.
func MaxFloat64 ¶
MaxFloat64 returns the bigger of two numbers.
func MinFloat32 ¶
MinFloat32 returns the smaller of two numbers.
func MinFloat64 ¶
MinFloat64 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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 TestFloat32 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
NewRangeInt makes a new Range and returns its pointer. RangeInt can also be created with a RangeInt{...} literal or new(RangeInt).
func (RangeInt) Clamp ¶
Clamp does not obey minExclusive and maxExclusive and always assumes [min,max] range.
func (RangeInt) String ¶ added in v0.0.2
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 ¶
Test returns true if the value is within [(min,max)] range (depending on minExclusive and maxExclusive).
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 ¶
NewRangeInt8 makes a new Range and returns its pointer. RangeInt8 can also be created with a RangeInt8{...} literal or new(RangeInt8).
func (RangeInt8) Clamp ¶
Clamp does not obey minExclusive and maxExclusive and always assumes [min,max] range.
func (RangeInt8) String ¶ added in v0.0.2
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 ¶
Test returns true if the value is within [(min,max)] range (depending on minExclusive and maxExclusive).
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 ¶
NewRangeUint makes a new Range and returns its pointer. RangeUint can also be created with a RangeUint{...} literal or new(RangeUint).
func (RangeUint) Clamp ¶
Clamp does not obey minExclusive and maxExclusive and always assumes [min,max] range.
func (RangeUint) String ¶ added in v0.0.2
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 ¶
Test returns true if the value is within [(min,max)] range (depending on minExclusive and maxExclusive).
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.