func nearestDelta(next, prev int64, precisionBits, prevTrailingZeros uint8) (int64, uint8) {
	d := next - prev
	if d == 0 {
		// Fast path.
		return 0, decIfNonZero(prevTrailingZeros)
	}

	origin := next
	if origin < 0 {
		origin = -origin
		// There is no need in handling special case origin = -1<<63.
	}

	originBits := 64 - uint8(bits.LeadingZeros64(uint64(origin)))
	if originBits <= precisionBits {
		// Cannot zero trailing bits for the given precisionBits.
		return d, decIfNonZero(prevTrailingZeros)
	}

	// originBits > precisionBits. May zero trailing bits in d.
	trailingZeros := originBits - precisionBits
	if trailingZeros > prevTrailingZeros+4 {
		// Probably counter reset. Return d with full precision.
		return d, prevTrailingZeros + 2
	}
	if trailingZeros+4 < prevTrailingZeros {
		// Probably counter reset. Return d with full precision.
		return d, prevTrailingZeros - 2
	}

	// zero trailing bits in d.
	minus := false
	if d < 0 {
		minus = true
		d = -d
		// There is no need in handling special case d = -1<<63.
	}
	nd := int64(uint64(d) & (uint64(1<<64-1) << trailingZeros))
	if minus {
		nd = -nd
	}
	return nd, trailingZeros
}
// nearestDelta returns the nearest value for (next-prev) with the given
// precisionBits.
//
// The second returned value is the number of zeroed trailing bits
// in the returned delta.
nearestDelta returns the nearest value for (next-prev) with the given
precisionBits.

The second returned value is the number of zeroed trailing bits
in the returned delta.
// nearestDelta returns the nearest value for ( next - prev ) with the given // precisionBits . // // The second returned value is the number of zeroed trailing bits // in the returned delta .
func nearestDelta(next, prev int64, precisionBits, prevTrailingZeros uint8) (int64, uint8) {
	d := next - prev
	if d == 0 {
		return 0, decIfNonZero(prevTrailingZeros)
	}
	origin := next
	if origin < 0 {
		origin = -origin
	}
	originBits := 64 - uint8(bits.LeadingZeros64(uint64(origin)))
	if originBits <= precisionBits {
		return d, decIfNonZero(prevTrailingZeros)
	}
	trailingZeros := originBits - precisionBits
	if trailingZeros > prevTrailingZeros+4 {
		return d, prevTrailingZeros + 2
	}
	if trailingZeros+4 < prevTrailingZeros {
		return d, prevTrailingZeros - 2
	}
	minus := false
	if d < 0 {
		minus = true
		d = -d
	}
	nd := int64(uint64(d) & (uint64(1<<64-1) << trailingZeros))
	if minus {
		nd = -nd
	}
	return nd, trailingZeros
}
func nearestDelta ( next , prev int64 , precisionBits , prevTrailingZeros uint8 ) ( int64 , uint8 ) { d := next - prev if d == 0 { return 0 , decIfNonZero ( prevTrailingZeros ) } origin := next if origin < 0 { origin = - origin } originBits := 64 - uint8 ( bits . LeadingZeros64 ( uint64 ( origin ) ) ) if originBits <= precisionBits { return d , decIfNonZero ( prevTrailingZeros ) } trailingZeros := originBits - precisionBits if trailingZeros > prevTrailingZeros + 4 { return d , prevTrailingZeros + 2 } if trailingZeros + 4 < prevTrailingZeros { return d , prevTrailingZeros - 2 } minus := false if d < 0 { minus = true d = - d } nd := int64 ( uint64 ( d ) & ( uint64 ( 1 << 64 - 1 ) << trailingZeros ) ) if minus { nd = - nd } return nd , trailingZeros }
nearestDelta returns the nearest value for (next-prev) with the given
precisionBits.
nearestDelta returns the nearest value for ( next - prev ) with the given precisionBits .
// Fast path. // There is no need in handling special case origin = -1<<63. // Cannot zero trailing bits for the given precisionBits. // originBits > precisionBits. May zero trailing bits in d. // Probably counter reset. Return d with full precision. // Probably counter reset. Return d with full precision. // zero trailing bits in d. // There is no need in handling special case d = -1<<63.