{"record":{"id":"4cd8d3b4c28d4f3d","repo":"gohugoio/hugo","slug":"sqrt-operator-can-t-be-used-with-non-integer-or-fl","errorCode":null,"errorMessage":"Sqrt operator can't be used with non integer or float value","messagePattern":"Sqrt operator can't be used with non integer or float value","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"tpl/math/math.go","lineNumber":244,"sourceCode":"\t}\n\n\treturn _round(xf), nil\n}\n\n// Sin returns the sine of the radian argument n.\nfunc (ns *Namespace) Sin(n any) (float64, error) {\n\taf, err := cast.ToFloat64E(n)\n\tif err != nil {\n\t\treturn 0, errors.New(\"requires a numeric argument\")\n\t}\n\treturn math.Sin(af), nil\n}\n\n// Sqrt returns the square root of the number n.\nfunc (ns *Namespace) Sqrt(n any) (float64, error) {\n\taf, err := cast.ToFloat64E(n)\n\tif err != nil {\n\t\treturn 0, errors.New(\"Sqrt operator can't be used with non integer or float value\")\n\t}\n\n\treturn math.Sqrt(af), nil\n}\n\n// Sub subtracts multivalued.\nfunc (ns *Namespace) Sub(inputs ...any) (any, error) {\n\treturn ns.doArithmetic(inputs, '-')\n}\n\n// Sum returns the sum of all numbers in inputs. Any slices in inputs are flattened.\nfunc (ns *Namespace) Sum(inputs ...any) (sum float64, err error) {\n\tfn := func(x, y float64) float64 {\n\t\treturn x + y\n\t}\n\treturn ns.applyOpToScalarsOrSlices(\"Sum\", fn, inputs...)\n}\n","sourceCodeStart":226,"sourceCodeEnd":262,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/tpl/math/math.go#L226-L262","documentation":"Returned by math.Sqrt when its argument cannot be converted to float64. Despite the message mentioning integer or float, the implementation uses cast.ToFloat64E which accepts ints, floats, and numeric strings; non-numeric values are rejected. Note: passing a negative number will not error here but math.Sqrt returns NaN.","triggerScenarios":"Calling {{ math.Sqrt \"foo\" }}, {{ math.Sqrt $nil }}, or {{ math.Sqrt $slice }}. Passing a non-numeric .Params value is the most common cause.","commonSituations":"Statistical/layout computations in templates; params typed as strings; accidentally passing a resource or page object instead of a measurement.","solutions":["Cast the input: {{ math.Sqrt (float $x) }}.","Default nil values: {{ math.Sqrt ($x | default 0) }}.","Ensure front matter uses numeric types."],"exampleFix":"// before\n{{ math.Sqrt .Params.value }}\n// after\n{{ math.Sqrt (float .Params.value) }}","handlingStrategy":"validation","validationCode":"{{ math.Sqrt (float $x) }}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Cast inputs to float.","Default nil values to 0.","Avoid passing resource or page objects to math functions."],"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"}