Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove integer domain example that doesn't work #31298

Merged
merged 4 commits into from
Mar 14, 2019

Conversation

AnjoMan
Copy link
Contributor

@AnjoMan AnjoMan commented Mar 8, 2019

I tried this in julia 1.0.2 and it seems that the interepreter is smart enough now to interpret the expression as a float

julia> 2^-1
0.5

@Keno
Copy link
Member

Keno commented Mar 8, 2019

This was fixed by making exponents with integer literals special syntax:

julia> a = -1
-1

julia> 2^a
ERROR: DomainError with -1:
Cannot raise an integer x to a negative power -1.
Make x a float by adding a zero decimal (e.g., 2.0^-1 instead of 2^-1), or write 1/x^1, float(x)^-1, or (x//1)^-1
Stacktrace:
 [1] throw_domerr_powbysq(::Int64, ::Int64) at ./intfuncs.jl:176
 [2] power_by_squaring(::Int64, ::Int64) at ./intfuncs.jl:196
 [3] ^(::Int64, ::Int64) at ./intfuncs.jl:220
 [4] top-level scope at none:0

julia> 2^-1
0.5

The documentation should reflect this distinction and I just now notice that that error message should probably be updated also.

@StefanKarpinski
Copy link
Member

Arbitrarily large integer literals are supported. Full stop.

"\nMake x a float by adding a zero decimal (e.g., 2.0^$p instead ",
"of 2^$p), or write 1/x^$(-p), float(x)^$p, or (x//1)^$p")))
"\nMake x or $p a float by adding a zero decimal ",
"(e.g., 2.0^$p or 2^$(float(p)) instead of 2^$p), ",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Keno I think this addresses your point about the error message suggestion. It adds a suggestion for 2^-1.0, as well as calling float on the exponent (i.e. 2^(float(p))) which should cover the literal and expression cases.

@fredrikekre fredrikekre added the docs This change adds or pertains to documentation label Mar 14, 2019
@fredrikekre fredrikekre merged commit 4457264 into JuliaLang:master Mar 14, 2019
@fredrikekre
Copy link
Member

Thank you, and welcome as a contributor to Julia!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs This change adds or pertains to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants