Skip to content

Instantly share code, notes, and snippets.

@rbobillot
Last active August 29, 2015 14:20
Show Gist options
  • Save rbobillot/db6da297c240ec4f4261 to your computer and use it in GitHub Desktop.
Save rbobillot/db6da297c240ec4f4261 to your computer and use it in GitHub Desktop.
import scala.language.reflectiveCalls
import scala.language.implicitConversions
object MyMath {
implicit def doubleOps(x: Double) = new {
def **(n:Double):Double = Math.pow( x, n )
def <<<(n:Double):Double = Math.pow( 2, n ) * x
}
}
object Main {
import MyMath.doubleOps
def main(av:Array[String]) {
val Pow = 2 ** 5 //equivalent to: 2.**(5)
val Shift = 2 <<< 5 //equivalent to: 2.<<<(5)
println( s"2 ** 5 = ${Pow}" ) // 2 ^ 5 = 32.0
println( s"2 <<< 5 = ${Shift}" ) // 2 * (2 ^ 5) = 64.0
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment