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) sorted, Logic didSwap})
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);
final larger =
(swapped.$1.clone(name: 'larger')..gets(swapped.$1)) as FpType;
final smaller =
(swapped.$2.clone(name: 'smaller')..gets(swapped.$2)) as FpType;
return (sorted: (larger, smaller), didSwap: doSwap);
}