FloatingPointComparator constructor

FloatingPointComparator(
  1. FloatingPoint a,
  2. FloatingPoint b, {
  3. bool alignExplicitJBit = false,
  4. String name = 'floating_point_comparator',
  5. bool reserveName = false,
  6. bool reserveDefinitionName = false,
  7. String? definitionName,
})

Creates a comparator for two matching formats.

Implementation

FloatingPointComparator(
  FloatingPoint a,
  FloatingPoint b, {
  bool alignExplicitJBit = false,
  super.name = 'floating_point_comparator',
  super.reserveName,
  super.reserveDefinitionName,
  String? definitionName,
}) : super(
        definitionName: definitionName ??
            'FloatingPointComparator_${_formatIdentity(a)}'
                '${a.explicitJBit ? '_J1' : ''}',
      ) {
  _requireSupportedFormat(a, alignExplicitJBit);
  _requireSupportedFormat(b, alignExplicitJBit);
  if (a.exponent.width != b.exponent.width ||
      a.mantissa.width != b.mantissa.width ||
      a.explicitJBit != b.explicitJBit ||
      a.subNormalAsZero != b.subNormalAsZero ||
      a.supportsInfinities != b.supportsInfinities ||
      a.supportsSignalingNaNs != b.supportsSignalingNaNs) {
    throw ArgumentError('Floating-point operand formats must match.');
  }
  a = addTypedInput('a', a);
  b = addTypedInput('b', b);
  if (a.explicitJBit) {
    a = canonicalizeExplicitJBit(a);
    b = canonicalizeExplicitJBit(b);
  }
  final resolvedA = a.resolveSubNormalAsZero();
  final resolvedB = b.resolveSubNormalAsZero();
  addOutput('unordered') <= a.isNaN | b.isNaN;
  addOutput('equal') <= resolvedA.eq(resolvedB);
  addOutput('less') <= resolvedA.lt(resolvedB);
  addOutput('greater') <= resolvedA.gt(resolvedB);
}