UUlpNacre
Workflows

Coding workflows · Finite binary64 ULP distance

03
Built around your work

A concrete starting point

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.

01

Open the context

Choose the project folder and name the files or behavior involved.

02

Define the change

Describe the input, expected output and boundaries that must stay intact.

03

Inspect the work

Review the proposed edits and any commands before relying on their result.

04

Check the outcome

Compare actual behavior with the expected result. If a check fails, investigate it before applying more changes.

Finite binary64 ULP distance

A concrete starting point
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.

AI coding workspace

Your next change starts here.

Get the Windows app ↗