Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,6 @@ e93fe9bcf5ff0c314ca676bf9f3b9c8148574786

# Scala Steward: Reformat with scalafmt 3.7.17
7829f68c27c622dee3a8d1329d82a139f183d0c1

# Scala Steward: Reformat with scalafmt 3.9.7
3c8e11c5f9f0bcfab9f7f7502578ba90c41c4bfb
2 changes: 1 addition & 1 deletion .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version=3.7.17
version=3.9.7
runner.dialect = Scala213Source3
fileOverride {
"glob:**/scala-3/**" {
Expand Down
12 changes: 6 additions & 6 deletions core/src/main/scala-3/spire/syntax/macros/literalMacros.scala
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def byte(digits: Expr[StringContext])(using Quotes): Expr[Byte] =

parseNumber(digits.valueOrAbort.parts, BigInt(-128), BigInt(255)) match
case Right(a) => Expr(a.toByte)
case Left(b) =>
case Left(b) =>
report.error(b)
'{ 0.toByte }

Expand All @@ -43,7 +43,7 @@ def short(digits: Expr[StringContext])(using Quotes): Expr[Short] =

parseNumber(digits.valueOrAbort.parts, BigInt(-32768), BigInt(65535)) match
case Right(a) => Expr(a.toShort)
case Left(b) =>
case Left(b) =>
report.error(b)
'{ 0.toShort }

Expand All @@ -52,7 +52,7 @@ def ubyte(digits: Expr[StringContext])(using Quotes): Expr[UByte] =

parseNumber(digits.valueOrAbort.parts, BigInt(0), BigInt(255)) match
case Right(a) => '{ UByte(${ Expr(a.toByte) }) }
case Left(b) =>
case Left(b) =>
report.error(b)
'{ UByte(0) }

Expand All @@ -61,7 +61,7 @@ def ushort(digits: Expr[StringContext])(using Quotes): Expr[UShort] =

parseNumber(digits.valueOrAbort.parts, BigInt(0), BigInt(65535)) match
case Right(a) => '{ UShort(${ Expr(a.toShort) }) }
case Left(b) =>
case Left(b) =>
report.error(b)
'{ UShort(0) }

Expand All @@ -70,7 +70,7 @@ def uint(digits: Expr[StringContext])(using Quotes): Expr[UInt] =

parseNumber(digits.valueOrAbort.parts, BigInt(0), BigInt(4294967295L)) match
case Right(a) => '{ UInt(${ Expr(a.toInt) }) }
case Left(b) =>
case Left(b) =>
report.error(b)
'{ UInt(0) }

Expand All @@ -79,7 +79,7 @@ def ulong(digits: Expr[StringContext])(using Quotes): Expr[ULong] =

parseNumber(digits.valueOrAbort.parts, BigInt(0), BigInt("18446744073709551615")) match
case Right(a) => '{ ULong(${ Expr(a.toLong) }) }
case Left(b) =>
case Left(b) =>
report.error(b)
'{ ULong(0) }

Expand Down
18 changes: 9 additions & 9 deletions core/src/main/scala/spire/math/Algebraic.scala
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ final class Algebraic private (val expr: Algebraic.Expr)
case (that: SafeLong) => isWhole && that == this
case (that: Complex[_]) => that == this
case (that: Quaternion[_]) => that == this
case (that: BigDecimal) =>
case (that: BigDecimal) =>
try {
toBigDecimal(that.mc) == that
} catch {
Expand Down Expand Up @@ -421,10 +421,10 @@ final class Algebraic private (val expr: Algebraic.Expr)
import Expr._

def eval(e: Expr): A = e match {
case ConstantLong(n) => conv.fromLong(n)
case ConstantDouble(n) => conv.fromDouble(n)
case ConstantBigDecimal(n) => conv.fromBigDecimal(n)
case ConstantRational(n) => conv.fromRational(n)
case ConstantLong(n) => conv.fromLong(n)
case ConstantDouble(n) => conv.fromDouble(n)
case ConstantBigDecimal(n) => conv.fromBigDecimal(n)
case ConstantRational(n) => conv.fromRational(n)
case ConstantRoot(poly, i, _, _) =>
RootFinder[A].findRoots(poly.map(conv.fromBigInt)).get(i)
case Neg(n) => -eval(n)
Expand Down Expand Up @@ -1453,10 +1453,10 @@ object Algebraic extends AlgebraicInstances {
}

def apply(expr: Algebraic.Expr): Bound = expr match {
case ConstantLong(n) => integer(n)
case ConstantDouble(n) => rational(n)
case ConstantBigDecimal(n) => rational(n)
case ConstantRational(n) => rational(n)
case ConstantLong(n) => integer(n)
case ConstantDouble(n) => rational(n)
case ConstantBigDecimal(n) => rational(n)
case ConstantRational(n) => rational(n)
case root @ ConstantRoot(poly, _, _, _) =>
Bound(root.lead.bitLength + 1, Roots.upperBound(poly))
case Neg(sub) => sub.getBound(this)
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/spire/math/Complex.scala
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ final case class Complex[@sp(Float, Double) T](real: T, imag: T)

// not typesafe, so this is the best we can do :(
override def equals(that: Any): Boolean = that match {
case that: Complex[_] => this === that
case that: Complex[_] => this === that
case that: Quaternion[_] =>
real == that.r && imag == that.i && anyIsZero(that.j) && anyIsZero(that.k)
case that =>
Expand Down
55 changes: 26 additions & 29 deletions core/src/main/scala/spire/math/Interval.scala
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,8 @@ sealed abstract class Interval[A] extends Serializable { lhs =>

// Does this interval contains any points at or above t ?
def hasAtOrAbove(t: A)(implicit o: Order[A]): Boolean = this match {
case _: Empty[_] => false
case Point(p) => p >= t
case _: Empty[_] => false
case Point(p) => p >= t
case Below(upper, flags) =>
upper > t || isClosedUpper(flags) && upper === t
case Bounded(lower, upper, flags) =>
Expand All @@ -199,8 +199,8 @@ sealed abstract class Interval[A] extends Serializable { lhs =>

// Does this interval contains any points at or below t ?
def hasAtOrBelow(t: A)(implicit o: Order[A]): Boolean = this match {
case _: Empty[_] => false
case Point(p) => p <= t
case _: Empty[_] => false
case Point(p) => p <= t
case Above(lower, flags) =>
lower < t || isClosedLower(flags) && lower === t
case Bounded(lower, upper, flags) =>
Expand Down Expand Up @@ -890,44 +890,41 @@ object Interval {
* This method assumes that lower < upper to avoid comparisons.
*
* - When one of the arguments is Unbound, the result will be All, Above(x, _), or Below(y, _).
*
* - When both arguments are Open/Closed (e.g. Open(x), Open(y)), then x < y and the result will be a Bounded
* interval.
*
* - If both arguments are EmptyBound, the result is Empty.
*
* - Any other arguments are invalid.
*
* This method cannot construct Point intervals.
*/
private[spire] def fromOrderedBounds[A: Order](lower: Bound[A], upper: Bound[A]): Interval[A] =
(lower, upper) match {
case (EmptyBound(), EmptyBound()) => empty
case (Closed(x), Closed(y)) => Bounded(x, y, closedLowerFlags | closedUpperFlags)
case (Open(x), Open(y)) => Bounded(x, y, openLowerFlags | openUpperFlags)
case (Unbound(), Open(y)) => below(y)
case (Open(x), Unbound()) => above(x)
case (Unbound(), Closed(y)) => atOrBelow(y)
case (Closed(x), Unbound()) => atOrAbove(x)
case (Closed(x), Open(y)) => Bounded(x, y, closedLowerFlags | openUpperFlags)
case (Open(x), Closed(y)) => Bounded(x, y, openLowerFlags | closedUpperFlags)
case (Unbound(), Unbound()) => all
case (EmptyBound(), EmptyBound()) => empty
case (Closed(x), Closed(y)) => Bounded(x, y, closedLowerFlags | closedUpperFlags)
case (Open(x), Open(y)) => Bounded(x, y, openLowerFlags | openUpperFlags)
case (Unbound(), Open(y)) => below(y)
case (Open(x), Unbound()) => above(x)
case (Unbound(), Closed(y)) => atOrBelow(y)
case (Closed(x), Unbound()) => atOrAbove(x)
case (Closed(x), Open(y)) => Bounded(x, y, closedLowerFlags | openUpperFlags)
case (Open(x), Closed(y)) => Bounded(x, y, openLowerFlags | closedUpperFlags)
case (Unbound(), Unbound()) => all
case (EmptyBound(), _) | (_, EmptyBound()) =>
throw new IllegalArgumentException("invalid empty bound")
}

def fromBounds[A: Order](lower: Bound[A], upper: Bound[A]): Interval[A] =
(lower, upper) match {
case (EmptyBound(), EmptyBound()) => empty
case (Closed(x), Closed(y)) => closed(x, y)
case (Open(x), Open(y)) => open(x, y)
case (Unbound(), Open(y)) => below(y)
case (Open(x), Unbound()) => above(x)
case (Unbound(), Closed(y)) => atOrBelow(y)
case (Closed(x), Unbound()) => atOrAbove(x)
case (Closed(x), Open(y)) => openUpper(x, y)
case (Open(x), Closed(y)) => openLower(x, y)
case (Unbound(), Unbound()) => all
case (EmptyBound(), EmptyBound()) => empty
case (Closed(x), Closed(y)) => closed(x, y)
case (Open(x), Open(y)) => open(x, y)
case (Unbound(), Open(y)) => below(y)
case (Open(x), Unbound()) => above(x)
case (Unbound(), Closed(y)) => atOrBelow(y)
case (Closed(x), Unbound()) => atOrAbove(x)
case (Closed(x), Open(y)) => openUpper(x, y)
case (Open(x), Closed(y)) => openLower(x, y)
case (Unbound(), Unbound()) => all
case (EmptyBound(), _) | (_, EmptyBound()) =>
throw new IllegalArgumentException("invalid empty bound")
}
Expand Down Expand Up @@ -955,8 +952,8 @@ object Interval {

def apply(s: String): Interval[Rational] =
s match {
case NullRe() => Interval.empty[Rational]
case SingleRe(x) => Interval.point(Rational(x))
case NullRe() => Interval.empty[Rational]
case SingleRe(x) => Interval.point(Rational(x))
case PairRe(left, x, y, right) =>
(left, x, y, right) match {
case ("(", "-∞", "∞", ")") => Interval.all[Rational]
Expand Down
10 changes: 5 additions & 5 deletions core/src/main/scala/spire/math/Natural.scala
Original file line number Diff line number Diff line change
Expand Up @@ -357,10 +357,10 @@ sealed abstract class Natural extends ScalaNumber with ScalaNumericConversions w
}

def *(rhs: Natural): Natural = lhs match {
case End(ld) => rhs * ld
case End(ld) => rhs * ld
case Digit(ld, ltail) =>
rhs match {
case End(rd) => lhs * rd
case End(rd) => lhs * rd
case Digit(rd, rtail) =>
Digit(UInt(0), Digit(UInt(0), ltail * rtail)) +
Digit(UInt(0), ltail * rd) +
Expand Down Expand Up @@ -402,7 +402,7 @@ sealed abstract class Natural extends ScalaNumber with ScalaNumericConversions w
case Digit(ld, ltail) =>
rhs.compare(UInt(1)) match {
case -1 => throw new IllegalArgumentException("/ by zero")
case 0 =>
case 0 =>
lhs
case 1 =>
val p = rhs.powerOfTwo
Expand All @@ -428,7 +428,7 @@ sealed abstract class Natural extends ScalaNumber with ScalaNumericConversions w
rhs.compare(UInt(1)) match {
case -1 => throw new IllegalArgumentException("/ by zero")
case 0 => End(UInt(0))
case 1 =>
case 1 =>
val p = rhs.powerOfTwo
if (p >= 0)
lhs & ((Natural(1) << p) - UInt(1))
Expand All @@ -451,7 +451,7 @@ sealed abstract class Natural extends ScalaNumber with ScalaNumericConversions w
rhs.compare(UInt(1)) match {
case -1 => throw new IllegalArgumentException("/ by zero")
case 0 => (lhs, Natural(0))
case 1 =>
case 1 =>
val p = rhs.powerOfTwo
if (p >= 0) {
val mask = (Natural(1) << p) - UInt(1)
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/spire/math/Polynomial.scala
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ trait PolynomialOverField[@sp(Double) C]
override def equotmod(x: Polynomial[C], y: Polynomial[C]): (Polynomial[C], Polynomial[C]) = {
require(!y.isZero, "Can't divide by polynomial of zero!")
(x: @unchecked) match {
case xd: poly.PolyDense[C] => poly.PolyDense.quotmodDense(xd, y)
case xd: poly.PolyDense[C] => poly.PolyDense.quotmodDense(xd, y)
case xs: poly.PolySparse[C] =>
val ys = (y: @unchecked) match {
case yd: poly.PolyDense[C] => poly.PolySparse.dense2sparse(yd)
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/spire/math/Quaternion.scala
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ final case class Quaternion[@sp(Float, Double) A](r: A, i: A, j: A, k: A)
// not typesafe, so this is the best we can do :(
override def equals(that: Any): Boolean = that match {
case that: Quaternion[_] => this === that
case that: Complex[_] =>
case that: Complex[_] =>
r == that.real && i == that.imag && anyIsZero(j) && anyIsZero(k)
case that =>
sillyIsReal && r == that
Expand Down
16 changes: 8 additions & 8 deletions core/src/main/scala/spire/math/Rational.scala
Original file line number Diff line number Diff line change
Expand Up @@ -273,9 +273,9 @@ sealed abstract class Rational extends ScalaNumber with ScalaNumericConversions
}

override def equals(that: Any): Boolean = that match {
case that: Real => this == that.toRational
case that: Algebraic => that == this
case that: BigInt => isWhole && toBigInt == that
case that: Real => this == that.toRational
case that: Algebraic => that == this
case that: BigInt => isWhole && toBigInt == that
case that: BigDecimal =>
try { toBigDecimal(that.mc) == that }
catch { case ae: ArithmeticException => false }
Expand Down Expand Up @@ -413,7 +413,7 @@ object Rational extends RationalInstances {
def apply(r: String): Rational = r match {
case RationalString(n, d) => Rational(SafeLong(n), SafeLong(d))
case IntegerString(n) => Rational(SafeLong(n))
case s =>
case s =>
try {
Rational(BigDecimal(s))
} catch {
Expand Down Expand Up @@ -786,7 +786,7 @@ object Rational extends RationalInstances {

def +(r: Rational): Rational = r match {
case r: LongRational => r + this
case r: BigRational =>
case r: BigRational =>
val dgcd: SafeLong = d.gcd(r.d)
if (dgcd.isOne) {
Rational(r.d * n + r.n * d, r.d * d)
Expand All @@ -804,7 +804,7 @@ object Rational extends RationalInstances {

def -(r: Rational): Rational = r match {
case r: LongRational => (-r) + this
case r: BigRational =>
case r: BigRational =>
val dgcd: SafeLong = d.gcd(r.d)
if (dgcd.isOne) {
Rational(r.d * n - r.n * d, r.d * d)
Expand All @@ -822,15 +822,15 @@ object Rational extends RationalInstances {

def *(r: Rational): Rational = r match {
case r: LongRational => r * this
case r: BigRational =>
case r: BigRational =>
val a = n.gcd(r.d)
val b = d.gcd(r.n)
Rational((n / a) * (r.n / b), (d / b) * (r.d / a))
}

def /(r: Rational): Rational = r match {
case r: LongRational => r.inverse * this
case r: BigRational =>
case r: BigRational =>
val a = n.gcd(r.n)
val b = d.gcd(r.d)
val num = (n / a) * (r.d / b)
Expand Down
Loading