Skip to content

Commit

Permalink
Split source files
Browse files Browse the repository at this point in the history
  • Loading branch information
propensive committed Aug 23, 2024
1 parent a628533 commit 66c61ef
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 23 deletions.
27 changes: 27 additions & 0 deletions src/core/cardinality-core.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
Cardinality, version [unreleased]. Copyright 2024 Jon Pretty, Propensive OÜ.
The primary distribution site is: https://propensive.com/
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 cardinality

import annotation.*

import language.experimental.genericNumberLiterals

export NumericRange.`~`

extension (value: Double)
def force[MinValueType <: Double, MaxValueType <: Double]: MinValueType ~ MaxValueType =
value.asInstanceOf[MinValueType ~ MaxValueType]
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,26 @@

package cardinality

import compiletime.ops.double.*

import fulminate.*
import anticipation.*

import scala.quoted.*
import scala.compiletime.*

object Cardinality:
type Asym[ValueType <: Double, TrueValueType <: Double, FalseValueType <: Double] <: Double =
(ValueType > 0.0) match
case true => TrueValueType
case false => FalseValueType

type Min4[Value1Type <: Double, Value2Type <: Double, Value3Type <: Double, Value4Type <: Double] =
Min[Min[Value1Type, Value2Type], Min[Value3Type, Value4Type]]

type Max4[Value1Type <: Double, Value2Type <: Double, Value3Type <: Double, Value4Type <: Double] =
Max[Max[Value1Type, Value2Type], Max[Value3Type, Value4Type]]

given Realm = realm"cardinality"

def apply[LeftDoubleType <: Double: Type, RightDoubleType <: Double: Type](digits: Expr[String])(using Quotes)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,7 @@ import annotation.*

import language.experimental.genericNumberLiterals

type Asym[ValueType <: Double, TrueValueType <: Double, FalseValueType <: Double] <: Double =
(ValueType > 0.0) match
case true => TrueValueType
case false => FalseValueType

type Min4[Value1Type <: Double, Value2Type <: Double, Value3Type <: Double, Value4Type <: Double] =
Min[Min[Value1Type, Value2Type], Min[Value3Type, Value4Type]]

type Max4[Value1Type <: Double, Value2Type <: Double, Value3Type <: Double, Value4Type <: Double] =
Max[Max[Value1Type, Value2Type], Max[Value3Type, Value4Type]]

extension (value: Double)
def force[MinValueType <: Double, MaxValueType <: Double]: MinValueType ~ MaxValueType =
value.asInstanceOf[MinValueType ~ MaxValueType]
import Cardinality.{Asym, Min4, Max4}

object NumericRange:
@targetName("Range")
Expand Down Expand Up @@ -64,15 +51,15 @@ object NumericRange:
: RangeParser[MinValueType, MaxValueType] with
override inline def fromDigits(digits: String): MinValueType ~ MaxValueType =
${Cardinality('digits)}

extension [LeftMinType <: Double, LeftMaxType <: Double](left: LeftMinType ~ LeftMaxType)
def double: Double = left

@targetName("add")
infix def + [RightMinType <: Double, RightMaxType <: Double](right: RightMinType ~ RightMaxType)
: (LeftMinType + RightMinType) ~ (LeftMaxType + RightMaxType) =
left + right

@targetName("add2")
infix def + [E <: Double & Singleton](right: E): (LeftMinType + right.type) ~ (LeftMaxType + right.type) =
left + right
Expand All @@ -87,13 +74,13 @@ object NumericRange:
LeftMaxType*RightMaxType, LeftMaxType*RightMinType]) =

left*right

@targetName("times2")
infix def * [RightType <: Double & Singleton](right: RightType)
: Min[LeftMinType*RightType, LeftMaxType*RightType] ~ Max[LeftMinType*RightType, LeftMaxType*RightType] =

left*right

@targetName("times3")
infix def * (right: Double): Double = left*right

Expand All @@ -117,17 +104,14 @@ object NumericRange:
: Min[LeftMinType/RightType, LeftMaxType/RightType] ~ Max[LeftMinType/RightType, LeftMaxType/RightType] =

left/right

@targetName("divide2")
infix def / [RightMinType <: Double, RightMaxType <: Double](right: RightMinType ~ RightMaxType)
: Asym[RightMinType*RightMaxType, Min4[LeftMinType/RightMinType, LeftMaxType/RightMinType,
LeftMinType/RightMaxType, LeftMaxType/RightMaxType], -1.0/0.0] ~ Asym[
RightMinType*RightMaxType, Max4[LeftMinType/RightMinType, LeftMaxType/RightMinType,
LeftMinType/RightMaxType, LeftMaxType/RightMaxType], 1.0/0.0] =
left/right

@targetName("divide3")
infix def / (right: Double): Double = left/right

export NumericRange.`~`

0 comments on commit 66c61ef

Please sign in to comment.