Hyperbolic sine (sinh) is almost linear near zero and grows in magnitude as you move away from zero.
dotnet add package RecursiveAI.OneMathRequires .NET 10 (net10.0); .NET 9 and earlier aren’t supported.
using RecursiveAI.OneMath; Console.WriteLine(Math64.Sinh(1)); Console.WriteLine(Math64.Sinh(1e-20));
Unzip the example, then dotnet run.
Prints with an English locale:
1.1752011936438014 1E-20
The full program
using RecursiveAI.OneMath; foreach (double x in new[] { 1.0, -1.0, 1e-20, -0.0, 1000.0 }) { double result = Math64.Sinh(x); ulong bits = BitConverter.DoubleToUInt64Bits(result); Console.WriteLine(FormattableString.Invariant( $"sinh({x:R}) = {result:R} (0x{bits:X16})")); }
sinh(1) = 1.1752011936438014 (0x3FF2CD9FC44EB982) sinh(-1) = -1.1752011936438014 (0xBFF2CD9FC44EB982) sinh(1E-20) = 1E-20 (0x3BC79CA10C924223) sinh(-0) = -0 (0x8000000000000000) sinh(1000) = Infinity (0x7FF0000000000000)
The full program prints both invariant decimal text and the 64-bit result in hexadecimal. The bits distinguish negative zero from positive zero even in a display that formats them the same way.
Overflow returns signed infinity rather than throwing, and NaN input produces NaN; use double.IsFinite on the result if your calculation requires a finite value.
Variations
Return a float. When the rest of your calculation uses single precision, use Math32.Sinh for rounding directly to that precision:
using RecursiveAI.OneMath; float result = Math32.Sinh(1f); Console.WriteLine(result);
This prints 1.1752012 with an English locale.
Related recipes
The short answer
Use Math64.Sinh(x) for a double. OneMath’s function contract specifies correct rounding to the nearest representable value, with ties going to the even significand. The same input bits produce the same result bits across platforms. OneMath promises the same bits across runtimes and CPUs; .NET doesn’t make that promise for System.Math.Sinh. Correct rounding doesn’t mean the exact real answer always fits in a double: for example, the printed value for sinh(1) represents the rounded result.
What is the difference between sin and sinh?
Ordinary sine oscillates between −1 and 1. Hyperbolic sine doesn’t repeat or have a fixed upper or lower bound: its formula is (eˣ − e⁻ˣ) / 2. Changing the sign of x changes the sign of sinh(x), as the rows for 1 and −1 show. The formula also explains why large inputs can overflow: one of the exponentials grows while the other shrinks toward zero.
What does sinh return near zero?
Close to zero, the two exponentials in the formula are almost equal. If you round each exponential to a double before subtracting, they can both become 1 and the subtraction can yield zero for a nonzero input. The OneMath function reference documents a higher-precision calculation based on expm1, which computes the exponential minus one without first rounding the exponential to a double.
For inputs with magnitude below 2⁻²⁷, the function reference says sinh(x) rounds back to x. That’s why 1e-20 comes back unchanged and negative zero keeps its sign. It doesn’t mean the mathematical sinh(x) equals x for small nonzero values; the difference is too small to change the rounded result.
Should I use float or double in C#?
Use Math64.Sinh if a saved value, replay, or downstream calculation needs a double. Use Math32.Sinh if the inputs and results are meant to be single precision. The documented rounding is to the result type; widening a result that was already rounded to float doesn’t restore the missing bits. When comparing results across machines, compare the input bits as well: a deterministic function can’t make different inputs agree.