{"record":{"id":"3447e62864194f91","repo":"TheAlgorithms/C-Sharp","slug":"input-tanh","errorCode":null,"errorMessage":"input","messagePattern":"input","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Algorithms/Numeric/Tanh.cs","lineNumber":33,"sourceCode":"    /// </summary>\n    /// <param name=\"input\">The input real number.</param>\n    /// <returns>The output real number in the range [-1, 1].</returns>\n    public static double Compute(double input)\n    {\n        // For a single double, we can directly use the optimized Math.Tanh method.\n        return Math.Tanh(input);\n    }\n\n    /// <summary>\n    ///     Compute the Hyperbolic Tangent (Tanh) function element-wise for a vector.\n    /// </summary>\n    /// <param name=\"input\">The input vector of real numbers.</param>\n    /// <returns>The output vector of real numbers, where each element is in the range [-1, 1].</returns>\n    public static double[] Compute(double[] input)\n    {\n        if (input is null)\n        {\n            throw new ArgumentNullException(nameof(input));\n        }\n\n        if (input.Length == 0)\n        {\n            throw new ArgumentException(\"Array is empty.\");\n        }\n\n        var outputVector = new double[input.Length];\n\n        for (var index = 0; index < input.Length; index++)\n        {\n            // Apply Tanh to each element using the optimized Math.Tanh method.\n            outputVector[index] = Math.Tanh(input[index]);\n        }\n\n        return outputVector;\n    }\n}","sourceCodeStart":15,"sourceCodeEnd":51,"githubUrl":"https://github.com/TheAlgorithms/C-Sharp/blob/96e2905cab7bc6b33ac0a34ee5bb82ddccbcbb6c/Algorithms/Numeric/Tanh.cs#L15-L51","documentation":"Tanh.Compute applies the hyperbolic tangent element-wise and requires a non-null input array. A null reference cannot be iterated, so the method throws ArgumentNullException naming the 'input' parameter instead of failing with a NullReferenceException.","triggerScenarios":"Calling Tanh.Compute(null), typically when an array field/property was never initialized or a method returned null instead of an empty array.","commonSituations":"Uninitialized class fields for activations; a lookup that returned null in older API versions; optional configuration vectors left unset.","solutions":["Initialize the array before calling (e.g. Array.Empty<double>() instead of null)","Add a null check at the call site and skip/return a default result when null","Fix the producer that returns null to return an empty array instead"],"exampleFix":"// before\ndouble[] activations = null;\nvar out = Tanh.Compute(activations); // throws\n// after\nvar out = Tanh.Compute(activations ?? Array.Empty<double>());","handlingStrategy":"type-guard","validationCode":"if (input is null) throw new ArgumentNullException(nameof(input));","typeGuard":"static bool IsNotNull<T>(T[]? a) => a is not null;","tryCatchPattern":"try { return Tanh.Compute(input); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"input\") { /* initialize or skip */ }","preventionTips":["Initialize array fields with Array.Empty<T>() at declaration","Avoid returning null arrays from methods; prefer empty arrays","Enable nullable reference types to catch nulls at compile time"],"tags":["null-reference","argument-validation","numeric"],"backgroundTag":"null-argument","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"}