Documentation ¶
Index ¶
- type NumericRegistry
- func (nr *NumericRegistry) Add(values ...any) (any, error)
- func (nr *NumericRegistry) Add1(x any) (any, error)
- func (nr *NumericRegistry) Ceil(num any) (float64, error)
- func (nr *NumericRegistry) DivInt(values ...any) (int64, error)
- func (nr *NumericRegistry) Divf(values ...any) (any, error)
- func (nr *NumericRegistry) Floor(num any) (float64, error)
- func (nr *NumericRegistry) LinkHandler(fh sprout.Handler) error
- func (nr *NumericRegistry) Max(a any, i ...any) (int64, error)
- func (nr *NumericRegistry) Maxf(a any, i ...any) (float64, error)
- func (nr *NumericRegistry) Min(a any, i ...any) (int64, error)
- func (nr *NumericRegistry) Minf(a any, i ...any) (float64, error)
- func (nr *NumericRegistry) Mod(x, y 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(num 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.
Example:
{{ 5, 3.5, 2 | add }} // Output: 10.5
func (*NumericRegistry) Add1 ¶
func (nr *NumericRegistry) Add1(x any) (any, error)
Add1 performs a unary addition operation on a single value.
Parameters:
x 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.
Example:
{{ 5 | add1 }} // Output: 6
func (*NumericRegistry) Ceil ¶
func (nr *NumericRegistry) Ceil(num any) (float64, error)
Ceil returns the smallest integer greater than or equal to the provided number.
Parameters:
num 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.
Example:
{{ 3.1 | ceil }} // Output: 4
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.
Example:
{{ 30, 3, 2 | divInt }} // Output: 5
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.
Example:
{{ 30.0, 3.0, 2.0 | divf }} // Output: 5.0
func (*NumericRegistry) Floor ¶
func (nr *NumericRegistry) Floor(num any) (float64, error)
Floor returns the largest integer less than or equal to the provided number.
Parameters:
num 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.
Example:
{{ 3.7 | floor }} // Output: 3
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(a any, i ...any) (int64, error)
Max returns the maximum value among the provided arguments.
Parameters:
a any - the first number to compare. i ...any - additional numbers to compare.
Returns:
int64 - the largest number among the inputs. error - when a value cannot be converted.
Example:
{{ 5, 3, 8, 2 | max }} // Output: 8
func (*NumericRegistry) Maxf ¶
func (nr *NumericRegistry) Maxf(a any, i ...any) (float64, error)
Maxf returns the maximum value among the provided floating-point arguments.
Parameters:
a any - the first number to compare, expected to be numeric or convertible to float64. i ...any - additional numbers to compare.
Returns:
float64 - the largest number among the inputs. error - when a value cannot be converted.
Example:
{{ 5.2, 3.8, 8.1, 2.6 | maxf }} // Output: 8.1
func (*NumericRegistry) Min ¶
func (nr *NumericRegistry) Min(a any, i ...any) (int64, error)
Min returns the minimum value among the provided arguments.
Parameters:
a any - the first number to compare. i ...any - additional numbers to compare.
Returns:
int64 - the smallest number among the inputs. error - when a value cannot be converted.
Example:
{{ 5, 3, 8, 2 | min }} // Output: 2
func (*NumericRegistry) Minf ¶
func (nr *NumericRegistry) Minf(a any, i ...any) (float64, error)
Minf returns the minimum value among the provided floating-point arguments.
Parameters:
a any - the first number to compare, expected to be numeric or convertible to float64. i ...any - additional numbers to compare.
Returns:
float64 - the smallest number among the inputs. error - when a value cannot be converted.
Example:
{{ 5.2, 3.8, 8.1, 2.6 | minf }} // Output: 2.6
func (*NumericRegistry) Mod ¶
func (nr *NumericRegistry) Mod(x, y any) (any, error)
Mod returns the remainder of division of 'x' by 'y'.
Parameters:
x any, y any - numbers to divide, expected to be numeric or convertible to float64.
Returns:
any - the remainder, converted to the type of 'x'. error - when a value cannot be converted.
Example:
{{ 10, 4 | mod }} // Output: 2
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.
Example:
{{ 5, 3, 2 | mulInt }} // Output: 30
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.
Example:
{{ 5.5, 2.0, 2.0 | mulf }} // Output: 22.0
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:
num 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.
Example:
{{ 3.746, 2, 0.5 | round }} // Output: 3.75
! NEED TO CHANGE PARAMS ORDER
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.
Example:
{{ 10, 3, 2 | sub }} // Output: 5
func (*NumericRegistry) Uid ¶
func (nr *NumericRegistry) Uid() string
Uid returns the unique identifier of the registry.