{"record":{"id":"2fb51ec8d3e8f590","repo":"qax-os/excelize","slug":"num","errorCode":"#NUM!","errorMessage":"#NUM!","messagePattern":"#NUM!","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"calc.go","lineNumber":10240,"sourceCode":"\t\treturn (((((c[1]*q+c[2])*q+c[3])*q+c[4])*q+c[5])*q + c[6]) /\n\t\t\t((((d[1]*q+d[2])*q+d[3])*q+d[4])*q + 1), nil\n\t} else if pLow <= p && p <= pHigh {\n\t\t// Rational approximation for central region.\n\t\tq := p - 0.5\n\t\tr := q * q\n\t\tf1 := ((((a[1]*r+a[2])*r+a[3])*r+a[4])*r + a[5]) * r\n\t\tf2 := (b[1]*r + b[2]) * r\n\t\tf3 := ((math.Nextafter(f2, f2)+b[3])*r + b[4]) * r\n\t\tf4 := (math.Nextafter(f3, f3) + b[5]) * r\n\t\treturn (math.Nextafter(f1, f1) + a[6]) * q /\n\t\t\t(math.Nextafter(f4, f4) + 1), nil\n\t} else if pHigh < p && p < 1 {\n\t\t// Rational approximation for upper region.\n\t\tq := math.Sqrt(-2 * math.Log(1-p))\n\t\treturn -(((((c[1]*q+c[2])*q+c[3])*q+c[4])*q+c[5])*q + c[6]) /\n\t\t\t((((d[1]*q+d[2])*q+d[3])*q+d[4])*q + 1), nil\n\t}\n\treturn 0, errors.New(formulaErrorNUM)\n}\n\n// kth is an implementation of the formula functions LARGE and SMALL.\nfunc (fn *formulaFuncs) kth(name string, argsList *list.List) formulaArg {\n\tif argsList.Len() != 2 {\n\t\treturn newErrorFormulaArg(formulaErrorVALUE, fmt.Sprintf(\"%s requires 2 arguments\", name))\n\t}\n\tarray := argsList.Front().Value.(formulaArg).ToList()\n\targK := argsList.Back().Value.(formulaArg).ToNumber()\n\tif argK.Type != ArgNumber {\n\t\treturn argK\n\t}\n\tk := int(argK.Number)\n\tif k < 1 {\n\t\treturn newErrorFormulaArg(formulaErrorNUM, \"k should be > 0\")\n\t}\n\tvar data []float64\n\tfor _, arg := range array {","sourceCodeStart":10222,"sourceCodeEnd":10258,"githubUrl":"https://github.com/qax-os/excelize/blob/f2483381fbfbe432a6baa98d48a1c277183f3285/calc.go#L10222-L10258","documentation":"This site is the tail of the inverse standard normal CDF implementation (used by NORMSINV/NORM.INV/NORMDIST-style functions). It covers only three probability regions; if p is outside (0,1) (p <= 0, p >= 1, or NaN), the rational approximations do not apply and the function returns errors.New(formulaErrorNUM), i.e. #NUM!, matching Excel's #NUM! for invalid numeric arguments.","triggerScenarios":"Calling NORMSINV(p)/NORM.INV(...) (directly or via related statistical functions) with probability p <= 0, p >= 1, or a non-numeric argument coerced to an out-of-range value.","commonSituations":"Computing z-scores from percentile columns where a cell is 0 or 1 exactly (e.g. 100%); cumulative probabilities computed with floating-point overshoot to 1.0000000001; empty cells coerced to 0 then passed as p.","solutions":["Clamp p into an open interval, e.g. =NORMSINV(MIN(MAX(p,0.0000001),0.9999999))","Compute the percentile with a guard: =IF(OR(p<=0,p>=1),NA(),NORMSINV(p))","Fix upstream data so probabilities are strictly between 0 and 1","Catch the Calculate error and treat #NUM! as out-of-domain input in your application"],"exampleFix":"// before: =NORMSINV(A1) where A1 = 1 -> #NUM!\n// after: =NORMSINV(MIN(MAX(A1,0.0000001),0.9999999))","handlingStrategy":"validation","validationCode":"p, _ := strconv.ParseFloat(cellValue, 64)\nif !(p > 0 && p < 1) {\n    return fmt.Errorf(\"probability %v out of (0,1); NORMSINV would return #NUM!\", p)\n}","typeGuard":null,"tryCatchPattern":"if _, err := f.Calculate(); err != nil {\n    if strings.Contains(err.Error(), \"#NUM!\") {\n        // out-of-domain statistical input; clamp or skip\n    }\n    return err\n}","preventionTips":["Clamp probabilities away from exact 0 and 1 before NORMSINV/NORM.INV","Watch for floating-point cumulative probabilities that exceed 1.0","Guard formulas with IF(OR(p<=0,p>=1),fallback,NORMSINV(p))"],"tags":["excel","formula","num-error","statistics","out-of-range"],"backgroundTag":"formula-num-error","analyzedSha":"f2483381fbfbe432a6baa98d48a1c277183f3285","analyzedAt":"2026-09-02T01:26:19.299Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}