From 0bcce65d5e3001b1b7098aa2c1ccd60fcc2a6628 Mon Sep 17 00:00:00 2001 From: chick Date: Thu, 12 Dec 2019 12:06:15 -0800 Subject: - New trait HasBinaryPoint which provides literal values as double and big decimal - made .F and .I work for creating fixed point and interval lits from big decimal - Added NumObject trait which provides new math conversions - Made a Num object that extends NumObject - Add this trait to FixedPoint and Interval for backward compatibility - Removed code that is now in NumObject, keeping things DRY - Add tests to FixedPointSpec to show lit conversion to double and big decimal - Add tests to IntervalSpec to show lit conversion to double and big decimal - Add tests to LiteralExtractorSpec to show general math conversions between BigInts with binary points and double and big decimal --- src/test/scala/chiselTests/FixedPointSpec.scala | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'src/test/scala/chiselTests/FixedPointSpec.scala') diff --git a/src/test/scala/chiselTests/FixedPointSpec.scala b/src/test/scala/chiselTests/FixedPointSpec.scala index a928f08e..e97c6be7 100644 --- a/src/test/scala/chiselTests/FixedPointSpec.scala +++ b/src/test/scala/chiselTests/FixedPointSpec.scala @@ -19,6 +19,21 @@ class FixedPointLiteralSpec extends FlatSpec with Matchers { initialDouble should be(finalDouble) } + + they should "have their literals support to double and to BigDecimal" in { + val d = -7.125 + val lit1 = d.F(3.BP) + lit1.litToDouble should be (d) + + val d2 = BigDecimal("1232123213131123.125") + val lit2 = d2.F(3.BP) + lit2.litToBigDecimal should be (d2) + + // Numbers that are too big will throw exception + intercept[ChiselException] { + lit2.litToDouble + } + } } //noinspection TypeAnnotation,EmptyParenMethodAccessedAsParameterless -- cgit v1.2.3