Skip to content

Commit

Permalink
Implement lcm for primitives
Browse files Browse the repository at this point in the history
  • Loading branch information
propensive committed Jun 30, 2024
1 parent 80c89bc commit 31a83c1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
12 changes: 12 additions & 0 deletions src/core/hypotenuse-core.scala
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,9 @@ extension (byte: Byte)
@tailrec @targetName("gcdByte")
def gcd(right: Byte): Byte = if right == 0 then byte else right.gcd((byte%right).toByte)

@targetName("lcmByte")
def lcm(right: Byte): Byte = (byte*right/byte.gcd(right)).toByte

extension (short: Short)
@targetName("bitsShort")
inline def bits: B16 = short.asInstanceOf[B16]
Expand Down Expand Up @@ -215,6 +218,9 @@ extension (short: Short)
@tailrec @targetName("gcdShort")
def gcd(right: Short): Short = if right == 0 then short else right.gcd((short%right).toShort)

@targetName("lcmShort")
def lcm(right: Short): Short = (short*right/short.gcd(right)).toShort

extension (int: Int)
@targetName("bitsInt")
inline def bits: B32 = int.asInstanceOf[B32]
Expand Down Expand Up @@ -249,6 +255,9 @@ extension (int: Int)
@tailrec @targetName("gcdInt")
def gcd(right: Int): Int = if right == 0 then int else right.gcd(int%right)

@targetName("lcmInt")
def lcm(right: Int): Int = int*right/int.gcd(right)

extension (long: Long)
@targetName("absLong")
inline def abs: Long = math.abs(long)
Expand Down Expand Up @@ -280,6 +289,9 @@ extension (long: Long)
@tailrec @targetName("gcdLong")
def gcd(right: Long): Long = if right == 0 then long else right.gcd(long%right)

@targetName("lcmLong")
def lcm(right: Long): Long = long*right/long.gcd(right)

extension (doubleObject: Double.type)
inline def apply(long: Long): Double = JDouble.longBitsToDouble(long)

Expand Down
1 change: 0 additions & 1 deletion src/core/hypotenuse.Hypotenuse.scala
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,6 @@ object Hypotenuse:

recur(s64, right)


extension (s32: S32)
@targetName("plusS32")
inline infix def + (right: into S32)(using overflow: CheckOverflow): overflow.Wrap[S32] =
Expand Down

0 comments on commit 31a83c1

Please sign in to comment.