Merge pull request #1144 from skirpichev/ulp
test / linter (push) Failing after 0s
test / coverage (push) Failing after 0s
test / docs (push) Failing after 1s
Publish on PyPI / Build distributions (push) Has been cancelled
test / frozen-version (push) Has been cancelled
test / tests (true, 3.x) (push) Has been cancelled
Publish on PyPI / Publish distributions to PyPI (push) Has been cancelled
test / tests (false, false, 3.14t) (push) Has been cancelled
test / tests (false, false, 3.15) (push) Has been cancelled
test / tests (false, false, 3.10) (push) Has been cancelled
test / tests (false, false, 3.11) (push) Has been cancelled
test / tests (false, false, 3.12) (push) Has been cancelled
test / tests (false, false, 3.13) (push) Has been cancelled
test / tests (false, false, 3.14) (push) Has been cancelled
test / tests (false, false, 3.15t) (push) Has been cancelled
test / tests (true, pypy3.11) (push) Has been cancelled

Add ulp(), see #1009
This commit is contained in:
Sergey B Kirpichev
2026-07-24 13:37:18 +03:00
committed by GitHub
3 changed files with 15 additions and 0 deletions
+1
View File
@@ -222,6 +222,7 @@ mertens = mp.mertens
ldexp = mp.ldexp
frexp = mp.frexp
ulp = mp.ulp
fsum = mp.fsum
fdot = mp.fdot
+1
View File
@@ -161,6 +161,7 @@ class FPContext(StandardBaseContext):
ldexp = math.ldexp
frexp = math.frexp
hypot = math.hypot
ulp = math.ulp
def mag(ctx, z):
if z:
+13
View File
@@ -783,6 +783,19 @@ maxterms, or set zeroprec."""
y, n = libmp.libmpf.mpf_frexp(x._mpf_)
return ctx.make_mpf(y), n
def ulp(ctx, x):
"""
Return the value of the least significant bit of the `x`.
>>> from mpmath import ulp
>>> ulp(1)
mpf('2.2204460492503131e-16')
"""
x = ctx.convert(x)
*_, e, bc = x._mpf_
return ctx.make_mpf((0, 1, e + bc - ctx.prec, 1))
def fneg(ctx, x, **kwargs):
"""
Negates the number *x*, giving a floating-point result, optionally