-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1319 from non/topic/kernel-bigDecimal
Topic/kernel big decimal
- Loading branch information
Showing
5 changed files
with
83 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
kernel/src/main/scala/cats/kernel/instances/bigDecimal.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package cats.kernel | ||
package instances | ||
|
||
package object bigDecimal extends BigDecimalInstances // scalastyle:ignore package.object.name | ||
|
||
trait BigDecimalInstances { | ||
implicit val catsKernelStdOrderForBigDecimal: Order[BigDecimal] = | ||
new BigDecimalOrder | ||
implicit val catsKernelStdGroupForBigDecimal: CommutativeGroup[BigDecimal] = | ||
new BigDecimalGroup | ||
} | ||
|
||
class BigDecimalGroup extends CommutativeGroup[BigDecimal] { | ||
val empty: BigDecimal = BigDecimal(0) | ||
def combine(x: BigDecimal, y: BigDecimal): BigDecimal = x + y | ||
def inverse(x: BigDecimal): BigDecimal = -x | ||
override def remove(x: BigDecimal, y: BigDecimal): BigDecimal = x - y | ||
} | ||
|
||
class BigDecimalOrder extends Order[BigDecimal] { | ||
|
||
def compare(x: BigDecimal, y: BigDecimal): Int = x compare y | ||
|
||
override def eqv(x: BigDecimal, y: BigDecimal): Boolean = x == y | ||
override def neqv(x: BigDecimal, y: BigDecimal): Boolean = x != y | ||
override def gt(x: BigDecimal, y: BigDecimal): Boolean = x > y | ||
override def gteqv(x: BigDecimal, y: BigDecimal): Boolean = x >= y | ||
override def lt(x: BigDecimal, y: BigDecimal): Boolean = x < y | ||
override def lteqv(x: BigDecimal, y: BigDecimal): Boolean = x <= y | ||
|
||
override def min(x: BigDecimal, y: BigDecimal): BigDecimal = x min y | ||
override def max(x: BigDecimal, y: BigDecimal): BigDecimal = x max y | ||
} |