mirror of
https://github.com/bitcoin-s/bitcoin-s.git
synced 2025-03-15 20:30:17 +01:00
remove redundant function checkResult
This commit is contained in:
parent
243e6cb65b
commit
ffcfe360a6
1 changed files with 6 additions and 16 deletions
|
@ -37,10 +37,10 @@ sealed abstract class Number[T <: Number[T]]
|
||||||
/** Factory function to create the underlying T, for instance a UInt32 */
|
/** Factory function to create the underlying T, for instance a UInt32 */
|
||||||
def apply: A => T
|
def apply: A => T
|
||||||
|
|
||||||
override def +(num: T): T = apply(checkResult(underlying + num.underlying))
|
override def +(num: T): T = apply(underlying + num.underlying)
|
||||||
override def -(num: T): T = apply(checkResult(underlying - num.underlying))
|
override def -(num: T): T = apply(underlying - num.underlying)
|
||||||
override def *(factor: BigInt): T = apply(checkResult(underlying * factor))
|
override def *(factor: BigInt): T = apply(underlying * factor)
|
||||||
override def *(num: T): T = apply(checkResult(underlying * num.underlying))
|
override def *(num: T): T = apply(underlying * num.underlying)
|
||||||
|
|
||||||
override def compare(num: T): Int = underlying compare num.underlying
|
override def compare(num: T): Int = underlying compare num.underlying
|
||||||
|
|
||||||
|
@ -64,20 +64,10 @@ sealed abstract class Number[T <: Number[T]]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
def |(num: T): T = apply(checkResult(underlying | num.underlying))
|
def |(num: T): T = apply(underlying | num.underlying)
|
||||||
def &(num: T): T = apply(checkResult(underlying & num.underlying))
|
def &(num: T): T = apply(underlying & num.underlying)
|
||||||
def unary_- : T = apply(-underlying)
|
def unary_- : T = apply(-underlying)
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if the given result is within the range
|
|
||||||
* of this number type
|
|
||||||
*/
|
|
||||||
private def checkResult(result: BigInt): A = {
|
|
||||||
require((result & andMask) == result,
|
|
||||||
"Result was out of bounds, got: " + result)
|
|
||||||
result
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Checks if the given nubmer is within range of a Int */
|
/** Checks if the given nubmer is within range of a Int */
|
||||||
private def checkIfInt(num: T): Try[Unit] = {
|
private def checkIfInt(num: T): Try[Unit] = {
|
||||||
if (num.toBigInt >= Int.MaxValue || num.toBigInt <= Int.MinValue) {
|
if (num.toBigInt >= Int.MaxValue || num.toBigInt <= Int.MinValue) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue