typelevel / algebra
1
package algebra
2
package instances
3

4
import algebra.lattice._
5
import algebra.ring._
6

7
package object short extends ShortInstances
8

9
trait ShortInstances extends cats.kernel.instances.ShortInstances {
10
  implicit val shortAlgebra: ShortAlgebra =
11 2
    new ShortAlgebra
12

13
  val ShortMinMaxLattice: BoundedDistributiveLattice[Short] =
14 2
    BoundedDistributiveLattice.minMax[Short](Short.MinValue, Short.MaxValue)
15
}
16

17
class ShortAlgebra extends CommutativeRing[Short] with Serializable {
18

19 2
  def zero: Short = 0
20 2
  def one: Short = 1
21

22 2
  def plus(x: Short, y: Short): Short = (x + y).toShort
23 2
  def negate(x: Short): Short = (-x).toShort
24 2
  override def minus(x: Short, y: Short): Short = (x - y).toShort
25

26 2
  def times(x: Short, y: Short): Short = (x * y).toShort
27

28
  override def pow(x: Short, y: Int): Short =
29 2
    Math.pow(x.toDouble, y.toDouble).toShort
30

31 2
  override def fromInt(n: Int): Short = n.toShort
32 2
  override def fromBigInt(n: BigInt): Short = n.toShort
33
}

Read our documentation on viewing source code .

Loading