-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* port Add to tl algebra * port Sub to tl algebra * port Mul to tl algebra * Div with TruncatedDivision is failing * / and tquot * neg * pow and tpow * remove algebra.scala * explicit truncating conversions * populate some coulomb.ops.algebra instances * refactor use of algebras * scala.math.Ordering -> cats.kernel.Order * refactor si, si.prefixes, mks, mksa to use export * tweak directories * refactor algebra to use export * factor value-specific optimizations to separate import * unit test optimized operations
- Loading branch information
1 parent
57e8b04
commit 201871f
Showing
33 changed files
with
930 additions
and
489 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Copyright 2022 Erik Erlandson | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package coulomb.ops.algebra | ||
|
||
import scala.annotation.implicitNotFound | ||
|
||
// there is no typelevel community typeclass that expresses the concept | ||
// "supports raising to fractional powers, without truncation" | ||
// The closest thing is spire NRoot, but it is also defined on truncating integer types, | ||
// so it is not helpful for distinguishing "pow" from "tpow", and in any case requires spire | ||
// https://github.com/typelevel/spire/issues/741 | ||
|
||
@implicitNotFound("Fractional power not defined for value type ${V}") | ||
abstract class FractionalPower[V]: | ||
/** returns v^e */ | ||
def pow(v: V, e: Double): V | ||
|
||
@implicitNotFound("Truncating power not defined for value type ${V}") | ||
abstract class TruncatingPower[V]: | ||
/** returns v^e, truncated to integer value (toward zero) */ | ||
def tpow(v: V, e: Double): V |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* Copyright 2022 Erik Erlandson | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package coulomb.ops.algebra | ||
|
||
object all: | ||
export coulomb.ops.algebra.int.{*,given} | ||
export coulomb.ops.algebra.long.{*,given} | ||
export coulomb.ops.algebra.float.{*,given} | ||
export coulomb.ops.algebra.double.{*,given} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Copyright 2022 Erik Erlandson | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package coulomb.ops.algebra | ||
|
||
import algebra.ring.TruncatedDivision | ||
|
||
object double: | ||
given ctx_Double_is_FractionalPower: FractionalPower[Double] with | ||
def pow(v: Double, e: Double): Double = math.pow(v, e) | ||
|
||
given ctx_Double_is_TruncatingPower: TruncatingPower[Double] with | ||
def tpow(v: Double, e: Double): Double = math.pow(v, e).toLong.toDouble | ||
|
||
given ctx_Double_is_TruncatedDivision: TruncatedDivision[Double] with | ||
def tquot(x: Double, y: Double): Double = (x / y).toLong.toDouble | ||
// I don't care about these | ||
def tmod(x: Double, y: Double): Double = ??? | ||
def fquot(x: Double, y: Double): Double = ??? | ||
def fmod(x: Double, y: Double): Double = ??? | ||
def abs(a: Double): Double = ??? | ||
def additiveCommutativeMonoid: algebra.ring.AdditiveCommutativeMonoid[Double] = ??? | ||
def order: cats.kernel.Order[Double] = ??? | ||
def signum(a: Double): Int = ??? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Copyright 2022 Erik Erlandson | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package coulomb.ops.algebra | ||
|
||
import algebra.ring.TruncatedDivision | ||
|
||
object float: | ||
given ctx_Float_is_FractionalPower: FractionalPower[Float] with | ||
def pow(v: Float, e: Double): Float = math.pow(v.toDouble, e).toFloat | ||
|
||
given ctx_Float_is_TruncatingPower: TruncatingPower[Float] with | ||
def tpow(v: Float, e: Double): Float = math.pow(v.toDouble, e).toLong.toFloat | ||
|
||
given ctx_Float_is_TruncatedDivision: TruncatedDivision[Float] with | ||
def tquot(x: Float, y: Float): Float = (x / y).toLong.toFloat | ||
// I don't care about these | ||
def tmod(x: Float, y: Float): Float = ??? | ||
def fquot(x: Float, y: Float): Float = ??? | ||
def fmod(x: Float, y: Float): Float = ??? | ||
def abs(a: Float): Float = ??? | ||
def additiveCommutativeMonoid: algebra.ring.AdditiveCommutativeMonoid[Float] = ??? | ||
def order: cats.kernel.Order[Float] = ??? | ||
def signum(a: Float): Int = ??? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Copyright 2022 Erik Erlandson | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package coulomb.ops.algebra | ||
|
||
import algebra.ring.TruncatedDivision | ||
|
||
object int: | ||
given ctx_Int_is_TruncatingPower: TruncatingPower[Int] with | ||
def tpow(v: Int, e: Double): Int = math.pow(v.toDouble, e).toInt | ||
|
||
given ctx_Int_is_TruncatedDivision: TruncatedDivision[Int] with | ||
def tquot(x: Int, y: Int): Int = x / y | ||
// I don't care about these | ||
def tmod(x: Int, y: Int): Int = ??? | ||
def fquot(x: Int, y: Int): Int = ??? | ||
def fmod(x: Int, y: Int): Int = ??? | ||
def abs(a: Int): Int = ??? | ||
def additiveCommutativeMonoid: algebra.ring.AdditiveCommutativeMonoid[Int] = ??? | ||
def order: cats.kernel.Order[Int] = ??? | ||
def signum(a: Int): Int = ??? | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Copyright 2022 Erik Erlandson | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package coulomb.ops.algebra | ||
|
||
import algebra.ring.TruncatedDivision | ||
|
||
object long: | ||
given ctx_Long_is_TruncatingPower: TruncatingPower[Long] with | ||
def tpow(v: Long, e: Double): Long = math.pow(v.toDouble, e).toLong | ||
|
||
given ctx_Long_is_TruncatedDivision: TruncatedDivision[Long] with | ||
def tquot(x: Long, y: Long): Long = x / y | ||
// I don't care about these | ||
def tmod(x: Long, y: Long): Long = ??? | ||
def fquot(x: Long, y: Long): Long = ??? | ||
def fmod(x: Long, y: Long): Long = ??? | ||
def abs(a: Long): Long = ??? | ||
def additiveCommutativeMonoid: algebra.ring.AdditiveCommutativeMonoid[Long] = ??? | ||
def order: cats.kernel.Order[Long] = ??? | ||
def signum(a: Long): Int = ??? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.