FloatingPointComparator constructor
- FloatingPoint a,
- FloatingPoint b, {
- bool alignExplicitJBit = false,
- String name = 'floating_point_comparator',
- bool reserveName = false,
- bool reserveDefinitionName = false,
- 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);
}