<h2 dir="auto">Conversion from BigInt</h2>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="gmp                                (78) |         failed at 2021-01-19T21:39:56.822
Test Failed at /nobackup/users/vchuravy/dev/julia/test/gmp.jl:501
  Expression: T(big&quot;2&quot; ^ (n + 1) - big&quot;2&quot; ^ (n - precision(T))) === T(Inf)
   Evaluated: -Inf16 === Inf16"><pre class="notranslate"><code class="notranslate">gmp                                (78) |         failed at 2021-01-19T21:39:56.822
Test Failed at /nobackup/users/vchuravy/dev/julia/test/gmp.jl:501
  Expression: T(big"2" ^ (n + 1) - big"2" ^ (n - precision(T))) === T(Inf)
   Evaluated: -Inf16 === Inf16
</code></pre></div>
<h3 dir="auto">On Power9 <code class="notranslate">julia -C pwr9</code></h3>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="julia&gt; T=Float16; n = exponent(floatmax(T))
15

julia&gt; T(big&quot;2&quot; ^ (n + 1) - big&quot;2&quot; ^ (n - precision(T)))
Inf16"><pre lang="julia-repl" class="notranslate"><code class="notranslate">julia&gt; T=Float16; n = exponent(floatmax(T))
15

julia&gt; T(big"2" ^ (n + 1) - big"2" ^ (n - precision(T)))
Inf16
</code></pre></div>
<h3 dir="auto">On Power9 <code class="notranslate">julia -C pwr8</code></h3>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="julia&gt; T=Float16; n = exponent(floatmax(T))
15

julia&gt; T(big&quot;2&quot; ^ (n + 1) - big&quot;2&quot; ^ (n - precision(T)))
-Inf16"><pre lang="julia-repl" class="notranslate"><code class="notranslate">julia&gt; T=Float16; n = exponent(floatmax(T))
15

julia&gt; T(big"2" ^ (n + 1) - big"2" ^ (n - precision(T)))
-Inf16
</code></pre></div>
<p dir="auto">Gist: <a href="https://gist.github.com/vchuravy/a0170b4d42e46d800aae53b3a80bb582">https://gist.github.com/vchuravy/a0170b4d42e46d800aae53b3a80bb582</a></p>
<p dir="auto">Duplicate of <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="767899399" data-permission-text="Title is private" data-url="https://github.com/JuliaLang/julia/issues/38896" data-hovercard-type="issue" data-hovercard-url="/JuliaLang/julia/issues/38896/hovercard" href="https://github.com/JuliaLang/julia/issues/38896">#38896</a> which I closed since fixing <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="767021083" data-permission-text="Title is private" data-url="https://github.com/JuliaLang/julia/issues/38883" data-hovercard-type="pull_request" data-hovercard-url="/JuliaLang/julia/pull/38883/hovercard" href="https://github.com/JuliaLang/julia/pull/38883">#38883</a> made it harder to reproduce until <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="787855886" data-permission-text="Title is private" data-url="https://github.com/JuliaLang/julia/issues/39300" data-hovercard-type="pull_request" data-hovercard-url="/JuliaLang/julia/pull/39300/hovercard" href="https://github.com/JuliaLang/julia/pull/39300">#39300</a></p>
<p dir="auto">Upstream: <a href="https://bugs.llvm.org/show_bug.cgi?id=49092" rel="nofollow">https://bugs.llvm.org/show_bug.cgi?id=49092</a></p>
<p dir="auto">Presently calls like _jl_lapack_geqp3 are simple wrappers around calls to Lapack subroutines.  They do return the info value as the value of the function call instead of a pointer argument that is modified in the subroutine.  However, they do not themselves do the "double call" where the first call to the Lapack subroutine returns the desired size of the work array and the second call does the actual computation.</p>
<p dir="auto">There have been a couple of suggestions on julia-dev on how to restructure this.  One is to use Lapacke which provides C calling sequences for Lapack subroutines.  However, after looking at the code for Lapacke I think it would be better to incorporate that functionality in Julia code.</p>
<p dir="auto">I propose extending the <em>jl_lapack</em>* functions to perform the allocation of any work or iwork arrays, doing the double call within this function if needed.</p>
<p dir="auto">I think it should also be possible to simplify the calling sequences by extracting the "leading dimension" arguments like lda if A is a StridedMatrix{T} argument.   Many if the higher-level functions that call the <em>jl_lapack</em>* functions themselves do the check of stride(A,1) == 1 and extract stride(A,2) as lda  To me it seems that the information on the dimensions and strides of A should be accessed within the <em>jl_lapack</em>* functions, not be passed to them, if A is defined to have type StridedMatrix{T}.  At least I can't think of a situation where the M, N, A, LDA arguments would be other than size(A,1), size(A,2), A, stride(A, 2) when A is a StridedMatrix{T}.</p>
<p dir="auto">I can make such changes and submit a pull request if this is deemed reasonable.</p>