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

Closed
palday opened this issue Apr 26, 2021 · 2 comments · Fixed by #40610 or #40620
Closed

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

palday opened this issue Apr 26, 2021 · 2 comments · Fixed by #40610 or #40620
Labels
domain:float16 good first issue Indicates a good issue for first-time contributors to Julia needs tests Unit tests are required for this change

Comments

@palday
Copy link
Contributor

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 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

Let's add the relevant tests before closing this.

@fredrikekre fredrikekre added good first issue Indicates a good issue for first-time contributors to Julia needs tests Unit tests are required for this change labels Apr 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain:float16 good first issue Indicates a good issue for first-time contributors to Julia needs tests Unit tests are required for this change
Projects
None yet
3 participants