{"record":{"id":"16d5f073afcbcade","repo":"TheAlgorithms/C-Sharp","slug":"error-value-is-not-on-interval-0-0-1-0","errorCode":null,"errorMessage":"Error value is not on interval (0.0; 1.0).","messagePattern":"Error value is not on interval \\(0\\.0; 1\\.0\\)\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"Algorithms/Numeric/Series/Maclaurin.cs","lineNumber":93,"sourceCode":"    /// <param name=\"error\">Last term error value.</param>\n    /// <returns>Approximated value of the function in the given point.</returns>\n    /// <exception cref=\"ArgumentException\">Error value is not on interval (0.0; 1.0).</exception>\n    public static double Cos(double x, double error = 0.00001) => ErrorTermWrapper(x, error, CosTerm);\n\n    /// <summary>\n    ///     Wrapper function for calculating approximation with estimated\n    ///     count of terms, where last term value is less than given error.\n    /// </summary>\n    /// <param name=\"x\">Given point.</param>\n    /// <param name=\"error\">Last term error value.</param>\n    /// <param name=\"term\">Indexed term of approximation series.</param>\n    /// <returns>Approximated value of the function in the given point.</returns>\n    /// <exception cref=\"ArgumentException\">Error value is not on interval (0.0; 1.0).</exception>\n    private static double ErrorTermWrapper(double x, double error, Func<double, int, double> term)\n    {\n        if (error <= 0.0 || error >= 1.0)\n        {\n            throw new ArgumentException(\"Error value is not on interval (0.0; 1.0).\");\n        }\n\n        var i = 0;\n        var termCoefficient = 0.0;\n        var result = 0.0;\n\n        do\n        {\n            result += termCoefficient;\n            termCoefficient = term(x, i);\n            i++;\n        }\n        while (Math.Abs(termCoefficient) > error);\n\n        return result;\n    }\n\n    /// <summary>","sourceCodeStart":75,"sourceCodeEnd":111,"githubUrl":"https://github.com/TheAlgorithms/C-Sharp/blob/96e2905cab7bc6b33ac0a34ee5bb82ddccbcbb6c/Algorithms/Numeric/Series/Maclaurin.cs#L75-L111","documentation":"Maclaurin-series approximations of Exp, Sin, and Cos require the caller to supply a truncation error bound that is a probability-like fraction strictly between 0 and 1. The library throws this ArgumentException immediately when error <= 0 or error >= 1 because the number of series terms it computes is derived from that bound; a value outside the open interval cannot define a meaningful tolerance.","triggerScenarios":"Calling Exp, Sin, or Cos (which forward to ErrorTermWrapper) with error = 0, error = 1, a negative error, or a value like 1.0 computed from an off-by-one (e.g. 1 - 0.0).","commonSituations":"Passing a percentage (e.g. 1 meaning 100% precision) instead of a fraction; computing the error as a difference of doubles that rounded to exactly 0 or 1; copy-pasting epsilon values from other numeric libraries with different conventions.","solutions":["Pass a strict open-interval value such as 0.0001 or 1e-6 as the error argument","Clamp and validate the value before calling: if (error <= 0 || error >= 1) adjust it","If you intended 100% accuracy, use double.MaxValue iterations manually or a different API; the series needs a positive tolerance"],"exampleFix":"// before\nvar e = Algorithms.Numeric.Maclaurin.Exp(1.0, 1.0); // throws\n// after\nvar e = Algorithms.Numeric.Maclaurin.Exp(1.0, 0.0001);","handlingStrategy":"validation","validationCode":"if (double.IsNaN(error) || error <= 0.0 || error >= 1.0)\n    throw new ArgumentException(\"error must be strictly between 0 and 1\", nameof(error));","typeGuard":"static bool IsValidError(double e) => !double.IsNaN(e) && e > 0.0 && e < 1.0;","tryCatchPattern":"try { var y = Maclaurin.Exp(x, error); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"interval\")) { /* use a default tolerance like 1e-6 */ }","preventionTips":["Treat error bounds as open-interval fractions, never percentages","Validate the tolerance once at your API boundary","Avoid deriving the tolerance from subtraction of doubles that can yield exactly 0 or 1"],"tags":["argument-validation","numeric","math"],"backgroundTag":"value-out-of-range","analyzedSha":"96e2905cab7bc6b33ac0a34ee5bb82ddccbcbb6c","analyzedAt":"2026-09-13T17:04:01.438Z","contentChangedAt":"2026-09-13T17:04:01.438Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}