typelevel / algebra
1
package algebra
2
package instances
3

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

7
package object byte extends ByteInstances
8

9
trait ByteInstances extends cats.kernel.instances.ByteInstances {
10 2
  implicit val byteAlgebra = new ByteAlgebra
11

12
  val ByteMinMaxLattice: BoundedDistributiveLattice[Byte] =
13 2
    BoundedDistributiveLattice.minMax[Byte](Byte.MinValue, Byte.MaxValue)
14
}
15

16
class ByteAlgebra extends CommutativeRing[Byte] with Serializable {
17

18 2
  def zero: Byte = 0
19 2
  def one: Byte = 1
20

21 2
  def plus(x: Byte, y: Byte): Byte = (x + y).toByte
22 2
  def negate(x: Byte): Byte = (-x).toByte
23 2
  override def minus(x: Byte, y: Byte): Byte = (x - y).toByte
24

25 2
  def times(x: Byte, y: Byte): Byte = (x * y).toByte
26

27
  override def pow(x: Byte, y: Int): Byte =
28 2
    Math.pow(x.toDouble, y.toDouble).toByte
29

30 2
  override def fromInt(n: Int): Byte = n.toByte
31 2
  override def fromBigInt(n: BigInt): Byte = n.toByte
32
}

Read our documentation on viewing source code .

Loading