Open laborg opened 6 years ago
Mhm. It is basically documented in ^
:
If y is an Int literal (e.g. 2 in x^2 or -3 in x^-3), the Julia code x^y is transformed by the compiler to Base.literal_pow(^, x, Val(y)), to enable compile-time specialization on the value of the exponent. (As a default fallback we have Base.literal_pow(^, x, Val(y)) = ^(x,y), where usually ^ == Base.^ unless ^ has been defined in the calling namespace.)
But from that I think it's not clear that this compile-time specialization results in unexpected behaviour (see discourse thread).
Maybe we can add it as a FAQ?
As a naive user I expected to find something in the Mathematical Operations and Elementary Functions - Arithmetic Operators section of the manual. I think this is a section everybody new to Julia will read at least once, so it might be a good place to raise awareness and point to further information.
As discussed in https://discourse.julialang.org/t/confusing-difference-literal-vs-variable/13515/5 it would be good if this is documented somewhere. The explanation of @StefanKarpinski in this thread will be helpful:
24240