Open the context
Choose the project folder and name the files or behavior involved.
Measure representable-step distance between two finite binary64 floats, treating signed zeros as equal. Test adjacent subnormals and both signs, rejecting integers, infinities and NaN without interpreting the result as relative error.
Choose the project folder and name the files or behavior involved.
Describe the input, expected output and boundaries that must stay intact.
Review the proposed edits and any commands before relying on their result.
Compare actual behavior with the expected result. If a check fails, investigate it before applying more changes.
import math, struct
def ulp_distance(a, b):
if any(type(x) is not float or not math.isfinite(x) for x in (a, b)):
raise ValueError("ulp.finite")
def key(value):
bits = struct.unpack(">Q", struct.pack(">d", value))[0]
magnitude = bits & ((1 << 63)-1)
return (1 << 63)-magnitude if bits >> 63 else (1 << 63)+magnitude
return abs(key(a)-key(b))
The example is a starting point for a real project, not a claim that generated code is already tested. Adjust paths, dependencies and expected behavior to match your application.