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

Unexpected return value of NaN when raising to power #5361

Closed
milktrader opened this issue Jan 11, 2014 · 15 comments
Closed

Unexpected return value of NaN when raising to power #5361

milktrader opened this issue Jan 11, 2014 · 15 comments

Comments

@milktrader
Copy link
Contributor

julia> foo = 0.1; foo ^ .21
0.6165950018614822

julia> foo = -0.1; foo ^ .21
NaN

julia>  -0.1 ^ .21
-0.6165950018614822
@StefanKarpinski
Copy link
Member

Well, that's no good.

@johnmyleswhite
Copy link
Member

This doesn't happen on master anymore:

julia> foo = -0.1; foo ^ .21
NaN

The third case seems to be a parse ambiguity:

julia>  -0.1 ^ .21
-0.6165950018614822

This gets parsed as:

julia> -(0.1^.21)
-0.6165950018614822

@StefanKarpinski
Copy link
Member

What version did you encounter this bug on?

@milktrader
Copy link
Contributor Author

I haven't updated in a couple weeks ...

@milktrader
Copy link
Contributor Author

julia> versioninfo()
Julia Version 0.3.0-prerelease+503
Commit cb64f5a* (2013-12-15 23:50 UTC)
Platform Info:
  System: Darwin (x86_64-apple-darwin13.0.0)
  WORD_SIZE: 64
  BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY)
  LAPACK: libopenblas
  LIBM: libopenlibm

@johnmyleswhite
Copy link
Member

Maybe this was a very recent change:

julia> versioninfo()
Julia Version 0.3.0-prerelease+916
Commit a007350* (2014-01-11 01:19 UTC)
Platform Info:
  System: Darwin (x86_64-apple-darwin13.0.0)
  CPU: Intel(R) Core(TM) i7-3520M CPU @ 2.90GHz
  WORD_SIZE: 64
  BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY)
  LAPACK: libopenblas
  LIBM: libopenlibm

@milktrader
Copy link
Contributor Author

Did an update just now

julia> foo = 0.1; foo ^ .21
0.6165950018614822

julia> foo = -0.1; foo ^ .21
ERROR: DomainError
 in ^ at math.jl:405

julia> -0.1 ^ .21
-0.6165950018614822

With this

julia> versioninfo()
Julia Version 0.3.0-prerelease+925
Commit bf8c1a2* (2014-01-11 15:39 UTC)
Platform Info:
  System: Darwin (x86_64-apple-darwin13.0.0)
  CPU: Intel(R) Core(TM)2 Duo CPU     P7350  @ 2.00GHz
  WORD_SIZE: 64
  BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY)
  LAPACK: libopenblas
  LIBM: libopenlibm

@johnmyleswhite
Copy link
Member

I think that's the right behavior unless we want to change Julia's precedence rules.

@StefanKarpinski
Copy link
Member

Yes, I think the current version is correct. Arguably the NaN was also right. I was misreading the example.

@jiahao
Copy link
Member

jiahao commented Jan 11, 2014

#5234

@milktrader
Copy link
Contributor Author

So when foo is a negative value, it gets parsed differently?

julia> foo = 0.1; foo ^ .21
0.6165950018614822

julia> foo = 0.1; -foo ^ .21
-0.6165950018614822

julia> foo = -0.1; foo ^ .21
ERROR: DomainError
 in ^ at math.jl:405

@StefanKarpinski
Copy link
Member

Unary operators like - bind less tightly than ^.

@johnmyleswhite
Copy link
Member

The relevant issue is that ^ binds tighter than -.

@StefanKarpinski
Copy link
Member

It's very common to write things like -2x^2 or -x^2. These do not mean (-2x)^2 or (-x)^2 but rather -2(x^2) and -(x^2) respectively. This interpretation is completely standard in mathematical notation.

@milktrader
Copy link
Contributor Author

Okay, I see this now. Thanks for the clarification. Sorry for the noise here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants