Skip to content

Commit

Permalink
refined either power
Browse files Browse the repository at this point in the history
  • Loading branch information
erikerlandson committed Dec 2, 2022
1 parent ddcbe2f commit 09f5c28
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
7 changes: 7 additions & 0 deletions refined/src/main/scala/coulomb/ops/algebra/refined/all.scala
Original file line number Diff line number Diff line change
Expand Up @@ -145,3 +145,10 @@ object all:
Try(alg.div(xv, yv)) match
case Success(z) => Right(z)
case Failure(e) => Left(e.getMessage)

class FPRE[V, P](using alg: FractionalPower[Refined[V, P]]) extends
FractionalPower[Either[String, Refined[V, P]]]:
def pow(v: Either[String, Refined[V, P]], e: Double): Either[String, Refined[V, P]] =
Try(v.map(alg.pow(_, e))) match
case Success(z) => z
case Failure(e) => Left(e.getMessage)
10 changes: 10 additions & 0 deletions refined/src/test/scala/coulomb/quantity.scala
Original file line number Diff line number Diff line change
Expand Up @@ -302,4 +302,14 @@ class RefinedQuantityAlgebraicSuite extends CoulombSuite:
2.withRP[Positive].withUnit[Meter].pow[2]
.assertQ[Refined[Int, Positive], Meter ^ 2](4.withRP[Positive])
assertCE("2.withRP[Positive].withUnit[Meter].pow[-1]")

val x = refineVU[Positive, Meter](2d)
val z = refineVU[Positive, Meter](0d)
x.pow[0].assertQ[RefinedE[Double, Positive], 1](refineV[Positive](1d))
x.pow[2].assertQ[RefinedE[Double, Positive], Meter ^ 2](refineV[Positive](4d))
assert(z.pow[2].value.isLeft)

val v = refineVU[Positive, Meter](Double.MinPositiveValue)
assert(v.value.isRight)
assert(v.pow[2].value.isLeft)
}

0 comments on commit 09f5c28

Please sign in to comment.