Last active
August 29, 2015 14:20
-
-
Save rbobillot/db6da297c240ec4f4261 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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