intel / rohd-hcl

A hardware component library developed with ROHD.
https://pub.dev/packages/rohd_hcl
BSD 3-Clause "New" or "Revised" License
81 stars 23 forks source link

Floating Point Value comparison #114

Closed soneryaldiz closed 2 weeks ago

soneryaldiz commented 1 month ago

Describe the bug

Comparison of floating point values should take sign into consideration.

To Reproduce

fp = FloatingPointValue.ofSeparatedBinaryStrings('1 0101 0101');
expect(fp.compareTo(FloatingPointValue.ofSeparatedBinaryStrings('1 0101 0101')), 0);
expect(fp.compareTo(FloatingPointValue.ofSeparatedBinaryStrings('1 0100 0101')), lessThan(0));
expect(fp.compareTo(FloatingPointValue.ofSeparatedBinaryStrings('1 0101 0100')), lessThan(0));

Expected behavior

No response

Actual behavior

No response

Additional: Dart SDK info

No response

Additional: pubspec.yaml

No response

Additional: Context

No response

desmonddak commented 2 weeks ago

I am not following this test. On the second test, we have fp.exponent = 5 and the new constructed fp has exponent =4. So compare should be greateTthan(0) not lessThan(0).

I am fixing the comparison to also not differentiate between +0 and -0.

soneryaldiz commented 2 weeks ago

Test 2 compares -2^(5-bias) to -2^(4-bias) and the result should be less than zero as the former number is smaller than the latter.

desmonddak commented 2 weeks ago

131 fixes this bug.