-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e425b74
commit 31605d7
Showing
2 changed files
with
104 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,11 +8,13 @@ | |
// Author: Soner Yaldiz <[email protected]> | ||
|
||
import 'dart:io'; | ||
import 'dart:math'; | ||
import 'package:rohd/rohd.dart'; | ||
import 'package:rohd_hcl/rohd_hcl.dart'; | ||
import 'package:test/test.dart'; | ||
|
||
void main() async { | ||
test('FixedToFloat: simple', () async { | ||
test('Smoke', () async { | ||
final fixed = FixedPoint(signed: true, m: 34, n: 33); | ||
final dut = | ||
FixedToFloatConverter(fixed, exponentWidth: 4, mantissaWidth: 3); | ||
|
@@ -21,4 +23,27 @@ void main() async { | |
fixed.put(FixedPointValue.ofDouble(1.25, signed: true, m: 34, n: 33)); | ||
expect(dut.float.floatingPointValue.toDouble(), 1.25); | ||
}); | ||
|
||
test('Q16.16 to E5M2', () async { | ||
final fixed = FixedPoint(signed: true, m: 16, n: 16); | ||
final dut = | ||
FixedToFloatConverter(fixed, exponentWidth: 5, mantissaWidth: 2); | ||
await dut.build(); | ||
for (var val = 0; val < pow(2, 14); val++) { | ||
final fixedValue = FixedPointValue( | ||
value: LogicValue.ofInt(val, fixed.width), | ||
signed: true, | ||
m: fixed.m, | ||
n: fixed.n); | ||
fixed.put(fixedValue); | ||
final fpv = dut.float.floatingPointValue; | ||
final fpvExpected = FloatingPointValue.ofDouble(fixedValue.toDouble(), | ||
exponentWidth: dut.exponentWidth, mantissaWidth: dut.mantissaWidth); | ||
expect(fpv.sign, fpvExpected.sign); | ||
expect(fpv.exponent.bitString, fpvExpected.exponent.bitString, | ||
reason: 'exponent'); | ||
expect(fpv.mantissa.bitString, fpvExpected.mantissa.bitString, | ||
reason: 'mantissa'); | ||
} | ||
}); | ||
} |