Skip to content

Commit

Permalink
Removed most long lines
Browse files Browse the repository at this point in the history
  • Loading branch information
propensive committed Jan 24, 2025
1 parent 7e15389 commit 924be4c
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 25 deletions.
22 changes: 16 additions & 6 deletions src/core/hypotenuse-core.scala
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,10 @@ package arithmeticOptions:
inline def divideS64(left: S64, right: S64): S64 = S64((left.long/right.long).bits)
inline def divideU32(left: U32, right: U32): U32 = U32((Int(left.bits)/Int(right.bits)).bits)
inline def divideS32(left: S32, right: S32): S32 = S32((left.int/right.int).bits)
inline def divideU16(left: U16, right: U16): U16 = U16((Short(left.bits)/Short(right.bits)).toShort.bits)

inline def divideU16(left: U16, right: U16): U16 =
U16((Short(left.bits)/Short(right.bits)).toShort.bits)

inline def divideS16(left: S16, right: S16): S16 = S16((left.short/right.short).toShort.bits)
inline def divideU8(left: U8, right: U8): U8 = U8((left.byte/right.byte).toByte.bits)
inline def divideS8(left: S8, right: S8): S8 = S8((left.byte/right.byte).toByte.bits)
Expand All @@ -432,14 +435,16 @@ package arithmeticOptions:
else U64((Long(left.bits)/Long(right.bits)).bits)

inline def divideS64(left: S64, right: S64): S64 raises DivisionError =
if right.long == 0 then raise(DivisionError(), S64(0.bits)) else S64((left.long/right.long).bits)
if right.long == 0 then raise(DivisionError(), S64(0.bits))
else S64((left.long/right.long).bits)

inline def divideU32(left: U32, right: U32): U32 raises DivisionError =
if right.long == 0 then raise(DivisionError(), U32(0.bits))
else U32((Int(left.bits)/Int(right.bits)).bits)

inline def divideS32(left: S32, right: S32): S32 raises DivisionError =
if right.int == 0 then raise(DivisionError(), S32(0.bits)) else S32((left.int/right.int).bits)
if right.int == 0 then raise(DivisionError(), S32(0.bits))
else S32((left.int/right.int).bits)

inline def divideU16(left: U16, right: U16): U16 raises DivisionError =
if right.int == 0 then raise(DivisionError(), U16(0.bits))
Expand All @@ -450,10 +455,12 @@ package arithmeticOptions:
else S16((left.short/right.short).toShort.bits)

inline def divideU8(left: U8, right: U8): U8 raises DivisionError =
if right.int == 0 then raise(DivisionError(), U8(0.bits)) else U8((left.byte/right.byte).toByte.bits)
if right.int == 0 then raise(DivisionError(), U8(0.bits))
else U8((left.byte/right.byte).toByte.bits)

inline def divideS8(left: S8, right: S8): S8 raises DivisionError =
if right.int == 0 then raise(DivisionError(), S8(0.bits)) else S8((left.byte/right.byte).toByte.bits)
if right.int == 0 then raise(DivisionError(), S8(0.bits))
else S8((left.byte/right.byte).toByte.bits)

object overflow:
inline given unchecked: CheckOverflow:
Expand All @@ -462,7 +469,10 @@ package arithmeticOptions:
inline def addS64(left: S64, right: S64): S64 = S64((left.long + right.long).bits)
inline def addU32(left: U32, right: U32): U32 = U32((Int(left.bits) + Int(right.bits)).bits)
inline def addS32(left: S32, right: S32): S32 = S32((left.int + right.int).bits)
inline def addU16(left: U16, right: U16): U16 = U16((Short(left.bits) + Short(right.bits)).toShort.bits)

inline def addU16(left: U16, right: U16): U16 =
U16((Short(left.bits) + Short(right.bits)).toShort.bits)

inline def addS16(left: S16, right: S16): S16 = S16((left.short + right.short).toShort.bits)
inline def addU8(left: U8, right: U8): U8 = U8((left.byte + right.byte).toByte.bits)
inline def addS8(left: S8, right: S8): S8 = S8((left.byte + right.byte).toByte.bits)
Expand Down
3 changes: 2 additions & 1 deletion src/core/hypotenuse.Commensurable.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ import denominative.*
import rudiments.*

object Commensurable:
inline given numeric: [OperandType <: Int | Double | Char | Byte | Short | Float] => Boolean is Commensurable:
inline given numeric: [OperandType <: Int | Double | Char | Byte | Short | Float]
=> Boolean is Commensurable:
type Operand = OperandType

inline def compare
Expand Down
35 changes: 23 additions & 12 deletions src/core/hypotenuse.Hypotenuse.scala
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,13 @@ object Hypotenuse:
object F64:
erased given underlying: Underlying[F64, Double] = erasedValue

inline given canEqual: CanEqual[F64, F64 | S64 | S32 | S16 | S8 | Double | Long | Int | Short | Byte] =
inline given canEqual: CanEqual
[F64, F64 | S64 | S32 | S16 | S8 | Double | Long | Int | Short | Byte] =
erasedValue

inline def apply(inline sign: Boolean, inline exponent: B16, inline mantissa: B64): F64 =
F64((if sign then Long.MinValue else 0L) | ((exponent & 0xffL) << 52) | (mantissa & 0xfffffffffffffL))
inline def apply(inline sign: Boolean, inline exponent: B16, inline mantissa: B64): F64 = F64:
(if sign then Long.MinValue else 0L) | ((exponent & 0xffL) << 52)
| (mantissa & 0xfffffffffffffL)

inline def apply(inline bits: B64): F64 = JDouble.longBitsToDouble(bits)
inline def apply(inline double: Double): F64 = double
Expand Down Expand Up @@ -136,7 +138,8 @@ object Hypotenuse:
object F32:
erased given underlying: Underlying[F32, Float] = erasedValue

inline given canEqual: CanEqual[F32, F32 | S64 | S32 | S16 | S8 | Float | Long | Int | Short | Byte] =
inline given canEqual: CanEqual
[F32, F32 | S64 | S32 | S16 | S8 | Float | Long | Int | Short | Byte] =
erasedValue

inline given orderable: F32 is Orderable:
Expand Down Expand Up @@ -202,7 +205,8 @@ object Hypotenuse:

object S64:
erased given underlying: Underlying[S64, Long] = erasedValue
inline given canEqual: CanEqual[S64, F64 | F32 | S64 | S32 | S16 | S8 | Float | Double | Long | Int | Short | Byte] =
inline given canEqual: CanEqual[S64, F64 | F32 | S64 | S32 | S16 | S8 | Float | Double | Long
| Int | Short | Byte] =
erasedValue

given fromDigits: FromDigits[S64]:
Expand Down Expand Up @@ -246,7 +250,8 @@ object Hypotenuse:

object S32:
erased given underlying: Underlying[S32, Int] = erasedValue
inline given canEqual: CanEqual[S32, F64 | F32 | S64 | S32 | S16 | S8 | Float | Double | Long | Int | Short | Byte] =
inline given canEqual: CanEqual[S32, F64 | F32 | S64 | S32 | S16 | S8 | Float | Double | Long
| Int | Short | Byte] =
erasedValue

given fromDigits: FromDigits[S32]:
Expand Down Expand Up @@ -291,7 +296,8 @@ object Hypotenuse:
object S16:
erased given underlying: Underlying[S16, Short] = erasedValue

inline given canEqual: CanEqual[S16, F64 | F32 | S64 | S32 | S16 | S8 | Float | Double | Long | Int | Short | Byte] =
inline given canEqual: CanEqual[S16, F64 | F32 | S64 | S32 | S16 | S8 | Float | Double | Long
| Int | Short | Byte] =
erasedValue

given fromDigits: FromDigits[S16]:
Expand Down Expand Up @@ -335,7 +341,8 @@ object Hypotenuse:
object S8:
erased given underlying: Underlying[S8, Byte] = erasedValue

inline given canEqual: CanEqual[S8, F64 | F32 | S64 | S32 | S16 | S8 | Float | Double | Long | Int | Short | Byte] =
inline given canEqual: CanEqual[S8, F64 | F32 | S64 | S32 | S16 | S8 | Float | Double | Long
| Int | Short | Byte] =
erasedValue

given fromDigits: FromDigits[S8]:
Expand Down Expand Up @@ -690,10 +697,12 @@ object Hypotenuse:
inline def apply(inline index: Ordinal): Boolean = ((bitmap >> index.n0) & 1) == 1

@targetName("rotateLeftB8")
inline infix def <<< (inline count: Int): B8 = ((bitmap << count%%8) | (bitmap >>> (8 - count%%8))).toByte
inline infix def <<< (inline count: Int): B8 =
((bitmap << count%%8) | (bitmap >>> (8 - count%%8))).toByte

@targetName("rotateRightB8")
inline infix def >>> (inline count: Int): B8 = ((bitmap >>> count%%8) | (bitmap << (8 - count%%8))).toByte
inline infix def >>> (inline count: Int): B8 =
((bitmap >>> count%%8) | (bitmap << (8 - count%%8))).toByte

@targetName("shiftLeftB8")
inline infix def << (inline count: Int): B8 = (bitmap << count).toByte
Expand Down Expand Up @@ -779,10 +788,12 @@ object Hypotenuse:
inline def apply(inline index: Ordinal): Boolean = ((bitmap >> index.n0) & 1) == 1

@targetName("rotateLeftB16")
inline infix def <<< (count: Int): B16 = ((bitmap << count%%16) | (bitmap >>> (16 - count%%16))).toShort
inline infix def <<< (count: Int): B16 =
((bitmap << count%%16) | (bitmap >>> (16 - count%%16))).toShort

@targetName("rotateRightB16")
inline infix def >>> (count: Int): B16 = ((bitmap >>> count%%16) | (bitmap << (16 - count%%16))).toShort
inline infix def >>> (count: Int): B16 =
((bitmap >>> count%%16) | (bitmap << (16 - count%%16))).toShort

@targetName("shiftLeftB16")
inline infix def << (count: Int): B16 = (bitmap << count).toShort
Expand Down
13 changes: 7 additions & 6 deletions src/core/soundness+hypotenuse-core.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@

package soundness

export hypotenuse.{CheckOverflow, Commensurable, DivisionByZero,
DivisionError, Orderable, OverflowError, B8, B16, B32, B64, S8, S16, S32, S64, U8, U16,
U32, U64, F32, F64, abs, sqrt, cbrt, ceiling, floor, exponent, increment, decrement, round, scalb, signum, ulp,
bits, rawBits, finite, infinite, nan, **, mantissa, long, int, short, octal, hex, base32, binary, %%,
\, apply, erf, π, pi, euler, φ, goldenRatio, cos, acos, cosh, sin, asin, sinh, tan, atan, hyp, exp,
expm1, ln, log10, log1p, <, <=, >, >=}
export hypotenuse .
{ CheckOverflow, Commensurable, DivisionByZero, DivisionError, Orderable, OverflowError, B8, B16,
B32, B64, S8, S16, S32, S64, U8, U16, U32, U64, F32, F64, abs, sqrt, cbrt, ceiling, floor,
exponent, increment, decrement, round, scalb, signum, ulp, bits, rawBits, finite, infinite, nan,
**, mantissa, long, int, short, octal, hex, base32, binary, %%, \, apply, erf, π, pi, euler, φ,
goldenRatio, cos, acos, cosh, sin, asin, sinh, tan, atan, hyp, exp, expm1, ln, log10, log1p, <,
<=, >, >= }

package arithmeticOptions:
export hypotenuse.arithmeticOptions.{division, overflow}

0 comments on commit 924be4c

Please sign in to comment.