All Downloads are FREE. Search and download functionalities are using the official Maven repository.

spire.math.ScalaWrappers.scala Maven / Gradle / Ivy

The newest version!
package spire.math

import spire.algebra._

trait ScalaEquivWrapper[A] extends scala.math.Equiv[A] {
  def eq: Eq[A]

  def equiv(x:A, y:A): Boolean = eq.eqv(x, y)
}

trait ScalaOrderingWrapper[A] extends scala.math.Ordering[A] {
  def order: Order[A]

  def compare(x:A, y:A): Int = order.compare(x, y)

  override def equiv(x:A, y:A): Boolean = order.eqv(x, y)
  override def gt(x:A, y:A): Boolean = order.gt(x, y)
  override def gteq(x:A, y:A): Boolean = order.gteqv(x, y)
  override def lt(x:A, y:A): Boolean = order.lt(x, y)
  override def lteq(x:A, y:A): Boolean = order.lteqv(x, y)

  override def min(x:A, y:A): A = order.min(x, y)
  override def max(x:A, y:A): A = order.max(x, y)
}

trait ScalaNumericWrapper[A] extends scala.math.Numeric[A]
with ScalaOrderingWrapper[A] {
  def structure: Ring[A]
  def conversions: ConvertableFrom[A]
  def signed: Signed[A]
  def order: Order[A]

  def fromInt(x: Int) = structure.fromInt(x)
  def negate(x:A) = structure.negate(x)
  def minus(x:A, y:A) = structure.minus(x, y)
  def plus(x:A, y:A) = structure.plus(x, y)
  def times(x:A, y:A) = structure.times(x, y)
  override def zero: A = structure.zero
  override def one: A = structure.one

  def toDouble(x: A) = conversions.toDouble(x)
  def toFloat(x: A) = conversions.toFloat(x)
  def toInt(x: A) = conversions.toInt(x)
  def toLong(x: A) = conversions.toLong(x)

  override def signum(x:A): Int = signed.signum(x)
  override def abs(x: A): A = signed.abs(x)
}

trait ScalaFractionalWrapper[A] extends ScalaNumericWrapper[A]
with scala.math.Fractional[A] {
  def structure: Field[A]

  def div(x:A, y:A) = structure.div(x, y)
}

trait ScalaIntegralWrapper[A] extends ScalaNumericWrapper[A]
with scala.math.Integral[A]{
  def structure: EuclideanRing[A]

  def quot(x:A, y:A): A = structure.quot(x, y)
  def rem(x:A, y:A): A = structure.mod(x, y)
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy