UCIDataScienceInitiative / IntroToJulia

A Deep Introduction to Julia for Data Science and Scientific Computing
http://ucidatascienceinitiative.github.io/IntroToJulia/
MIT License
252 stars 87 forks source link

2^-5 isn't an error #44

Open non-Jedi opened 5 years ago

non-Jedi commented 5 years ago

WhyJulia states this gives an error, bt within the page it shows a regular Float64 result.

ChrisRackauckas commented 5 years ago

Yeah, anyone have an example that isn't fixed by literal and constant propogation? It's hard to write a simple example now that fails because that tends to auto-fix them lol.

rsokl commented 5 years ago

I think that this would suffice:

julia> x = -5; 2 ^ x
ERROR: DomainError with -5:
Cannot raise an integer x to a negative power -5.
Make x or -5 a float by adding a zero decimal (e.g., 2.0^-5 or 2^-5.0 instead of 2^-5), or write 1/x^5, float(x)^-5, x^float(-5) or (x//1)^-5

Although it does lead to the unfortunate added burden of explaining why this is different than 2^(-5).