chipsalliance / chipsalliance/chisel
Make literal handling consistent and reliable for FixedPoint and Interval and others
- Dominant language
- Scala
- Stars
- 4.8k
- Forks
- 658
- Avg merge
- 18h 59m
- Merged PRs (30d)
- 14
Description
**Type of issue**: bug report | feature request | documentation
The literal handling mechanisms of Interval and FixedPoint are limited at best and broken at worst. FixedPoint provides a `litToDouble` and `litToDoubleOption` both of which can drop lower significant bits (arguably a bug). Interval has neither. The proper thing to return is a BigDecimal which is a parallel type to BigInt.
**Impact**: API addition (no impact on existing code)
**Development Phase**: proposal
- Add to Num (or some other parent trait of the numeric hardware types)
- `litToBigDecimalOption` and `litToBigDecimal` so they are available to all
- `UInt`, `SInt`, `FixedPoint`, `Interval`
- Add `.U`, `.S`, `.F`, `.I` conversion for BigDecimal
- Possibly throwing exceptions if target type cannot represent the value
- Deprecate `litToDouble` and `litToDouble` as those can be problematic
**Other information**
It's possible this is overkill and should just be implemented ad hoc in the various testers environment.
**What is the use case for changing the behavior?**
literalHandling should be as consistent and symmetric as possible across numeric types
Contributor guide
Assessment
This issue has not been assessed yet.