sort<FpType extends FloatingPoint> static method
- (FpType, FpType) toSort
Sort two FloatingPoints and swap them if necessary so that the larger of the two is the first element in the returned tuple.
Implementation
static (FpType larger, FpType smaller) sort<FpType extends FloatingPoint>(
(FpType, FpType) toSort) {
final ae = toSort.$1.exponent;
final be = toSort.$2.exponent;
final am = toSort.$1.mantissa;
final bm = toSort.$2.mantissa;
final doSwap = (ae.lt(be) |
(ae.eq(be) & am.lt(bm)) |
((ae.eq(be) & am.eq(bm)) & toSort.$1.sign))
.named('doSwap');
final swapped = swap(doSwap, toSort);
FpType clone({String? name}) => toSort.$1.clone(name: name) as FpType;
final larger = clone(name: 'larger')..gets(swapped.$1);
final smaller = clone(name: 'smaller')..gets(swapped.$2);
return (larger, smaller);
}