Skip to content

Commit

Permalink
Reorder implicits
Browse files Browse the repository at this point in the history
  • Loading branch information
propensive committed May 8, 2024
1 parent 5255d23 commit 2d88333
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 30 deletions.
4 changes: 2 additions & 2 deletions src/core/inequality.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@

package hypotenuse

import rudiments.*
import language.experimental.captureChecking

import scala.annotation.*

import language.experimental.captureChecking
import rudiments.*

object NumericallyComparable:
inline given Inequality[Boolean, Int | Double | Char | Byte | Short | Float | Long] as numeric:
Expand Down
40 changes: 20 additions & 20 deletions src/core/macros.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@

package hypotenuse

import fulminate.*

import scala.quoted.*
import language.experimental.genericNumberLiterals

import java.lang.{Integer as JInt, Long as JLong}

import language.experimental.genericNumberLiterals
import scala.quoted.*

import fulminate.*

object Hypotenuse2:
given Realm = realm"hypotenuse"
Expand All @@ -34,65 +34,65 @@ object Hypotenuse2:
def parseI64(digits: Expr[String])(using Quotes): Expr[Long] = digits.value match
case None => '{JLong.parseLong($digits)}
case Some(digits) => Expr(JLong.parseLong(digits))

def parseU32(digits: Expr[String])(using Quotes): Expr[Int] = digits.value match
case None => '{JInt.parseUnsignedInt($digits)}
case Some(digits) => Expr(JInt.parseUnsignedInt(digits))

def parseI32(digits: Expr[String])(using Quotes): Expr[Int] = digits.value match
case None => '{JInt.parseInt($digits)}
case Some(digits) => Expr(JInt.parseInt(digits))

def parseU16(digits: Expr[String])(using Quotes): Expr[Short] = digits.value match
case None => '{JInt.parseInt($digits).toShort}

case Some(digits) =>
val int = JInt.parseInt(digits)
if int < 0 then fail(msg"a U16 may not be less than ${0}")
if int > 0xffff then fail(msg"a U16 may not be greater than ${0xffff}")

Expr(int.toShort)

def parseI16(digits: Expr[String])(using Quotes): Expr[Short] = digits.value match
case None => '{JInt.parseInt($digits).toShort}

case Some(digits) =>
val int = JInt.parseInt(digits)
if int < Short.MinValue then fail(msg"an I16 may not be less than ${Short.MinValue.toInt}")
if int > Short.MaxValue then fail(msg"an I16 may not be greater than ${Short.MaxValue.toInt}")

Expr(int.toShort)

def parseU8(digits: Expr[String])(using Quotes): Expr[Byte] = digits.value match
case None => '{JInt.parseInt($digits).toByte}

case Some(digits) =>
val int = JInt.parseInt(digits)
if int < 0 then fail(msg"a U8 may not be less than ${0}")
if int > 0xffff then fail(msg"a U8 may not be greater than ${0xffff}")

Expr(int.toByte)

def parseI8(digits: Expr[String])(using Quotes): Expr[Byte] = digits.value match
case None => '{JInt.parseInt($digits).toByte}

case Some(digits) =>
val int = JInt.parseInt(digits)
if int < Byte.MinValue then fail(msg"an I8 may not be less than ${Byte.MinValue.toInt}")
if int > Byte.MaxValue then fail(msg"an I8 may not be greater than ${Byte.MaxValue.toInt}")

Expr(int.toByte)

def inequality
(expr: Expr[Boolean],
bound: Expr[Int | Double | Char | Byte | Short | Long | Float],
strict: Expr[Boolean],
greaterThan: Expr[Boolean])
(using Quotes)
: Expr[Boolean] =

val errorMessage = msg"this cannot be written as a range expression"

val value =
if greaterThan.valueOrAbort then expr match
case '{($bound: Int) > ($value: Int)} => value
Expand Down Expand Up @@ -127,7 +127,7 @@ object Hypotenuse2:
case '{($bound: Float) < ($value: Float)} => value
case '{($bound: Float) <= ($value: Float)} => value
case _ => fail(errorMessage)

val (lessStrict, less) =
(if greaterThan.valueOrAbort then (bound, value) else (value, bound)) match
case ('{$left: Int}, '{$right: Int}) => ('{$left < $right}, '{$left <= $right})
Expand All @@ -139,4 +139,4 @@ object Hypotenuse2:
case ('{$left: Short}, '{$right: Short}) => ('{$left < $right}, '{$left <= $right})
case _ => fail(errorMessage)

'{$expr && ${if strict.valueOrAbort then lessStrict else less}}
'{$expr && ${if strict.valueOrAbort then lessStrict else less}}
16 changes: 8 additions & 8 deletions src/core/math.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@

package hypotenuse

import anticipation.*
import contingency.*
import fulminate.*
import language.experimental.genericNumberLiterals

import java.lang.{Integer as JInt, Long as JLong, Short as JShort, Byte as JByte, Double as JDouble,
Float as JFloat}

import scala.util.FromDigits
import scala.annotation.*
import scala.compiletime.*

import language.experimental.genericNumberLiterals

import java.lang.{Integer as JInt, Long as JLong, Short as JShort, Byte as JByte, Double as JDouble,
Float as JFloat}
import anticipation.*
import contingency.*
import fulminate.*

case class OverflowError() extends Error(msg"an overflow error occurred")
case class DivisionError() extends Error(msg"the result is unrepresentable")
Expand Down Expand Up @@ -183,7 +183,7 @@ object Hypotenuse:
object F64:
erased given Underlying[F64, Double] = erasedValue

inline given canEqual: CanEqual[F64, F64 | I64 | I32 | I16 | I8 | Double | Long | Int | Short | Byte] =
inline given CanEqual[F64, F64 | I64 | I32 | I16 | I8 | Double | Long | Int | Short | Byte] as canEqual =
erasedValue

inline def apply(sign: Boolean, exponent: B16, mantissa: B64): F64 =
Expand Down

0 comments on commit 2d88333

Please sign in to comment.