Skip to content

Commit

Permalink
Provide methods to get adjacent floating-point values (#196)
Browse files Browse the repository at this point in the history
  • Loading branch information
propensive authored Mar 2, 2025
1 parent 49039b3 commit 0c50db6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/hypotenuse/src/core/hypotenuse-core.scala
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ extension (float: Float)
@targetName("nanFloat")
inline def nan: Boolean = float.isNaN

@targetName("successorFloat")
inline def successor: Float = Math.nextUp(float)

@targetName("predecessorFloat")
inline def predecessor: Float = Math.nextDown(float)

@targetName("powerFloat")
inline infix def ** (exponent: Double): Float = math.pow(float, exponent).toFloat

Expand Down Expand Up @@ -150,6 +156,12 @@ extension (double: Double)
@targetName("nanDouble")
inline def nan: Boolean = double.isNaN

@targetName("successorDouble")
inline def successor: Double = Math.nextUp(double)

@targetName("predecessorDouble")
inline def predecessor: Double = Math.nextDown(double)

@targetName("powerDouble")
inline infix def ** (exponent: Double): Double = math.pow(double, exponent)

Expand Down
11 changes: 11 additions & 0 deletions lib/hypotenuse/src/core/hypotenuse.Hypotenuse.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1151,6 +1151,12 @@ object Hypotenuse:
@targetName("nanF64")
inline def nan: Boolean = double.isNaN

@targetName("successorF64")
inline def successor: F64 = Math.nextUp(double)

@targetName("predecessorF64")
inline def predecessor: F64 = Math.nextDown(double)

extension (f32: F32)
@targetName("floatF32")
inline def float: Float = f32
Expand Down Expand Up @@ -1227,6 +1233,11 @@ object Hypotenuse:
@targetName("nanF32")
inline def nan: Boolean = float.isNaN

@targetName("successorF32")
inline def successor: F32 = Math.nextUp(float)

@targetName("predecessorF32")
inline def predecessor: F32 = Math.nextDown(float)

extension (u64: U64)
@targetName("bitsU64")
Expand Down

0 comments on commit 0c50db6

Please sign in to comment.