<p dir="auto">This is magical:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="julia&gt; (1:4) .+ (1:4)
2:2:8"><pre lang="juilia" class="notranslate"><code class="notranslate">julia&gt; (1:4) .+ (1:4)
2:2:8
</code></pre></div>
<p dir="auto">I love that we can be so clever.  Unfortunately, it can come back and bite us sometimes:</p>
<div class="highlight highlight-source-julia notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="julia&gt; (1:4) .+ (4:-1:1)
ERROR: ArgumentError: step cannot be zero
Stacktrace:
 [1] steprange_last(::Int64, ::Int64, ::Int64) at ./range.jl:137
 [2] Type at ./range.jl:127 [inlined]
 [3] _rangestyle at ./range.jl:90 [inlined]
 [4] _range at ./range.jl:88 [inlined]
 [5] #range#29 at ./range.jl:73 [inlined]
 [6] #range at ./none:0 [inlined]
 [7] + at ./range.jl:890 [inlined]
 [8] broadcasted at ./broadcast.jl:969 [inlined]
 [9] broadcasted(::Function, ::UnitRange{Int64}, ::StepRange{Int64,Int64}) at ./broadcast.jl:1146
 [10] top-level scope at none:0
"><pre class="notranslate">julia<span class="pl-k">&gt;</span> (<span class="pl-c1">1</span><span class="pl-k">:</span><span class="pl-c1">4</span>) <span class="pl-k">.+</span> (<span class="pl-c1">4</span><span class="pl-k">:</span><span class="pl-k">-</span><span class="pl-c1">1</span><span class="pl-k">:</span><span class="pl-c1">1</span>)
ERROR<span class="pl-k">:</span> ArgumentError<span class="pl-k">:</span> step cannot be zero
Stacktrace<span class="pl-k">:</span>
 [<span class="pl-c1">1</span>] <span class="pl-c1">steprange_last</span>(<span class="pl-k">::</span><span class="pl-c1">Int64</span>, <span class="pl-k">::</span><span class="pl-c1">Int64</span>, <span class="pl-k">::</span><span class="pl-c1">Int64</span>) at <span class="pl-k">./</span>range<span class="pl-k">.</span>jl<span class="pl-k">:</span><span class="pl-c1">137</span>
 [<span class="pl-c1">2</span>] Type at <span class="pl-k">./</span>range<span class="pl-k">.</span>jl<span class="pl-k">:</span><span class="pl-c1">127</span> [inlined]
 [<span class="pl-c1">3</span>] _rangestyle at <span class="pl-k">./</span>range<span class="pl-k">.</span>jl<span class="pl-k">:</span><span class="pl-c1">90</span> [inlined]
 [<span class="pl-c1">4</span>] _range at <span class="pl-k">./</span>range<span class="pl-k">.</span>jl<span class="pl-k">:</span><span class="pl-c1">88</span> [inlined]
 [<span class="pl-c1">5</span>] <span class="pl-c"><span class="pl-c">#</span>range#29 at ./range.jl:73 [inlined]</span>
 [<span class="pl-c1">6</span>] <span class="pl-c"><span class="pl-c">#</span>range at ./none:0 [inlined]</span>
 [<span class="pl-c1">7</span>] <span class="pl-k">+</span> at <span class="pl-k">./</span>range<span class="pl-k">.</span>jl<span class="pl-k">:</span><span class="pl-c1">890</span> [inlined]
 [<span class="pl-c1">8</span>] broadcasted at <span class="pl-k">./</span>broadcast<span class="pl-k">.</span>jl<span class="pl-k">:</span><span class="pl-c1">969</span> [inlined]
 [<span class="pl-c1">9</span>] <span class="pl-c1">broadcasted</span>(<span class="pl-k">::</span><span class="pl-c1">Function</span>, <span class="pl-k">::</span><span class="pl-c1">UnitRange{Int64}</span>, <span class="pl-k">::</span><span class="pl-c1">StepRange{Int64,Int64}</span>) at <span class="pl-k">./</span>broadcast<span class="pl-k">.</span>jl<span class="pl-k">:</span><span class="pl-c1">1146</span>
 [<span class="pl-c1">10</span>] top<span class="pl-k">-</span>level scope at none<span class="pl-k">:</span><span class="pl-c1">0</span>
</pre></div>
<p dir="auto">This is very clearly due to us trying to construct the range <code class="notranslate">[5:0:5]</code> that is supposed to be 4 elements long, but unfortunately we lose that information since it's supposed to be implicit in <code class="notranslate">start</code>, <code class="notranslate">stop</code> and <code class="notranslate">step</code>.  The range abstraction doesn't know what to do here, and so we fail out.</p>
<p dir="auto">Likely we should have a fallback for this cleverness that simply constructs an array, but I don't like the idea that <code class="notranslate">Range</code> + <code class="notranslate">Range</code> = <code class="notranslate">Union{Range,Vector}</code>.  I would rather that we had a different abstraction similar to <code class="notranslate">UnitRange</code>, perhaps called <code class="notranslate">ConstantRange</code> or something, that takes in a value and an explicit length so that we don't have some poor fool who is doing something like:</p>
<div class="highlight highlight-source-julia notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="for stepA in 1:3
  for stepB in -3:-1
    x = (1:stepA:stepA*1000000000) .+ (stepB*-1000000000:stepB:1)
    println(sum(x))
  end
end"><pre class="notranslate"><span class="pl-k">for</span> stepA <span class="pl-k">in</span> <span class="pl-c1">1</span><span class="pl-k">:</span><span class="pl-c1">3</span>
  <span class="pl-k">for</span> stepB <span class="pl-k">in</span> <span class="pl-k">-</span><span class="pl-c1">3</span><span class="pl-k">:</span><span class="pl-k">-</span><span class="pl-c1">1</span>
    x <span class="pl-k">=</span> (<span class="pl-c1">1</span><span class="pl-k">:</span>stepA<span class="pl-k">:</span>stepA<span class="pl-k">*</span><span class="pl-c1">1000000000</span>) <span class="pl-k">.+</span> (stepB<span class="pl-k">*-</span><span class="pl-c1">1000000000</span><span class="pl-k">:</span>stepB<span class="pl-k">:</span><span class="pl-c1">1</span>)
    <span class="pl-c1">println</span>(<span class="pl-c1">sum</span>(x))
  <span class="pl-k">end</span>
<span class="pl-k">end</span></pre></div>
<p dir="auto">and have his memory blow up for very particular values of <code class="notranslate">stepA</code> and <code class="notranslate">stepB</code>.  (Note that the code sample above, fanciful as it is, fails on current versions of Julia because it cannot finish the summation of the two ranges)</p>
<p dir="auto">Julia 1.0:</p>
<p dir="auto">I observed that when starting up Julia with the <code class="notranslate">--math-mode=fast</code> option, I get incorrect results for sinpi and cospi functions.</p>
<p dir="auto">With the default math mode:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="julia&gt; a = rand(5)
5-element Array{Float64,1}:
 0.5897641978923696
 0.2459464145866952
 0.06373272357797632
 0.26244049804714087
 0.7254898186800567

julia&gt; cospi.(a)
5-element Array{Float64,1}:
 -0.27827964958957724
  0.7160540045153001
  0.9800223981473272
  0.6789380012385138
 -0.650617399829044

julia&gt; sinpi.(a)
5-element Array{Float64,1}:
 0.9605000971495538
 0.6980448858186719
 0.19888715174581242
 0.7341956077737403
 0.7594056880480248"><pre class="notranslate"><code class="notranslate">julia&gt; a = rand(5)
5-element Array{Float64,1}:
 0.5897641978923696
 0.2459464145866952
 0.06373272357797632
 0.26244049804714087
 0.7254898186800567

julia&gt; cospi.(a)
5-element Array{Float64,1}:
 -0.27827964958957724
  0.7160540045153001
  0.9800223981473272
  0.6789380012385138
 -0.650617399829044

julia&gt; sinpi.(a)
5-element Array{Float64,1}:
 0.9605000971495538
 0.6980448858186719
 0.19888715174581242
 0.7341956077737403
 0.7594056880480248
</code></pre></div>
<p dir="auto">while with <code class="notranslate">--math-mode=fast</code> option:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="julia&gt; cospi.(a)
5-element Array{Float64,1}:
 1.0
 1.0
 1.0
 1.0
 1.0

julia&gt; sinpi.(a)
5-element Array{Float64,1}:
 0.0
 0.0
 0.0
 0.0
 0.0"><pre class="notranslate"><code class="notranslate">julia&gt; cospi.(a)
5-element Array{Float64,1}:
 1.0
 1.0
 1.0
 1.0
 1.0

julia&gt; sinpi.(a)
5-element Array{Float64,1}:
 0.0
 0.0
 0.0
 0.0
 0.0
</code></pre></div>