I find myself using the Java function Math.ulp() from time
to time. It has an implementation based on unpacking
a float number, and doing some bit shuffling. How would one
bootstrap ulp() from ISO core standard arithmetic
functions only in Prolog? Here are some test cases:
?- X is -pi, 'Math':ulp(X, Y).
X = -3.141592653589793, Y = 4.440892098500626E-16.
?- 'Math':ulp(1.0E10, X).
X = 1.9073486328125E-6.
Edit 28.10.2022:
I was able to bootstrap the function in SWI-Prolog, as follows,
agrees on the two examples, for positive floating point values only:
ulp(X, Y) :- Y is nexttoward(X, 1.7976931348623157E+308) - X.
?- X is pi, ulp(X, Y).
X = 3.141592653589793,
Y = 4.440892098500626e-16.
?- ulp(1.0E10, X).
X = 1.9073486328125e-6.
But many Prolog systems don't have nexttoward/2.
So I am again left with a bootstrapping problem.