typelevel / algebra
1
package algebra
2
package instances
3

4
import java.math.MathContext
5

6
import algebra.ring._
7

8
package object bigDecimal extends BigDecimalInstances
9

10
trait BigDecimalInstances extends cats.kernel.instances.BigDecimalInstances {
11 2
  implicit val bigDecimalAlgebra: BigDecimalAlgebra = new BigDecimalAlgebra()
12
}
13

14
class BigDecimalAlgebra(mc: MathContext) extends Field[BigDecimal] with Serializable {
15 2
  def this() = this(MathContext.UNLIMITED)
16

17 2
  val zero: BigDecimal = BigDecimal(0, mc)
18 2
  val one: BigDecimal = BigDecimal(1, mc)
19

20 2
  def plus(a: BigDecimal, b: BigDecimal): BigDecimal = a + b
21 2
  def negate(a: BigDecimal): BigDecimal = -a
22 2
  override def minus(a: BigDecimal, b: BigDecimal): BigDecimal = a - b
23

24 2
  def times(a: BigDecimal, b: BigDecimal): BigDecimal = a * b
25 2
  def div(a: BigDecimal, b: BigDecimal): BigDecimal = a / b
26

27 2
  override def pow(a: BigDecimal, k: Int): BigDecimal = a pow k
28

29 2
  override def fromInt(n: Int): BigDecimal = BigDecimal(n, mc)
30 2
  override def fromBigInt(n: BigInt): BigDecimal = BigDecimal(n, mc)
31
}

Read our documentation on viewing source code .

Loading