Skip to content

Commit a95197d

Browse files
ffranrguggero
authored andcommitted
rfqmath: clarify FixedPoint.WithinTolerance doc for max-based approach
Updated the method documentation to specify that tolerance is applied relative to the larger of the two values. This ensures a 100% tolerance (1,000,000 PPM) always results in a match for any two nonzero values. Added an example comparing max-based and bid-based tolerance, explaining why max-based is more lenient and allows slightly wider spreads in bid-ask scenarios.
1 parent dda465e commit a95197d

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

rfqmath/fixed_point.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,20 @@ func (f FixedPoint[T]) Equals(other FixedPoint[T]) bool {
119119
}
120120

121121
// WithinTolerance returns true if the two FixedPoint values are within the
122-
// given tolerance (in parts per million (PPM)).
122+
// given tolerance, specified in parts per million (PPM).
123+
//
124+
// The tolerance is applied relative to the larger of the two values to ensure
125+
// that a 100% tolerance (1,000,000 PPM) always results in a match for any two
126+
// nonzero values.
127+
//
128+
// This max-based approach (e.g. ask) is more lenient than using the smaller
129+
// value (e.g., bid) as the reference. For example, if the two values are 100
130+
// and 105, a 5% tolerance (50,000 PPM) allows a maximum difference of:
131+
// - Bid-based: 100 × 0.05 = 5 (so 105 is the limit)
132+
// - Max-based: 105 × 0.05 = 5.25 (so 105 is still within tolerance)
133+
//
134+
// This means max-based tolerance accepts slightly wider spreads, making it
135+
// less strict in bid-ask scenarios.
123136
func (f FixedPoint[T]) WithinTolerance(
124137
other FixedPoint[T], tolerancePpm T) (bool, error) {
125138

0 commit comments

Comments
 (0)