close
The Wayback Machine - https://web.archive.org/web/20210705013802/https://github.com/JuliaLang/julia/issues/40609
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

Exponentiation of negative single and half precision fails on nightly #40609

Open
palday opened this issue Apr 26, 2021 · 2 comments · May be fixed by #40620
Open

Exponentiation of negative single and half precision fails on nightly #40609

palday opened this issue Apr 26, 2021 · 2 comments · May be fixed by #40620

Comments

@palday
Copy link
Contributor

@palday palday commented Apr 26, 2021

julia> versioninfo()
Julia Version 1.7.0-DEV.1011
Commit 4e176ac965* (2021-04-26 08:26 UTC)
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: Intel(R) Xeon(R) E-2288G CPU @ 3.70GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-11.0.1 (ORCJIT, skylake)
Environment:
  JULIA_EDITOR = code
  JULIA_NUM_THREADS = 8

julia> Float64(-2)^5
-32.0

julia> Float32(-2)^5
ERROR: DomainError with -2.0:
log2 will only return a complex result if called with a complex argument. Try log2(Complex(x)).
Stacktrace:
 [1] throw_complex_domainerror(f::Symbol, x::Float64)
   @ Base.Math ./math.jl:33
 [2] _log(x::Float64, base::Val{2}, func::Symbol)
   @ Base.Math ./special/log.jl:304
 [3] log2
   @ ./special/log.jl:268 [inlined]
 [4] ^
   @ ./math.jl:914 [inlined]
 [5] ^
   @ ./math.jl:942 [inlined]
 [6] literal_pow(#unused#::typeof(^), x::Float32, #unused#::Val{5})
   @ Base ./intfuncs.jl:315
 [7] top-level scope
   @ REPL[34]:1

julia> Float16(-2)^5
ERROR: DomainError with -2.0:
log2 will only return a complex result if called with a complex argument. Try log2(Complex(x)).
Stacktrace:
 [1] throw_complex_domainerror(f::Symbol, x::Float64)
   @ Base.Math ./math.jl:33
 [2] _log(x::Float64, base::Val{2}, func::Symbol)
   @ Base.Math ./special/log.jl:304
 [3] log2
   @ ./special/log.jl:268 [inlined]
 [4] ^
   @ ./math.jl:914 [inlined]
 [5] ^
   @ ./math.jl:942 [inlined]
 [6] ^
   @ ./math.jl:944 [inlined]
 [7] literal_pow(#unused#::typeof(^), x::Float16, #unused#::Val{5})
   @ Base ./intfuncs.jl:315
 [8] top-level scope
   @ REPL[40]:1
@palday
Copy link
Contributor Author

@palday palday commented Apr 26, 2021

@oscardssmith

This comes from #40236 -- there is a relatively obvious problem with taking the logarithm of the base without checking its sign. This could be fixed by taking the absolute value first and then computing what the sign of the final result should be, but I'm not sure would preserve the speed gain. The fix should definitely include a test with negative bases.

@fredrikekre
Copy link
Member

@fredrikekre fredrikekre commented Apr 26, 2021

Let's add the relevant tests before closing this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Linked pull requests

Successfully merging a pull request may close this issue.

3 participants