re: What does ** (two asterisks in a row) mean in Ruby? VIEW POST


Ah yes...exponentiation. There's a mildly interesting (mostly annoying) history around the choice of operator for it. Back in the good ol' days of C, it was much more common to find oneself twiddling bits than doing higher order math. A very useful operation if you are dealing with bits is the bit-wise XOR. In mathematics, this operation is usually represented with the character. However, since this is not part of the base ASCII set of characters, the developers of C chose to use the next closest thing: ^.

Of course, when more feature-full languages such as Perl came along and wanted to have an operator for exponentiation, they were stuck. While ^ is typically used in mathematics for this operation, C already established the tradition of using this for XOR. Thus was ** born. Ruby, Python, Javascript, and a whole host of other languages followed suit.

But not Julia. Julia made two decisions early on in its development. First, Julia is very mathematics focused and tries to keep as close to traditional conventions from mathematics as possible. Second, Julia (like Swift and many other languages today) embraced the full unicode set for operators. Julia also made it easy to use these operators by allowing one to type \xor at the REPL, hit <TAB>, et voila:

julia> 2 ^ 3
julia> 2  3
code of conduct - report abuse