Skip to content

Commit

Permalink
Add messages to require statements in Math (#3385) (#3387)
Browse files Browse the repository at this point in the history
* log2 functions
* unsignedBitLength

(cherry picked from commit 88fecfc)

Co-authored-by: Jack Koenig <koenig@sifive.com>
  • Loading branch information
mergify[bot] and jackkoenig authored Jun 27, 2023
1 parent bea473e commit 9536927
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/main/scala/chisel3/util/Math.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ object log2Up {
//@chiselRuntimeDeprecated
//@deprecated("Use log2Ceil instead", "chisel3")
def apply(in: BigInt): Int = {
require(in >= 0)
require(in >= 0, s"log2Up is only defined on integers >= 0, got $in")
1.max((in - 1).bitLength)
}
def apply(in: Int): Int = apply(BigInt(in))
Expand All @@ -50,7 +50,7 @@ object log2Up {
*/
object log2Ceil {
def apply(in: BigInt): Int = {
require(in > 0)
require(in > 0, s"log2 is only defined on integers > 0, got $in")
(in - 1).bitLength
}
def apply(in: Int): Int = apply(BigInt(in))
Expand Down Expand Up @@ -114,7 +114,7 @@ object unsignedBitLength {
* @return - an Int representing the number of bits to encode.
*/
def apply(in: BigInt): Int = {
require(in >= 0)
require(in >= 0, s"Unsigned integers must be non-negative, got $in")
in.bitLength
}
}
Expand Down

0 comments on commit 9536927

Please sign in to comment.