mirror of
https://github.com/bitcoin-s/bitcoin-s.git
synced 2025-02-24 23:08:31 +01:00
Adding lowerbounds invariant on .toInt inside of NumberTypes
This commit is contained in:
parent
8cb8bcc0f2
commit
f2941cb24c
1 changed files with 6 additions and 3 deletions
|
@ -84,6 +84,7 @@ sealed trait UInt32 extends UnsignedNumber with NumberOperations[UInt32] {
|
|||
|
||||
override def toInt = {
|
||||
require(underlying <= Int.MaxValue, "Overflow error when casting " + this + " to an integer.")
|
||||
require(underlying >= 0, "Unsigned integer should not be cast to a number less than 0" + this)
|
||||
underlying.toInt
|
||||
}
|
||||
|
||||
|
@ -134,6 +135,7 @@ sealed trait UInt64 extends UnsignedNumber with NumberOperations[UInt64] {
|
|||
|
||||
override def toInt = {
|
||||
require(underlying <= Int.MaxValue, "Overflow error when casting " + this + " to an integer.")
|
||||
require(underlying >= 0, "Unsigned integer should not be cast to a number less than 0" + this)
|
||||
underlying.toInt
|
||||
}
|
||||
|
||||
|
@ -199,9 +201,9 @@ sealed trait Int32 extends SignedNumber with NumberOperations[Int32] {
|
|||
override def <= (num : Int32): Boolean = underlying <= num.underlying
|
||||
|
||||
override def toInt = {
|
||||
if (underlying > Int.MaxValue) throw new IllegalArgumentException("Overflow error when casting " + this +
|
||||
" to an integer.")
|
||||
else underlying.toInt
|
||||
require(underlying <= Int.MaxValue, "Overflow error when casting " + this + " to an integer.")
|
||||
require(underlying >= Int.MinValue, "Overfolow error when casting " + this + " to an integer.")
|
||||
underlying
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -248,6 +250,7 @@ sealed trait Int64 extends SignedNumber with NumberOperations[Int64] {
|
|||
|
||||
override def toInt = {
|
||||
require(underlying <= Int.MaxValue, "Overflow error when casting " + this + " to an integer.")
|
||||
require(underlying >= Int.MinValue, "Overflow error when casting " + this + " to an integer.")
|
||||
underlying.toInt
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue