1
      2
      3
      4
      5
      6
      7
      8
      9
     10
     11
     12
     13
     14
     15
     16
     17
     18
     19
     20
     21
     22
     23
     24
     25
     26
     27
     28
     29
     30
#ifndef ULMBLAS_IMPL_LAPACK_SAFEMIN_TCC
#define ULMBLAS_IMPL_LAPACK_SAFEMIN_TCC 1

#include <limits>
#include <ulmblas/impl/lapack/safemin.h>

namespace ulmBLAS {

template <typename T>
T
safeMin()
{
    const T eps   = std::numeric_limits<T>::epsilon() * 0.5;
    const T small = T(1) / std::numeric_limits<T>::max();

    T sMin  = std::numeric_limits<T>::min();

    if (small>=sMin) {
//
//      Use SMALL plus a bit, to avoid the possibility of rounding
//      causing overflow when computing  1/sfmin.
//
        sMin = small*(1.0+eps);
    }
    return sMin;
}

// namespace ulmBLAS

#endif // ULMBLAS_IMPL_LAPACK_SAFEMIN_TCC