4 ms·
Is there a good reason that ^ is not used as an exponent operator in most (all?) languages. Its used in every calculator Ive seen. 2^5 = 32
by seanalltogether 6y ago
Is there a good reason that ^ is not used as an exponent operator in most (all?) languages. Its used in every calculator Ive seen.
2^5 = 32
- pansa2 6y agoC doesn't have an exponentiation operator, and instead uses `^` to mean XOR. Other languages have copied that meaning of `^` and hence need to use something different for exponentiation. However, Lua is one language that does use `^` for exponentiation (its XOR operator is `~`).
- drej 6y agoYes, it's often used for a XOR operation (bitwise exclusive or).
- williamstein 6y agoI speculate that ^ is used for xor in many languages for psychological compatibility with C, which is a very old language. In SageMath, which uses a lightweight preparser on top of Python, I made it automatically convert ^ to , since otherwise mathematicians, who are used to LaTeX, would be very confused (I remember realizing this during a tutorial at Pycon in 2005).