def ulp(x):
 x = abs(float(x))
 if (math.isnan(x) or math.isinf(x)):
  return x
 n = struct.unpack('<q', struct.pack('<d', x))[0]
 x_next = struct.unpack('<d', struct.pack('<q', (n + 1)))[0]
 if math.isinf(x_next):
  x_prev = struct.unpack('<d', struct.pack('<q', (n - 1)))[0]
  return (x - x_prev)
 else:
  return (x_next - x)

def ulp ( x ) : x = abs ( float ( x ) ) if ( math . isnan ( x ) or math . isinf ( x ) ) : return x n = struct . unpack ( '<q' , struct . pack ( '<d' , x ) ) [ 0 ] x_next = struct . unpack ( '<d' , struct . pack ( '<q' , ( n + 1 ) ) ) [ 0 ] if math . isinf ( x_next ) : x_prev = struct . unpack ( '<d' , struct . pack ( '<q' , ( n - 1 ) ) ) [ 0 ] return ( x - x_prev ) else : return ( x_next - x )
return the value of the least significant bit of a float x .