Example #1
0
template<> float128 fromString<float128>(const std::string& s) {
	char* rest = nullptr;
	float128 f = strtoflt128 (s.c_str(), &rest);
	if(rest != s.c_str() + s.size()){
		throw std::runtime_error("invalid conversion");
	}
	return f;
}
Example #2
0
/*
 * Functions of the extension type
 */
static PyObject *
pyquad_new(PyTypeObject *NPY_UNUSED(type), PyObject *args,
	   PyObject *NPY_UNUSED(kwds))
{
    qdouble q;
    char *c_literal, *remain;

    if (!PyArg_ParseTuple(args, "s", &c_literal))
        return NULL;

    q = strtoflt128(c_literal, &remain);
    return PyQuad_FromQuad(q);
}
Example #3
0
   float128_backend& operator = (const char* s)
   {
#ifndef BOOST_MP_USE_QUAD
      char* p_end;
      m_value = strtoflt128(s, &p_end);
      if(p_end - s != (std::ptrdiff_t)std::strlen(s))
      {
         BOOST_THROW_EXCEPTION(std::runtime_error("Unable to interpret input string as a floating point value"));
      }
#else
      boost::multiprecision::detail::convert_from_string(*this, s);
#endif
      return *this;
   }
Example #4
0
longdouble parse_longdouble(const char *str)
{
    longdouble ld;
#ifdef LONGDOUBLE_IS_FLOAT128
    ld = strtoflt128(str,NULL);
#endif

#ifdef LONGDOUBLE_IS_IEEE754
    sscanf(str, "%Lf", &ld);
#endif

#ifdef LONGDOUBLE_IS_DDREAL
    ld = str;
#endif
    return ld;
}
Example #5
0
// TODO: Move into core/imports/quadmath.hpp?
#ifdef EL_HAVE_QUAD
ostream& operator<<( ostream& os, const Quad& alpha )
{
    char str[128];
    quadmath_snprintf( str, 128, "%Qe", alpha );
    os << str;
    return os;
}

istream& operator>>( istream& is, Quad& alpha )
{
    string token;
    is >> token; 
    alpha = strtoflt128( token.c_str(), NULL );
    return is;
}
#endif

// Return the complex argument
// ---------------------------
#ifdef EL_HAVE_QUAD
template<>
Quad Arg( const Complex<Quad>& alphaPre )
{
    __complex128 alpha;
    __real__(alpha) = alphaPre.real();
    __imag__(alpha) = alphaPre.imag();

    return cargq(alpha);