Documentation
¶
Index ¶
- type NumericRegistry
- func (nr *NumericRegistry) Add(values ...any) (any, error)
- func (nr *NumericRegistry) Add1(value any) (any, error)
- func (nr *NumericRegistry) Ceil(value any) (float64, error)
- func (nr *NumericRegistry) DivInt(values ...any) (int64, error)
- func (nr *NumericRegistry) Divf(values ...any) (any, error)
- func (nr *NumericRegistry) Floor(value any) (float64, error)
- func (nr *NumericRegistry) LinkHandler(fh sprout.Handler) error
- func (nr *NumericRegistry) Max(value any, values ...any) (int64, error)
- func (nr *NumericRegistry) Maxf(value any, values ...any) (float64, error)
- func (nr *NumericRegistry) Min(subtrahend any, values ...any) (int64, error)
- func (nr *NumericRegistry) Minf(subtrahend any, values ...any) (float64, error)
- func (nr *NumericRegistry) Mod(value, divisor any) (any, error)
- func (nr *NumericRegistry) MulInt(values ...any) (int64, error)
- func (nr *NumericRegistry) Mulf(values ...any) (any, error)
- func (nr *NumericRegistry) RegisterAliases(aliasMap sprout.FunctionAliasMap) error
- func (nr *NumericRegistry) RegisterFunctions(funcsMap sprout.FunctionMap) error
- func (nr *NumericRegistry) RegisterNotices(notices *[]sprout.FunctionNotice) error
- func (nr *NumericRegistry) Round(value any, poww int, roundOpts ...float64) (float64, error)
- func (nr *NumericRegistry) Sub(values ...any) (any, error)
- func (nr *NumericRegistry) UID() string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type NumericRegistry ¶
type NumericRegistry struct {
// contains filtered or unexported fields
}
func NewRegistry ¶
func NewRegistry() *NumericRegistry
NewRegistry creates a new instance of numeric registry.
func (*NumericRegistry) Add ¶
func (nr *NumericRegistry) Add(values ...any) (any, error)
Add performs addition on a slice of values.
Parameters:
values ...any - numbers to add.
Returns:
any - the sum of the values, converted to the type of the first value. error - when a value cannot be converted.
For an example of this function in a Go template, refer to Sprout Documentation: add.
func (*NumericRegistry) Add1 ¶
func (nr *NumericRegistry) Add1(value any) (any, error)
Add1 performs a unary addition operation on a single value.
Parameters:
value any - the number to add.
Returns:
any - the sum of the value and 1, converted to the type of the input. error - when a value cannot be converted.
For an example of this function in a Go template, refer to Sprout Documentation: add1.
func (*NumericRegistry) Ceil ¶
func (nr *NumericRegistry) Ceil(value any) (float64, error)
Ceil returns the smallest integer greater than or equal to the provided number.
Parameters:
value any - the number to ceil, expected to be numeric or convertible to float64.
Returns:
float64 - the ceiled value. error - an error if the input cannot be converted to float64.
For an example of this function in a Go template, refer to Sprout Documentation: ceil.
func (*NumericRegistry) DivInt ¶
func (nr *NumericRegistry) DivInt(values ...any) (int64, error)
DivInt divides a sequence of values and returns the result as int64.
Parameters:
values ...any - numbers to divide.
Returns:
int64 - the quotient of the division.
For an example of this function in a Go template, refer to Sprout Documentation: div.
func (*NumericRegistry) Divf ¶
func (nr *NumericRegistry) Divf(values ...any) (any, error)
Divf divides a sequence of values, starting with the first value, and returns the result.
Parameters:
values ...any - numbers to divide.
Returns:
any - the quotient of the division, converted to the type of the first value.
For an example of this function in a Go template, refer to Sprout Documentation: divf.
func (*NumericRegistry) Floor ¶
func (nr *NumericRegistry) Floor(value any) (float64, error)
Floor returns the largest integer less than or equal to the provided number.
Parameters:
value any - the number to floor, expected to be numeric or convertible to float64.
Returns:
float64 - the floored value. error - an error if the input cannot be converted to float64.
For an example of this function in a Go template, refer to Sprout Documentation: floor.
func (*NumericRegistry) LinkHandler ¶
func (nr *NumericRegistry) LinkHandler(fh sprout.Handler) error
LinkHandler links the handler to the registry at runtime.
func (*NumericRegistry) Max ¶
func (nr *NumericRegistry) Max(value any, values ...any) (int64, error)
Max returns the maximum value among the provided arguments.
Parameters:
value any - the first number to compare. values ...any - additional numbers to compare.
Returns:
int64 - the largest number among the inputs. error - when a value cannot be converted.
For an example of this function in a Go template, refer to Sprout Documentation: max.
func (*NumericRegistry) Maxf ¶
func (nr *NumericRegistry) Maxf(value any, values ...any) (float64, error)
Maxf returns the maximum value among the provided floating-point arguments.
Parameters:
value any - the first number to compare, expected to be numeric or convertible to float64. values .any - additional numbers to compare.
Returns:
float64 - the largest number among the inputs. error - when a value cannot be converted.
For an example of this function in a Go template, refer to Sprout Documentation: maxf.
func (*NumericRegistry) Min ¶
func (nr *NumericRegistry) Min(subtrahend any, values ...any) (int64, error)
Min returns the minimum value among the provided arguments.
Parameters:
subtrahend any - the first number to compare. values ...any - additional numbers to compare.
Returns:
int64 - the smallest number among the inputs. error - when a value cannot be converted.
For an example of this function in a Go template, refer to Sprout Documentation: min.
func (*NumericRegistry) Minf ¶
func (nr *NumericRegistry) Minf(subtrahend any, values ...any) (float64, error)
Minf returns the minimum value among the provided floating-point arguments.
Parameters:
subtrahend any - the first number to compare, expected to be numeric or convertible to float64. values ...any - additional numbers to compare.
Returns:
float64 - the smallest number among the inputs. error - when a value cannot be converted.
For an example of this function in a Go template, refer to Sprout Documentation: minf.
func (*NumericRegistry) Mod ¶
func (nr *NumericRegistry) Mod(value, divisor any) (any, error)
Mod returns the remainder of division of 'x' by 'y'.
Parameters:
value any - the number to divide. divisor any - the number to divide by.
Returns:
any - the remainder, converted to the type of 'x'. error - when a value cannot be converted.
For an example of this function in a Go template, refer to Sprout Documentation: mod.
func (*NumericRegistry) MulInt ¶
func (nr *NumericRegistry) MulInt(values ...any) (int64, error)
MulInt multiplies a sequence of values and returns the result as int64.
Parameters:
values ...any - numbers to multiply, expected to be numeric or convertible to float64.
Returns:
int64 - the product of the values. error - an error if the result cannot be converted to int64.
For an example of this function in a Go template, refer to Sprout Documentation: mul.
func (*NumericRegistry) Mulf ¶
func (nr *NumericRegistry) Mulf(values ...any) (any, error)
Mulf multiplies a sequence of values and returns the result as float64.
Parameters:
values ...any - numbers to multiply.
Returns:
any - the product of the values, converted to the type of the first value. error - when a value cannot be converted.
For an example of this function in a Go template, refer to Sprout Documentation: mulf.
func (*NumericRegistry) RegisterAliases ¶
func (nr *NumericRegistry) RegisterAliases(aliasMap sprout.FunctionAliasMap) error
func (*NumericRegistry) RegisterFunctions ¶
func (nr *NumericRegistry) RegisterFunctions(funcsMap sprout.FunctionMap) error
RegisterFunctions registers all functions of the registry.
func (*NumericRegistry) RegisterNotices ¶ added in v0.6.0
func (nr *NumericRegistry) RegisterNotices(notices *[]sprout.FunctionNotice) error
func (*NumericRegistry) Round ¶
Round rounds a number to a specified precision and rounding threshold.
Parameters:
value any - the number to round. poww int - the power of ten to which to round. roundOpts ...float64 - optional threshold for rounding up (default is 0.5).
Returns:
float64 - the rounded number.
error - an error if the input cannot be converted to float64.
For an example of this function in a Go template, refer to Sprout Documentation: round.
func (*NumericRegistry) Sub ¶
func (nr *NumericRegistry) Sub(values ...any) (any, error)
Sub performs subtraction on a slice of values, starting with the first value.
Parameters:
values ...any - numbers to subtract from the first number.
Returns:
any - the result of the subtraction, converted to the type of the first value. error - when a value cannot be converted.
For an example of this function in a Go template, refer to Sprout Documentation: sub.
func (*NumericRegistry) UID ¶ added in v1.0.0
func (nr *NumericRegistry) UID() string
UID returns the unique identifier of the registry.