diff --git a/src/stdlib_linalg_svd.fypp b/src/stdlib_linalg_svd.fypp index 8910bd3ce..6fa991d49 100644 --- a/src/stdlib_linalg_svd.fypp +++ b/src/stdlib_linalg_svd.fypp @@ -269,7 +269,11 @@ submodule(stdlib_linalg) stdlib_linalg_svd if (info==0) then !> Prepare working storage - lwork = nint(real(work_dummy(1),kind=${rk}$), kind=ilp) + ! Check if the returned working storage space is smaller than the largest value + ! allowed by lwork + lwork = merge(nint(real(work_dummy(1),kind=${rk}$), kind=ilp) & + , huge(lwork) & + , real(work_dummy(1),kind=${rk}$) < real(huge(lwork),kind=${rk}$) ) allocate(work(lwork)) !> Compute SVD