Re: [julia-users] ^ operator cannot compute correctly on "modified" range

2016-06-03 Thread Stefan Karpinski
This problem boils down to this:

julia> (-10.0)^2.2
ERROR: DomainError:
 in nan_dom_err at ./math.jl:134 [inlined]
 in ^(::Float64, ::Float64) at ./math.jl:293
 in eval(::Module, ::Any) at ./boot.jl:225
 in macro expansion at ./REPL.jl:92 [inlined]
 in (::Base.REPL.##1#2{Base.REPL.REPLBackend})() at ./event.jl:46


The problem is that you're raising a negative value to a fractional power,
which has a complex result, but the power function gives real results for
real values, so that result cannot be represented. If you convert the
argument to complex first, it works:

julia> Complex(-10.0)^2.2
128.22055269702062 + 93.15768449873806im


Applying this to your original problem:

julia> map(Complex,bb).^2.2
100-element Array{Complex{Float64},1}:
  128.221+93.1577im
  101.693+73.8843im
  78.4794+57.0186im
 ⋮
  18490.2+0.0im
  18961.0+0.0im
  19438.3+0.0im


On Fri, Jun 3, 2016 at 5:25 AM, Technet  wrote:

> Look at this code:
>
> x = 0.1:100
> m = 10.1
> bb = x-m
> display(typeof(x)) # FloatRange{Float64}
> display(typeof(bb)) # FloatRange{Float64}
>
> # x.^2.1 #correctly done
> bb.^2.2 # error -> why ?
>
>
> The last line throw this error:
> LoadError: DomainError:
> while loading In[13], in expression starting on line 6
>
>  in .^ at range.jl:653
>
> x and bb are the same type of data
> Why cannot elevate the "bb" range to a float exponent ?
>


[julia-users] ^ operator cannot compute correctly on "modified" range

2016-06-03 Thread Steven G. Johnson
bb has negative elements, and if you exponentiate these to a fractional power 
you get a complex result. To get a complex result, one of the arguments needs 
to be complex, e.g. try bb.^(2.1+0im)

(Automatically switching to a complex result for negative inputs would be 
type-unstable and kill performance. See the "type stability" section in the 
manual.)

[julia-users] ^ operator cannot compute correctly on "modified" range

2016-06-03 Thread Technet
Look at this code:

x = 0.1:100
m = 10.1
bb = x-m
display(typeof(x)) # FloatRange{Float64}
display(typeof(bb)) # FloatRange{Float64}

# x.^2.1 #correctly done
bb.^2.2 # error -> why ? 


The last line throw this error:
LoadError: DomainError:
while loading In[13], in expression starting on line 6

 in .^ at range.jl:653

x and bb are the same type of data
Why cannot elevate the "bb" range to a float exponent ?