Skip to content

Commit

Permalink
Add messages to require statements in Math
Browse files Browse the repository at this point in the history
* log2 functions
* unsignedBitLength
  • Loading branch information
jackkoenig committed Jun 27, 2023
1 parent 385feff commit e209e1d
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 e209e1d

Please sign in to comment.