Table of Contents

Class NDLog1pExpm1Math

Namespace
NumSharp.Utilities
Assembly
NumSharp.dll

Scalar kernels backing NumSharp's float32 / float64 np.log1p and np.expm1, and the log1p inside np.logaddexp / np.logaddexp2 (NDLogAddExpMath): models of the MSVC UCRT routines that NumPy 2.4.2's win-amd64 wheel calls (npy_log1p / npy_expm1 forward to the C library; the AVX-512 SVML loops that would replace them are not built into that wheel).

log1p / log1pf are BIT-EXACT with NumPy. Probed against np.log1p (parity QA-22, 2026-11-05): the UCRT's log1p is Goldberg's correction over its own log, u = 1 + x; log(u) - ((u - 1) - x) / u, applied for every u (also above 2), and log1pf is the same statements in float32 over logf. Log(double) / Log(float) ARE the UCRT's log / logf, so the model equals NumPy on all 320,000 finite inputs per dtype of the probe (tiny and subnormal, small, (-1, 1), near -1, [1, 10], up to the largest finite value), and the specials are pinned by hand: a NaN comes back untouched (a signalling NaN stays signalling, sign and payload kept), log1p(-1) = -inf, log1p(+inf) = +inf, and every x < -1 (-inf included) gives the POSITIVE quiet NaN (.NET's Math.Log of a negative is the negative one). Faithfully rounded, not correctly rounded: about 6% of float64 results sit one ULP from the true value, exactly where NumPy's do.

expm1 / expm1f are bit-exact outside a band and within 2-3 ULP inside it. Outside [-ln 2, ln 1.5], where |expm1(x)| >= 0.5 and the subtraction loses nothing, the UCRT returns exactly exp(x) - 1 (expf(x) - 1f for float32, whose band ends at the float32 roundings of the same constants): those results are NumPy's bit for bit. Inside the band the UCRT runs an undocumented approximation no public formula reproduces (see Expm1Sun(double)), so the band runs Sun's s_expm1.c — accurate to one ULP of the true value, equal to NumPy on about 58% of float64 and 57% of float32 in-band inputs, never more than 2 (float64) / 3 (float32) ULP from it. A NaN comes back untouched, -0.0 keeps its sign, expm1(-inf) = -1.

The naive forms these replace, Exp(x) - 1 and Log(1 + x) (also what .NET's ExpM1 / LogP1 compute), cancel catastrophically near zero: expm1(1e-8) kept 8 digits, expm1(1e-300) and log1p(1e-300) were 0, and -0.0 became +0.0. A platform pin, like NDHypotMath: Linux NumPy calls glibc's routines, which round differently.

public static class NDLog1pExpm1Math
Inheritance
NDLog1pExpm1Math
Inherited Members

Methods

Expm1(double)

float64 np.expm1 of one element — e^x - 1 accurate near zero: NumPy's bits outside [-ln 2, ln 1.5], Sun's s_expm1.c (within 2 ULP of NumPy) inside it.

public static double Expm1(double x)

Parameters

x double

The argument.

Returns

double

e^x - 1; -1 for -inf (and once e^x underflows), +inf on overflow, the sign of a zero kept, a NaN argument untouched.

Expm1F(float)

float32 np.expm1 of one element: the UCRT's expf(x) - 1f outside the float32 band (NumPy's bits), the float64 Expm1Sun(double) rounded once inside it (within 3 ULP of NumPy's in-band polynomial, which is itself up to 4 ULP from the true value).

public static float Expm1F(float x)

Parameters

x float

The argument.

Returns

float

e^x - 1 in float32, with Expm1(double)'s special values.

Log1p(double)

float64 np.log1p of one element — ln(1 + x) accurate near zero, NumPy's bits on win-amd64 (the UCRT model of the class remarks).

public static double Log1p(double x)

Parameters

x double

The argument.

Returns

double

ln(1 + x); x itself while 1 + x rounds to 1 (so -0.0, subnormals and tiny values return unchanged); -inf at -1; the positive quiet NaN below -1; a NaN argument untouched.

Log1pF(float)

float32 np.log1p of one element — the UCRT's log1pf: Log1p(double)'s statements in float32 over logf, NumPy's bits on win-amd64.

public static float Log1pF(float x)

Parameters

x float

The argument.

Returns

float

ln(1 + x) in float32, with Log1p(double)'s special values (the positive quiet NaN is 0x7FC00000).