Documentation ¶
Index ¶
- Constants
- Variables
- func Slice(nums []float64, expression string) []float64
- func Slice2(nums []float64, expression string) ([]float64, error)
- type Range
- func (r *Range) All() []float64
- func (r *Range) Bits() int
- func (r *Range) Find(x, threshold float64) (bool, float64)
- func (r *Range) ForEach(f func(float64))
- func (r *Range) ForEachWithBreak(f func(float64) bool)
- func (r *Range) ForN(n int, f func(float64))
- func (r *Range) Has(x, threshold float64) bool
- func (r *Range) Integer() bool
- func (r *Range) Join(sep string, digits int) string
- func (r *Range) JoinInts(sep string) string
- func (r *Range) Len() uint
- func (r *Range) Len64() float64
- func (r *Range) String() string
- func (r *Range) Sum() float64
- func (r *Range) Take(n int) []float64
- func (r *Range) Valid(x float64) bool
- func (r *Range) ValidFloat(x float64) bool
- func (r *Range) ValidInt(i int) bool
Constants ¶
const ( RANGE_MISSING = 0 RANGE_EXCLUDE_START = 1 << iota // Start at 1, then double RANGE_INCLUDE_START RANGE_EXCLUDE_STOP RANGE_INCLUDE_STOP // Thanks https://groups.google.com/forum/#!msg/golang-nuts/a9PitPAHSSU/ziQw1-QHw3EJ MaxUint = ^uint(0) MinUint = 0 MaxInt = int(MaxUint >> 1) MinInt = -MaxInt - 1 )
Variables ¶
var ( // Unsigned integers U4 = New("..2**4~") U8 = New("..2**8~") U16 = New("..2**16~") U32 = New("..2**32~") U64 = New("..2**64~") U128 = New("..2**128~") // Aliases for unsigned integers Nibble = U4 Char = U8 Byte = U8 Word = U16 Short = U16 Long = U32 Double = U32 Quad = U64 // Signed integers I8 = New("-2**7..2**7~") I16 = New("-2**15..2**15~") I32 = New("-2**31..2**31~") I64 = New("-2**63..2**63~") I128 = New("-2**127..2**127~") )
var ( ErrRangeSyntax = errors.New("INVALID RANGE SYNTAX") ErrMissingRange = errors.New("MISSING RANGE VALUES") )
Functions ¶
Types ¶
type Range ¶
type Range struct {
// contains filtered or unexported fields
}
Range can represent a number type in a programming language For example: An uint8 can be [0, 256) step 1 A float between 0 and 1 can be [0, 1] step 0.01
func (*Range) Find ¶
Find searches a range for a given number The threshold is how close the float has to be a float in the range for it to be "equal" If the difference between the given float and the float in the range are less than the given threshold, they are counted as equal. The allowed difference could be 0.00001, for example. This is needed because of how floats are stored.
func (*Range) ForEachWithBreak ¶
ForEachWithBreak calls the given function for each iteration in the range If the given function returns true, the remaining iterations are skipped
func (*Range) ForN ¶
ForN runs the given function for the n first iterations If n is never reached, a smaller number of iterations will happen.
func (*Range) Has ¶
Has checks if a given number is in the range. If the difference between the given float and the float in the range are less than the given threshold, they are counted as equal.
func (*Range) Join ¶
Join returns the output from the range as a string, where elements are separated by sep digits are how many digits should be added to the fractional part of the floats, use 0 for integers
func (*Range) JoinInts ¶
JoinInts returns the output from the range as a string, where elements are separated by sep
func (*Range) Len ¶
Len returns the length of the range by iterating over it! May get stuck if the range is impossibly large.
func (*Range) Len64 ¶
Len returns the length of the range by iterating over it! May get stuck if the range is impossibly large.
func (*Range) String ¶
String returns the range as a string where "[" means inclusive and "(" means exclusive
func (*Range) Take ¶
Take returns a slice of n numbers, generated from the range. It not generate the entire slice first, but return numbers as it iterates.
func (*Range) ValidFloat ¶
ValidFloat checks if the given float is in the range, using half the range step size as the threshold for float equality