{"record":{"id":"5730d52b0b352e8e","repo":"gohugoio/hugo","slug":"pow-operator-can-t-be-used-with-non-float-value","errorCode":null,"errorMessage":"Pow operator can't be used with non-float value","messagePattern":"Pow operator can't be used with non-float value","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"tpl/math/math.go","lineNumber":202,"sourceCode":"}\n\n// Mul multiplies the multivalued numbers n1 and n2 or more values.\nfunc (ns *Namespace) Mul(inputs ...any) (any, error) {\n\treturn ns.doArithmetic(inputs, '*')\n}\n\n// Pi returns the mathematical constant pi.\nfunc (ns *Namespace) Pi() float64 {\n\treturn math.Pi\n}\n\n// Pow returns n1 raised to the power of n2.\nfunc (ns *Namespace) Pow(n1, n2 any) (float64, error) {\n\taf, erra := cast.ToFloat64E(n1)\n\tbf, errb := cast.ToFloat64E(n2)\n\n\tif erra != nil || errb != nil {\n\t\treturn 0, errors.New(\"Pow operator can't be used with non-float value\")\n\t}\n\n\treturn math.Pow(af, bf), nil\n}\n\n// Product returns the product of all numbers in inputs. Any slices in inputs are flattened.\nfunc (ns *Namespace) Product(inputs ...any) (product float64, err error) {\n\tfn := func(x, y float64) float64 {\n\t\treturn x * y\n\t}\n\treturn ns.applyOpToScalarsOrSlices(\"Product\", fn, inputs...)\n}\n\n// Rand returns, as a float64, a pseudo-random number in the half-open interval [0.0,1.0).\nfunc (ns *Namespace) Rand() float64 {\n\treturn rand.Float64()\n}\n","sourceCodeStart":184,"sourceCodeEnd":220,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/tpl/math/math.go#L184-L220","documentation":"Thrown by the math.Pow template function when either of its two arguments cannot be converted to a float64 via cast.ToFloat64E. Pow delegates to math.Pow(af, bf), so both operands must be numeric (int, float, or a numeric string). Any non-numeric value (nil, bool, struct, slice, non-numeric string) triggers this error.","triggerScenarios":"Calling {{ math.Pow \"abc\" 2 }}, {{ math.Pow $page 2 }}, or {{ math.Pow nil 3 }} in a Hugo template. Also triggered by passing a .Params value that resolved to a non-numeric type (e.g. a map or slice).","commonSituations":"Front matter values typed as strings that look numeric but are not coerced; passing a page object or .Scratch Get result that is nil; migrating templates where a value used to be an int but became a string after a Hugo version change.","solutions":["Ensure both arguments are numeric: use {{ math.Pow (float $base) (float $exp) }} or cast in front matter as numbers.","Default nil/empty values before calling: {{ $base | default 0 }} then pass to math.Pow.","If the value comes from .Params, declare it as a number in front matter (e.g. weight: 2 not weight: \"2\")."],"exampleFix":"// before\n{{ math.Pow $base $exp }}\n// after\n{{ math.Pow (float $base) (float $exp) }}","handlingStrategy":"validation","validationCode":"// In template: coerce before calling\n{{ math.Pow (float $base) (float $exp) }}\n\n// In Go: check numeric kind before invoking the namespace\nfunc isNumeric(v any) bool {\n    switch reflect.ValueOf(v).Kind() {\n    case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64,\n         reflect.Float32, reflect.Float64, reflect.Uint, reflect.Uint8, reflect.Uint16,\n         reflect.Uint32, reflect.Uint64:\n        return true\n    }\n    return false\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Cast template values with (float ...) before passing to math functions.","Declare numeric front matter without quotes so YAML parses them as numbers.","Default nil params: {{ $v | default 0 }} before arithmetic."],"tags":["template","math","type-conversion","hugo"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}