// xlocnum internal header (from <locale>)
#ifndef _XLOCNUM_
#define _XLOCNUM_
#include <limits>

#if defined(__ghs)
#include <cerrno>
#endif /* __ghs */

#if defined(__ghs)
#include <cmath0>
#else
#include <cmath>
#endif /* __ghs */
#include <cstdio>
#include <cstdlib>
#include <streambuf>

#define	__GHS_FASTER	1
#define _GetDigit(val)	(((unsigned)(_Elem)(val)) - (unsigned)(_Elem)_Elem0)
#define _VIRTUAL	virtual

 #if defined(__ghs)
  #pragma ghs start_cxx_lib_header
  #pragma ghs startdata
  #if defined(__ghs_max_pack_value)
   #pragma pack (push, __ghs_max_pack_value)
  #endif /* defined(__ghs_max_pack_value) */
 #endif /* defined(__ghs) */

		// TEXT-TO-NUMERIC CONVERSION FUNCTIONS
_C_STD_BEGIN
_C_LIB_DECL
#if defined(__GHS_FASTER)
extern unsigned long _Xstrtoul(const char *_Ptr, int _Base, unsigned long _Max, bool *_Fail);
#endif
#if !defined(__ghs) || !defined(__NoFloat)
 #if defined(__ghs)
extern float _Stof(const char *, char **, long);
  #if defined(__ghs) && defined(_MC_EXEC)
#define _Stod(a,b,c)  _mc_Stod(a,b,c)
  #elif defined(__ghs) && defined(__ADSPBLACKFIN__)
#define _Stod  _ghs_Stod
  #endif
  #if (!defined(__ghs__) || !defined(__FloatSingle__))
extern double _Stod(const char *, char **, long);
extern long double _Stold(const char *, char **, long);
  #endif
 #endif /* __ghs */
extern float _Stofx(const char *, char **,
	long, int *);
extern double _Stodx(const char *, char **,
	long, int *);
extern long double _Stoldx(const char *, char **,
	long, int *);
#endif // !defined(__ghs) || !defined(__NoFloat)
extern long _Stolx(const char *, char **,
	int, int *);
extern unsigned long _Stoulx(const char *, char **,
	int, int *);
#if !defined(__ghs) || defined(_LONGLONG)
extern _LONGLONG _Stollx(const char *, char **,
	int, int *);
extern _ULONGLONG _Stoullx(const char *, char **,
	int, int *);
#endif /* !__ghs || _LONGLONG */
_END_C_LIB_DECL
_C_STD_END

_STD_BEGIN

// TEMPLATE FUNCTION _Find_elem
template<class _Elem> inline
	size_t _Find_elem(_Elem *_Base, _Elem _Ch)
	{	// lookup _Ch in NUL-terminated string _Base
	_Elem *_Ptr = _Base;
	for (; *_Ptr != (_Elem)0 && *_Ptr != _Ch; ++_Ptr)
		;
	return ((size_t)(_Ptr - _Base));
	}

inline wchar_t *_Maklocwcs(const wchar_t *_Ptr)
	{	// copy NTWCS to allocated storage
	size_t _Count = _CSTD wcslen(_Ptr) + 1;
	wchar_t *_Ptrdest = (wchar_t *)_CSTD malloc(_Count * sizeof (wchar_t));
	if (!_Ptrdest)
		_Xbad_alloc();
	_CSTD wmemcpy(_Ptrdest, _Ptr, _Count);
	return (_Ptrdest);
	}

		// TEMPLATE CLASS numpunct
template<class _Elem>
	class numpunct
		: public locale::facet
	{	// facet for defining numeric punctuation text
public:
	typedef basic_string<_Elem, char_traits<_Elem>, allocator<_Elem> >
		string_type;
	typedef _Elem char_type;

	static locale::id id;	// unique facet id

	_Elem decimal_point() const
		{	// return decimal point
		return (do_decimal_point());
		}

	_Elem thousands_sep() const
		{	// return thousands separator
		return (do_thousands_sep());
		}

	string grouping() const
		{	// return grouping string
		return (do_grouping());
		}

	string_type falsename() const
		{	// return name for false
		return (do_falsename());
		}

	string_type truename() const
		{	// return name for true
		return (do_truename());
		}

	explicit numpunct(size_t _Refs = 0)
		: locale::facet(_Refs)
		{	// construct from current locale
		_BEGIN_LOCINFO(_Lobj)
			_Init(_Lobj);
			if (_Kseparator == 0)
				_Kseparator =	// NB: differs from "C" locale
					_MAKLOCCHR(_Elem, ',', _Lobj._Getcvt());
		_END_LOCINFO()
		}

	numpunct(const _Locinfo& _Lobj, size_t _Refs = 0, bool _Isdef = false)
		: locale::facet(_Refs)
		{	// construct from specified locale
		_Init(_Lobj, _Isdef);
		}

	static size_t _Getcat(const locale::facet **_Ppf = 0,
		const locale *_Ploc = 0)
		{	// return locale category mask and construct standard facet
		if (_Ppf != 0 && *_Ppf == 0)
#if defined(__ghs) && !_HAS_EXCEPTIONS
			*_Ppf = (numpunct<_Elem> *)_CHECK_LIB_ALLOC(
				new numpunct<_Elem>(
				_Locinfo(_Ploc->c_str()), 0, true));
#else  /* defined(__ghs) && !_HAS_EXCEPTIONS */
			*_Ppf = new numpunct<_Elem>(
				_Locinfo(_Ploc->c_str()), 0, true);
#endif /* defined(__ghs) && !_HAS_EXCEPTIONS */
		return (_X_NUMERIC);
		}

protected:

 #if defined(__ghs)

 #if defined(__ghs_shared_object_support)
	_NOINLINE _VIRTUAL ~numpunct() _NOEXCEPT
		;

 #else /* defined(__ghs_shared_object_support) */
	_NOINLINE _VIRTUAL ~numpunct() _NOEXCEPT
		{	// destroy the object
		_Tidy();
		}
 #endif /* defined(__ghs_shared_object_support) */

#else /* defined(__ghs) */
	_NOINLINE _VIRTUAL ~numpunct() _NOEXCEPT
		{	// destroy the object
		_Tidy();
		}
#endif /* defined(__ghs) */

	numpunct(const char *_Locname, size_t _Refs = 0, bool _Isdef = false)
		: locale::facet(_Refs)
		{	// construct from specified locale
		_BEGIN_LOCINFO(_Lobj(_Locname))
			_Init(_Lobj, _Isdef);
		_END_LOCINFO()
		}

	template<class _Elem2>
		void _Getvals(_Elem2, const lconv *_Ptr, _Locinfo::_Cvtvec _Cvt)
		{	// get values
		_Dp = _MAKLOCCHR(_Elem2, _Ptr->decimal_point[0], _Cvt);
		_Kseparator = _MAKLOCCHR(_Elem2, _Ptr->thousands_sep[0], _Cvt);
		}

	_NOINLINE void _Init(const _Locinfo& _Lobj, bool _Isdef = false)
		{	// initialize from _Lobj
		const lconv *_Ptr = _Lobj._Getlconv();
		_Locinfo::_Cvtvec _Cvt = _Lobj._Getcvt();	// conversion information

		_Grouping = 0;
		_Falsename = 0;
		_Truename = 0;

		_TRY_BEGIN
		_Grouping = _MAKLOCSTR(char, _Isdef ? "" : _Ptr->grouping,
			_Lobj._Getcvt());
		_Falsename = _MAKLOCSTR(_Elem, _Lobj._Getfalse(), _Cvt);
		_Truename = _MAKLOCSTR(_Elem, _Lobj._Gettrue(), _Cvt);
		_CATCH_ALL
		_Tidy();
		_RERAISE;
		_CATCH_END

		if (_Isdef)
			{	// apply defaults for required facets
//			_Grouping = _MAKLOCSTR(char, "", _Cvt);
			_Dp = _MAKLOCCHR(_Elem, '.', _Cvt);
			_Kseparator = _MAKLOCCHR(_Elem, ',', _Cvt);
			}
		else
			_Getvals((_Elem)0, _Ptr, _Cvt);
		}

	_NOINLINE _VIRTUAL _Elem do_decimal_point() const
		{	// return decimal point
		return (_Dp);
		}

	_NOINLINE _VIRTUAL _Elem do_thousands_sep() const
		{	// return thousands separator
		return (_Kseparator);
		}

	_NOINLINE _VIRTUAL string do_grouping() const
		{	// return grouping string
		return (string(_Grouping));
		}

	_NOINLINE _VIRTUAL string_type do_falsename() const
		{	// return name for false
		return (string_type(_Falsename));
		}

	_NOINLINE _VIRTUAL string_type do_truename() const
		{	// return name for true
		return (string_type(_Truename));
		}

private:
	void _Tidy()
		{	// free all storage
		delete[] _Grouping;
		delete[] _Falsename;
		delete[] _Truename;
	}

	const char *_Grouping;	// grouping string, "" for "C" locale
	_Elem _Dp;	// decimal point, '.' for "C" locale
	_Elem _Kseparator;	// thousands separator, '\0' for "C" locale
	const _Elem *_Falsename;	// name for false, "false" for "C" locale
	const _Elem *_Truename;	// name for true, "true" for "C" locale
	};

#if defined(__ghs) && defined(__ghs_shared_object_support)
template<class _Elem>
	numpunct<_Elem>::~numpunct() _NOEXCEPT
	{	// destroy the object
	_Tidy();
	}
#endif /* __ghs && defined(__ghs_shared_object_support) */

		// TEMPLATE CLASS numpunct_byname
template<class _Elem>
	class numpunct_byname
		: public numpunct<_Elem>
	{	// numpunct for named locale
public:
	explicit numpunct_byname(const char *_Locname, size_t _Refs = 0)
		: numpunct<_Elem>(_Locname, _Refs)
		{	// construct for named locale
		}

 #if _HAS_CPP11
	explicit numpunct_byname(const string& _Str, size_t _Refs = 0)
		: numpunct<_Elem>(_Str.c_str(), _Refs)
		{	// construct for named locale
		}
 #endif /* _HAS_CPP11 */

protected:
#ifdef __ghs
	__noinline
#endif
	_VIRTUAL ~numpunct_byname() _NOEXCEPT
#if defined(__ghs) && defined(__ghs_shared_object_support)
					;
#else /* !(__ghs && defined(__ghs_shared_object_support)) */
		{	// destroy the object
		}
#endif /* !(__ghs && defined(__ghs_shared_object_support)) */
	};

#if defined(__ghs) && defined(__ghs_shared_object_support)
template<class _Elem>
	numpunct_byname<_Elem>::~numpunct_byname() _NOEXCEPT
		{	// destroy the object
		}
#endif /* __ghs && defined(__ghs_shared_object_support) */

		// STATIC numpunct::id OBJECT
template<class _Elem>
	locale::id numpunct<_Elem>::id;

		// TEMPLATE CLASS num_get
template<class _Elem,
	class _InIt = istreambuf_iterator<_Elem, char_traits<_Elem> > >
	class num_get
		: public locale::facet
	{	// facet for converting text to encoded numbers
public:
	typedef numpunct<_Elem> _Mypunct;
	typedef basic_string<_Elem, char_traits<_Elem>, allocator<_Elem> >
		_Mystr;

	static size_t _Getcat(const locale::facet **_Ppf = 0,
		const locale *_Ploc = 0)
		{	// return locale category mask and construct standard facet
		if (_Ppf != 0 && *_Ppf == 0)
#if defined(__ghs) && !_HAS_EXCEPTIONS
			*_Ppf = (num_get<_Elem, _InIt> *)_CHECK_LIB_ALLOC(
				new num_get<_Elem, _InIt>(
				_Locinfo(_Ploc->c_str())));
#else  /* defined(__ghs) && !_HAS_EXCEPTIONS */
			*_Ppf = new num_get<_Elem, _InIt>(
				_Locinfo(_Ploc->c_str()));
#endif /* defined(__ghs) && !_HAS_EXCEPTIONS */
		return (_X_NUMERIC);
		}

	static locale::id id;	// unique facet id

protected:
#ifdef __ghs
	__noinline
#endif /* __ghs */
	_VIRTUAL ~num_get() _NOEXCEPT
#if defined(__ghs) && defined(__ghs_shared_object_support)
				;
#else  /* !(__ghs && defined(__ghs_shared_object_support)) */
		{	// destroy the object
		}
#endif /* !(__ghs && defined(__ghs_shared_object_support)) */

	void _Init(const _Locinfo&)
		{	// initialize from _Locinfo object
		}

public:
	explicit num_get(size_t _Refs = 0)
		: locale::facet(_Refs)
		{	// construct from current locale
		_BEGIN_LOCINFO(_Lobj)
			_Init(_Lobj);
		_END_LOCINFO()
		}

	num_get(const _Locinfo& _Lobj, size_t _Refs = 0)
		: locale::facet(_Refs)
		{	// construct from specified locale
		_Init(_Lobj);
		}

	typedef _Elem char_type;
	typedef _InIt iter_type;

	_InIt get(_InIt _First, _InIt _Last,
		ios_base& _Iosbase,	ios_base::iostate& _State,
			bool& _Val) const
		{	// get bool from [_First, _Last) into _Val
		return (do_get(_First, _Last, _Iosbase, _State, _Val));
		}

	_InIt get(_InIt _First, _InIt _Last,
		ios_base& _Iosbase,	ios_base::iostate& _State,
			unsigned short& _Val) const
		{	// get unsigned short from [_First, _Last) into _Val
		return (do_get(_First, _Last, _Iosbase, _State, _Val));
		}

	_InIt get(_InIt _First, _InIt _Last,
		ios_base& _Iosbase,	ios_base::iostate& _State,
			unsigned int& _Val) const
		{	// get unsigned int from [_First, _Last) into _Val
		return (do_get(_First, _Last, _Iosbase, _State, _Val));
		}

	_InIt get(_InIt _First, _InIt _Last,
		ios_base& _Iosbase, ios_base::iostate& _State,
			long& _Val) const
		{	// get long from [_First, _Last) into _Val
		return (do_get(_First, _Last, _Iosbase, _State, _Val));
		}

	_InIt get(_InIt _First, _InIt _Last,
		ios_base& _Iosbase, ios_base::iostate& _State,
			unsigned long& _Val) const
		{	// get unsigned long from [_First, _Last) into _Val
		return (do_get(_First, _Last, _Iosbase, _State, _Val));
		}

 #ifdef _LONGLONG
	_InIt get(_InIt _First, _InIt _Last,
		ios_base& _Iosbase, ios_base::iostate& _State,
			_LONGLONG& _Val) const
		{	// get long long from [_First, _Last) into _Val
		return (do_get(_First, _Last, _Iosbase, _State, _Val));
		}

	_InIt get(_InIt _First, _InIt _Last,
		ios_base& _Iosbase, ios_base::iostate& _State,
			_ULONGLONG& _Val) const
		{	// get unsigned long long from [_First, _Last) into _Val
		return (do_get(_First, _Last, _Iosbase, _State, _Val));
		}
 #endif /* _LONGLONG */

#if !(defined(__ghs) || defined(__SC3__)) || !defined(__NoFloat)
	_InIt get(_InIt _First, _InIt _Last,
		ios_base& _Iosbase, ios_base::iostate& _State,
			float& _Val) const
		{	// get float from [_First, _Last) into _Val
		return (do_get(_First, _Last, _Iosbase, _State, _Val));
		}

	_InIt get(_InIt _First, _InIt _Last,
		ios_base& _Iosbase, ios_base::iostate& _State,
			double& _Val) const
		{	// get double from [_First, _Last) into _Val
		return (do_get(_First, _Last, _Iosbase, _State, _Val));
		}

	_InIt get(_InIt _First, _InIt _Last,
		ios_base& _Iosbase, ios_base::iostate& _State,
			long double& _Val) const
		{	// get long double from [_First, _Last) into _Val
		return (do_get(_First, _Last, _Iosbase, _State, _Val));
		}
#endif // !defined(__ghs) || !defined(__NoFloat)

	_InIt get(_InIt _First, _InIt _Last,
		ios_base& _Iosbase, ios_base::iostate& _State,
			void *& _Val) const
		{	// get void pointer from [_First, _Last) into _Val
		return (do_get(_First, _Last, _Iosbase, _State, _Val));
		}

protected:
#if defined(__ghs)
	__noinline
#endif /* __ghs */
	_VIRTUAL _InIt do_get(_InIt _First, _InIt _Last,
		ios_base& _Iosbase, ios_base::iostate& _State,
			bool& _Val) const
		{	// get bool from [_First, _Last) into _Val
		_DEBUG_RANGE(_First, _Last);
		long _Ans = -1;	// negative answer indicates failure
#if defined(__ghs)
		bool _Is_eof = false;
#endif

		if (_Iosbase.flags() & ios_base::boolalpha)
			{	// get false name or true name
			typedef typename _Mystr::size_type _Mystrsize;
			const _Mypunct& _Punct_fac = use_facet< _Mypunct >(_Iosbase.getloc());
			_Mystr _Str((_Mystrsize)1, (char_type)0);
			_Str += _Punct_fac.falsename();
			_Str += (char_type)0;
			_Str += _Punct_fac.truename();	// construct "\0false\0true"
#if defined(__ghs)
			_Ans = _Getloctxt(_First, _Last, (size_t)2, _Str.c_str(), true, &_Is_eof);
#else
			_Ans = _Getloctxt(_First, _Last, (size_t)2, _Str.c_str());
#endif
			}
		else
			{	// get zero or nonzero integer
#if defined(__GHS_FASTER)
			char _Ac[_MAX_INT_DIG];
			bool _Fail;
			int _Base = _Getifld(_Ac, _First, _Last, _Iosbase.flags(),
						_Iosbase.getloc());
			const unsigned long _Ulo = _Xstrtoul(_Ac, _Base, 1, &_Fail);

			if (!_Fail)
				_Ans = _Ulo;
#else
			char _Ac[_MAX_INT_DIG], *_Ep;
			int _Errno = 0;
#if defined(__ghs) || defined(__SC3__)
			errno = 0;
			const unsigned long _Ulo = _CSTD strtoul(_Ac, &_Ep,
				_Getifld(_Ac, _First, _Last, _Iosbase.flags(),
					_Iosbase.getloc()));
			_Errno = errno;
#else /* !__ghs */
			const unsigned long _Ulo = _CSTD _Stoulx(_Ac, &_Ep,
				_Getifld(_Ac, _First, _Last, _Iosbase.flags(),
					_Iosbase.getloc()), &_Errno);
#endif /* !__ghs */
			if (_Ep != _Ac && _Errno == 0 && _Ulo <= 1)
				_Ans = _Ulo;
#endif
#if defined(__ghs)
			_Is_eof = (_First == _Last);
#endif
			}
#if defined(__ghs)
		if (_Is_eof)
			_State |= ios_base::eofbit;
#else
		if (_First == _Last)
			_State |= ios_base::eofbit;
#endif
		if (_Ans < 0)
			{	// make value true on failure
			_State |= ios_base::failbit;
 #if !defined(__ghs) || _HAS_CPP11
			_Val = !(_Iosbase.flags() & ios_base::boolalpha);
 #endif /* !defined(__ghs) || _HAS_CPP11 */
			}
		else
			_Val = _Ans != 0;	// deliver value
		return (_First);
		}

#if defined(__ghs)
	__noinline
#endif /* __ghs */
	_VIRTUAL _InIt do_get(_InIt _First, _InIt _Last,
		ios_base& _Iosbase, ios_base::iostate& _State,
			unsigned short& _Val) const
		{	// get unsigned short from [_First, _Last) into _Val
		_DEBUG_RANGE(_First, _Last);
#if defined(__GHS_FASTER)
		char _Ac[_MAX_INT_DIG];
		int _Base = _Getifld(_Ac, _First, _Last, _Iosbase.flags(),
			_Iosbase.getloc());	// gather field into _Ac
		bool _Fail;
		const unsigned long _Ans = _Xstrtoul(_Ac, _Base, USHRT_MAX, &_Fail);
#if defined(__ghs) && _HAS_CPP11
		_Val = _Ans;
		if (USHRT_MAX < _Ans || (_Ac[0] == '-' && _Ans > 0))
		        {
		        _Fail = true;
			_Val  = USHRT_MAX;
		        }
#endif
		if (_First == _Last)
			_State |= ios_base::eofbit;
		if (_Fail)
			_State |= ios_base::failbit;
#if !defined(__ghs) || !_HAS_CPP11
		else
			_Val = _Ans;	// deliver value
#endif
#else
		char _Ac[_MAX_INT_DIG], *_Ep;
		int _Errno = 0;
		int _Base = _Getifld(_Ac, _First, _Last, _Iosbase.flags(),
			_Iosbase.getloc());	// gather field into _Ac
		char *_Ptr = _Ac[0] == '-' ? _Ac + 1 : _Ac;	// point past any sign
#if defined(__ghs) || defined(__SC3__)
		errno = 0;
		const unsigned long _Ans =
		     _CSTD strtoul(_Ptr, &_Ep, _Base);	// convert
		_Errno = errno;
#else /* !__ghs */
		const unsigned long _Ans =
			_CSTD _Stoulx(_Ptr, &_Ep, _Base, &_Errno);	// convert
#endif /* !__ghs */

		if (_First == _Last)
			_State |= ios_base::eofbit;
		if (_Ep == _Ptr || _Errno != 0 || USHRT_MAX < _Ans)
			_State |= ios_base::failbit;
		else
			_Val = (unsigned short)(_Ac[0] == '-'
				? 0 - _Ans : _Ans);	// deliver value
#endif
		return (_First);
		}

#if defined(__ghs)
	__noinline
#endif /* __ghs */
	_VIRTUAL _InIt do_get(_InIt _First, _InIt _Last,
		ios_base& _Iosbase, ios_base::iostate& _State,
			unsigned int& _Val) const
		{	// get unsigned int from [_First, _Last) into _Val
		_DEBUG_RANGE(_First, _Last);
#if defined(__GHS_FASTER)
		char _Ac[_MAX_INT_DIG];
		int _Base = _Getifld(_Ac, _First, _Last, _Iosbase.flags(),
			_Iosbase.getloc());	// gather field into _Ac
		bool _Fail;
		const unsigned long _Ans = _Xstrtoul(_Ac, _Base, UINT_MAX, &_Fail);

#if defined(__ghs) && _HAS_CPP11
		_Val = _Ans;
		if (UINT_MAX < _Ans || (_Ac[0] == '-' && _Ans > 0))
		        {
		        _Fail = true;
			_Val  = UINT_MAX;
		        }
#endif
		if (_First == _Last)
			_State |= ios_base::eofbit;
		if (_Fail)
			_State |= ios_base::failbit;
#if !defined(__ghs) || !_HAS_CPP11
		else
			_Val = _Ans;	// deliver value
#endif
#else
		char _Ac[_MAX_INT_DIG], *_Ep;
		int _Errno = 0;
		int _Base = _Getifld(_Ac, _First, _Last, _Iosbase.flags(),
			_Iosbase.getloc());	// gather field into _Ac
		char *_Ptr = _Ac[0] == '-' ? _Ac + 1 : _Ac;	// point past any sign
#if defined(__ghs) || defined(__SC3__)
		errno = 0;
		const unsigned long _Ans =
			_CSTD strtoul(_Ptr, &_Ep, _Base);	// convert
		_Errno = errno;
#else /* !__ghs */
		const unsigned long _Ans =
			_CSTD _Stoulx(_Ptr, &_Ep, _Base, &_Errno);	// convert
#endif /* !__ghs */

		if (_First == _Last)
			_State |= ios_base::eofbit;
		if (_Ep == _Ptr || _Errno != 0 || UINT_MAX < _Ans)
			_State |= ios_base::failbit;
		else
			_Val = (unsigned int)(_Ac[0] == '-'
				? 0 - _Ans : _Ans);	// deliver value
#endif
		return (_First);
		}

#if defined(__ghs)
	__noinline
#endif /* __ghs */
	_VIRTUAL _InIt do_get(_InIt _First, _InIt _Last,
		ios_base& _Iosbase, ios_base::iostate& _State,
			long& _Val) const
		{	// get long from [_First, _Last) into _Val
		_DEBUG_RANGE(_First, _Last);
		char _Ac[_MAX_INT_DIG], *_Ep;
		int _Errno = 0;
#if defined(__ghs) || defined(__SC3__)
		errno = 0;
		const long _Ans = _CSTD strtol(_Ac, &_Ep,
			_Getifld(_Ac, _First, _Last, _Iosbase.flags(),
				_Iosbase.getloc()));  // gather field, convert
		_Errno = errno;
#else /* !__ghs */
		const long _Ans = _CSTD _Stolx(_Ac, &_Ep,
			_Getifld(_Ac, _First, _Last, _Iosbase.flags(),
				_Iosbase.getloc()), &_Errno);	// gather field, convert
#endif /* !__ghs */

		if (_First == _Last)
			_State |= ios_base::eofbit;
		if (_Ep == _Ac || _Errno != 0)
			_State |= ios_base::failbit;
#if defined(__ghs) && _HAS_CPP11
		_Val = _Ans;	// deliver value
#else
		else
			_Val = _Ans;	// deliver value
#endif
		return (_First);
		}

#if defined(__ghs)
	__noinline
#endif /* __ghs */
	_VIRTUAL _InIt do_get(_InIt _First, _InIt _Last,
		ios_base& _Iosbase, ios_base::iostate& _State,
			unsigned long& _Val) const
		{	// get unsigned long from [_First, _Last) into _Val
		_DEBUG_RANGE(_First, _Last);
#if defined(__GHS_FASTER)
		char _Ac[_MAX_INT_DIG];
		bool _Fail;
		int _Base = _Getifld(_Ac, _First, _Last, _Iosbase.flags(),
				_Iosbase.getloc());   // gather field, convert
		const unsigned long _Ans = _Xstrtoul(_Ac, _Base, ULONG_MAX, &_Fail);

#if defined(__ghs) && _HAS_CPP11
		_Val = _Ans;
		if (_Ac[0] == '-' && _Ans > 0)
		        {
		        _Fail = true;
			_Val  = ULONG_MAX;
		        }
#endif
		if (_First == _Last)
			_State |= ios_base::eofbit;
		if (_Fail)
			_State |= ios_base::failbit;
#if !defined(__ghs) || !_HAS_CPP11
		else
			_Val = _Ans;	// deliver value
#endif
#else
		char _Ac[_MAX_INT_DIG], *_Ep;
		int _Errno = 0;
#if defined(__ghs) || defined(__SC3__)
		errno = 0;
		const unsigned long _Ans = _CSTD strtoul(_Ac, &_Ep,
			_Getifld(_Ac, _First, _Last, _Iosbase.flags(),
				_Iosbase.getloc()));   // gather field, convert
		_Errno = errno;
#else /* !__ghs */
		const unsigned long _Ans = _CSTD _Stoulx(_Ac, &_Ep,
			_Getifld(_Ac, _First, _Last, _Iosbase.flags(),
				_Iosbase.getloc()), &_Errno);	// gather field, convert
#endif /* !__ghs */

		if (_First == _Last)
			_State |= ios_base::eofbit;
		if (_Ep == _Ac || _Errno != 0)
			_State |= ios_base::failbit;
		else
			_Val = _Ans;	// deliver value
#endif
		return (_First);
		}

 #ifdef _LONGLONG
#if defined(__ghs)
	__noinline
#endif /* __ghs */
	_VIRTUAL _InIt do_get(_InIt _First, _InIt _Last,
		ios_base& _Iosbase, ios_base::iostate& _State,
			_LONGLONG& _Val) const
		{	// get long long from [_First, _Last) into _Val
		_DEBUG_RANGE(_First, _Last);
		char _Ac[_MAX_INT_DIG], *_Ep;
		int _Errno = 0;
		const _LONGLONG _Ans = _CSTD _Stollx(_Ac, &_Ep,
			_Getifld(_Ac, _First, _Last, _Iosbase.flags(),
				_Iosbase.getloc()), &_Errno);	// gather field, convert

		if (_First == _Last)
			_State |= ios_base::eofbit;
		if (_Ep == _Ac || _Errno != 0)
			_State |= ios_base::failbit;
#if defined(__ghs) && _HAS_CPP11
		_Val = _Ans;	// deliver value
#else
		else
			_Val = _Ans;	// deliver value
#endif
		return (_First);
		}

#if defined(__ghs)
	__noinline
#endif /* __ghs */
	_VIRTUAL _InIt do_get(_InIt _First, _InIt _Last,
		ios_base& _Iosbase, ios_base::iostate& _State,
			_ULONGLONG& _Val) const
		{	// get unsigned long long from [_First, _Last) into _Val
		_DEBUG_RANGE(_First, _Last);
		char _Ac[_MAX_INT_DIG], *_Ep;
		int _Errno = 0;
		const _ULONGLONG _Ans = _CSTD _Stoullx(_Ac, &_Ep,
			_Getifld(_Ac, _First, _Last, _Iosbase.flags(),
				_Iosbase.getloc()), &_Errno);	// gather field, convert

#if defined(__ghs) && _HAS_CPP11
		_Val = _Ans;
		if (_Ac[0] == '-' && _Ans > 0)
		        {
			_State |= ios_base::failbit;
			_Val  = ULLONG_MAX;
		        }
#endif
		if (_First == _Last)
			_State |= ios_base::eofbit;
		if (_Ep == _Ac || _Errno != 0)
			_State |= ios_base::failbit;
#if !defined(__ghs) || !_HAS_CPP11
		else
			_Val = _Ans;	// deliver value
#endif
		return (_First);
		}
 #else
        /* If we do not have 'long long' support, we still need to preserve
	   the number and order of virtual functions. */
	struct __dummy_type1{};
	struct __dummy_type2{};
	_VIRTUAL void do_get(__dummy_type1) { }
	_VIRTUAL void do_get(__dummy_type2) { }
 #endif /* _LONGLONG */

#if !(defined(__ghs) || defined(__SC3__)) || !defined(__NoFloat)
#if defined(__ghs)
	__noinline
#endif /* __ghs */
	_VIRTUAL _InIt do_get(_InIt _First, _InIt _Last,
		ios_base& _Iosbase, ios_base::iostate& _State,
			float& _Val) const
		{	// get float from [_First, _Last) into _Val
		_DEBUG_RANGE(_First, _Last);
		char _Ac[_MAX_EXP_DIG + _MAX_SIG_DIG + 16], *_Ep;
#if !defined(__GHS_FASTER)
		int _Errno = 0;
#endif
		int _Hexexp = 0;
#if defined(__ghs) || defined(__SC3__)
#if !defined(__GHS_FASTER)
		errno = 0;
#endif
		float _Ans = _CSTD _Stof(_Ac, &_Ep,
			_Getffld(_Ac, _First, _Last,
				_Iosbase, &_Hexexp));	// gather field, convert
#if !defined(__GHS_FASTER)
		_Errno = errno;
#endif
#else /* !__ghs */
		float _Ans = _CSTD _Stofx(_Ac, &_Ep,
			_Getffld(_Ac, _First, _Last,
				_Iosbase, &_Hexexp), &_Errno);	// gather field, convert
#endif /* !__ghs */

		if (_Hexexp != 0)
			_Ans = _CSTD ldexpf(_Ans, 4 * _Hexexp);

		if (_First == _Last)
			_State |= ios_base::eofbit;
#if defined(__GHS_FASTER)
		if (_Ep == _Ac)
#else
		if (_Ep == _Ac || _Errno != 0)
#endif
			_State |= ios_base::failbit;
#if defined(__ghs) && _HAS_CPP11
		_Val = _Ans;	// deliver value
#else
		else
			_Val = _Ans;	// deliver value
#endif
		return (_First);
		}

#if defined(__ghs)
	__noinline
#endif /* __ghs */
	_VIRTUAL _InIt do_get(_InIt _First, _InIt _Last,
		ios_base& _Iosbase, ios_base::iostate& _State,
			double& _Val) const
		{	// get double from [_First, _Last) into _Val
		_DEBUG_RANGE(_First, _Last);
		char _Ac[_MAX_EXP_DIG + _MAX_SIG_DIG + 16], *_Ep;
#if !defined(__GHS_FASTER)
		int _Errno = 0;
#endif
		int _Hexexp = 0;
#if defined(__ghs) || defined(__SC3__)
#if !defined(__GHS_FASTER)
		errno = 0;
#endif
#if defined(__FloatSingle__)
		double _Ans = _CSTD _Stof(_Ac, &_Ep,
#else
		double _Ans = _CSTD _Stod(_Ac, &_Ep,
#endif
			_Getffld(_Ac, _First, _Last,
				_Iosbase, &_Hexexp));	// gather field, convert
#if !defined(__GHS_FASTER)
		_Errno = errno;
#endif
#else /* !__ghs */
		double _Ans = _CSTD _Stodx(_Ac, &_Ep,
			_Getffld(_Ac, _First, _Last,
				_Iosbase, &_Hexexp), &_Errno);	// gather field, convert
#endif /* !__ghs */

		if (_Hexexp != 0)
			_Ans = _CSTD ldexp(_Ans, 4 * _Hexexp);

		if (_First == _Last)
			_State |= ios_base::eofbit;
#if defined(__GHS_FASTER)
		if (_Ep == _Ac)
#else
		if (_Ep == _Ac || _Errno != 0)
#endif
			_State |= ios_base::failbit;
#if defined(__ghs) && _HAS_CPP11
		_Val = _Ans;	// deliver value
#else
		else
			_Val = _Ans;	// deliver value
#endif
		return (_First);
		}

#if defined(__ghs)
	__noinline
#endif /* __ghs */
	_VIRTUAL _InIt do_get(_InIt _First, _InIt _Last,
		ios_base& _Iosbase, ios_base::iostate& _State,
			long double& _Val) const
		{	// get long double from [_First, _Last) into _Val
		_DEBUG_RANGE(_First, _Last);
		char _Ac[_MAX_EXP_DIG + _MAX_SIG_DIG + 16], *_Ep;
#if !defined(__GHS_FASTER)
		int _Errno = 0;
#endif
		int _Hexexp = 0;
#if defined(__ghs) || defined(__SC3__)
#if !defined(__GHS_FASTER)
		errno = 0;
#endif
#if defined(__FloatSingle__)
		long double _Ans = _CSTD _Stof(_Ac, &_Ep,
#else
		long double _Ans = _CSTD _Stold(_Ac, &_Ep,
#endif
			_Getffld(_Ac, _First, _Last,
				_Iosbase, &_Hexexp));	// gather field, convert
#if !defined(__GHS_FASTER)
		_Errno = errno;
#endif
#else /* !__ghs */
		long double _Ans = _CSTD _Stoldx(_Ac, &_Ep,
			_Getffld(_Ac, _First, _Last,
				_Iosbase, &_Hexexp), &_Errno);	// gather field, convert
#endif /* !__ghs */

		if (_Hexexp != 0)
			_Ans = _CSTD ldexpl(_Ans, 4 * _Hexexp);

		if (_First == _Last)
			_State |= ios_base::eofbit;
#if defined(__GHS_FASTER)
		if (_Ep == _Ac)
#else
		if (_Ep == _Ac || _Errno != 0)
#endif
			_State |= ios_base::failbit;
#if defined(__ghs) && _HAS_CPP11
		_Val = _Ans;	// deliver value
#else
		else
			_Val = _Ans;	// deliver value
#endif
		return (_First);
		}
#else
	/* If we do not have floating point support, we still need to preserve
	   the number and order of virtual functions. */
	struct __dummy_type3{};
	struct __dummy_type4{};
        struct __dummy_type5{};
	_VIRTUAL void do_get(__dummy_type3) { }
	_VIRTUAL void do_get(__dummy_type4) { }
        _VIRTUAL void do_get(__dummy_type5) { }
#endif // !defined(__ghs) || !defined(__NoFloat)

#if defined(__ghs)
	__noinline
#endif /* __ghs */
	_VIRTUAL _InIt do_get(_InIt _First, _InIt _Last,
		ios_base& _Iosbase, ios_base::iostate& _State,
			void *& _Val) const
		{	// get void pointer from [_First, _Last) into _Val
		_DEBUG_RANGE(_First, _Last);
		char _Ac[_MAX_INT_DIG], *_Ep;
		int _Errno = 0;
#if defined(__ghs) || defined(__SC3__)
		errno = 0;
#endif /* __ghs */


 #ifdef _LONGLONG
		int _Base = _Getifld(_Ac, _First, _Last, ios_base::hex,
			_Iosbase.getloc());	// gather field
		const _ULONGLONG _Ans =
			(sizeof (void *) == sizeof (unsigned long))
#if defined(__ghs) || defined(__SC3__)
				? (_ULONGLONG)_CSTD strtoul(_Ac, &_Ep, _Base)
#else /* !__ghs */
				? (_ULONGLONG)_CSTD _Stoulx(_Ac, &_Ep, _Base, &_Errno)
#endif /* !__ghs */
				: _CSTD _Stoullx(_Ac, &_Ep, _Base, &_Errno);

 #else /* _LONGLONG */
#if defined(__ghs) || defined(__SC3__)
		const unsigned long _Ans = _CSTD strtoul(_Ac, &_Ep,
			_Getifld(_Ac, _First, _Last, ios_base::hex,
				_Iosbase.getloc()));   // gather field, convert
#else /* !__ghs */
		const unsigned long _Ans = _CSTD _Stoulx(_Ac, &_Ep,
			_Getifld(_Ac, _First, _Last, ios_base::hex,
				_Iosbase.getloc()), &_Errno);	// gather field, convert
#endif /* !__ghs */
 #endif /* _LONGLONG */
#if defined(__ghs) || defined(__SC3__)
		_Errno = errno;
#endif /* __ghs */

		if (_First == _Last)
			_State |= ios_base::eofbit;
		if (_Ep == _Ac || _Errno != 0)
#if defined(__ghs) && _HAS_CPP11
		        {
			_State |= ios_base::failbit;
			_Val = (void *)0;
		        }
#else
			_State |= ios_base::failbit;
#endif
		else
			_Val = (void *)((char *)0 + _Ans);	// deliver value
		return (_First);
		}

private:
	int _Getifld(char *_Ac,
		_InIt& _First, _InIt& _Last, ios_base::fmtflags _Basefield,
			const locale& _Loc) const
		{	// get integer field from [_First, _Last) into _Ac
		const _Mypunct& _Punct_fac = use_facet< _Mypunct >(_Loc);
		const string _Grouping = _Punct_fac.grouping();
		const _Elem _Kseparator = _Grouping.size() == 0
			? (_Elem)0 : _Punct_fac.thousands_sep();

		enum {
			_NUMGET_SIGNOFF = 22,
			_NUMGET_XOFF = 24};
		static const char _Src[] = {"0123456789ABCDEFabcdef-+Xx"};
		_Elem _Atoms[sizeof (_Src)];
		const ctype<_Elem>& _Ctype_fac =
			use_facet< ctype<_Elem> >(_Loc);
		_Ctype_fac.widen(&_Src[0], &_Src[sizeof (_Src)], _Atoms);

		char *_Ptr = _Ac;

		if (_First == _Last)
			;	// empty field
#if defined(__GHS_FASTER)
		else if ((2 | (2 + (_Elem)*_First)) == _Atoms[_NUMGET_SIGNOFF]+2)
			{ *_Ptr++ = *_First++; }	// gather plus or minus sign
#else
		else if (*_First == _Atoms[_NUMGET_SIGNOFF + 1])
			{ *_Ptr++ = '+'; ++_First; }	// gather plus sign
		else if (*_First == _Atoms[_NUMGET_SIGNOFF])
			{ *_Ptr++ = '-'; ++_First; }	// gather minus sign
#endif
		_Basefield &= ios_base::basefield;
		int _Base = _Basefield == ios_base::oct ? 8
			: _Basefield == ios_base::hex ? 16
			: _Basefield == ios_base::_Fmtzero ? 0 : 10;

		bool _Seendigit = false;	// seen a digit in input
		bool _Nonzero = false;	// seen a nonzero digit in input

#if defined(__GHS_FASTER)
		if (_First != _Last && *_First == _Atoms[0] && ((_Base & 15) == 0))	// Fmtzero or Hex
			{	// leading zero, look for 0x, 0X
			_Seendigit = true; ++_First;
			_Base >>= 1;
			_Base += 8;
			if (_First != _Last && (*_First | 0x20) == _Atoms[_NUMGET_XOFF + 1])
				{ _Base = 16; _Seendigit = false; ++_First; }
			}

		size_t _Dlen = _Base;
		if (_Dlen == 0)
		    _Dlen = 10;
		if (_Dlen == 16)
		    _Dlen = 22;
#else
		if (_First != _Last && *_First == _Atoms[0])
			{	// leading zero, look for 0x, 0X
			_Seendigit = true; ++_First;
			if (_First != _Last && (*_First == _Atoms[_NUMGET_XOFF + 1]
					|| *_First == _Atoms[_NUMGET_XOFF])
				&& (_Base == 0 || _Base == 16))
				{ _Base = 16; _Seendigit = false; ++_First; }
			else if (_Base == 0)
				_Base = 8;
			}

		size_t _Dlen = _Base == 0 || _Base == 10 ? 10
			: _Base == 8 ? 8 : 16 + 6;
#endif
		string _Groups((size_t)1, (char)_Seendigit);
		size_t _Group = 0;

		for (char *const _Pe = &_Ac[_MAX_INT_DIG - 1];
			_First != _Last; ++_First)
			{	// look for digits and separators
			size_t _Idx = _Find_elem(_Atoms, *_First);
			if (_Idx < _Dlen)
				{	// got a digit, characterize it and add to group size
				*_Ptr = _Src[_Idx];
				if ((_Nonzero || *_Ptr != '0') && _Ptr < _Pe)
					{ ++_Ptr; _Nonzero = true; }
				_Seendigit = true;
				if (_Groups[_Group] != CHAR_MAX)
					++_Groups[_Group];
				}
			else if (_Groups[_Group] == '\0'
				|| _Kseparator == (_Elem)0
				|| *_First != _Kseparator)
				break;	// not a group separator, done
			else
				{	// add a new group to _Groups string
				_Groups.append((string::size_type)1, '\0');
				++_Group;
				}
			}

		if (_Group == 0)
			;	// no thousands separators seen
		else if ('\0' < _Groups[_Group])
			++_Group;	// add trailing group to group count
		else
			_Seendigit = false;	// trailing separator, fail

		for (const char *_Pg = &_Grouping[0]; _Seendigit && 0 < _Group; )
			if (*_Pg == CHAR_MAX)
				break;	// end of grouping constraints to check
			else if ((0 < --_Group && *_Pg != _Groups[_Group])
				|| (0 == _Group && *_Pg < _Groups[_Group]))
				_Seendigit = false;	// bad group size, fail
			else if ('\0' < _Pg[1])
				++_Pg;	// group size okay, advance to next test

#if defined(__GHS_FASTER)
		if (!_Seendigit)
			_Ptr = _Ac;	// roll back pointer to indicate failure
		else if (!_Nonzero)
			*_Ptr++ = '0';	// zero field, replace stripped zero(s)
#else
		if (_Seendigit && !_Nonzero)
			*_Ptr++ = '0';	// zero field, replace stripped zero(s)
		else if (!_Seendigit)
			_Ptr = _Ac;	// roll back pointer to indicate failure
#endif
		*_Ptr = '\0';
		return (_Base);
		}

	int _Getffld(char *_Ac,
		_InIt& _First, _InIt &_Last,
		ios_base& _Iosbase, int *_Phexexp) const
		{	// get floating-point field from [_First, _Last) into _Ac
		if ((_Iosbase.flags() & ios_base::floatfield) == ios_base::hexfloat)
			return (_Getffldx(_Ac, _First, _Last,
				_Iosbase, _Phexexp));	// hex format

		const _Mypunct& _Punct_fac = use_facet< _Mypunct >(_Iosbase.getloc());
		const string _Grouping = _Punct_fac.grouping();
		char *_Ptr = _Ac;
		bool _Bad = false;
		bool _Sticky = false;
#if defined(__ghs)
		enum {
			_NUMGET_SIGNOFF = 10,
			_NUMGET_EOFF = 12,
			_NUMGET_XOFF = 14
			};
		static const char _Src[] = {"0123456789-+EeXx"};
#else
		enum {
			_NUMGET_SIGNOFF = 10,
			_NUMGET_EOFF = 12};
		static const char _Src[] = {"0123456789-+Ee"};
#endif
		_Elem _Atoms[sizeof (_Src)];
		const ctype<_Elem>& _Ctype_fac =
			use_facet< ctype<_Elem> >(_Iosbase.getloc());
		_Ctype_fac.widen(&_Src[0], &_Src[sizeof (_Src)], _Atoms);
#if defined(__GHS_FASTER)
		const _Elem _Elem0 = _Atoms[0];
#endif

		if (_First == _Last)
			;	// empty field
#if defined(__GHS_FASTER)
		else if ((2 | (2 + (_Elem)*_First)) == _Atoms[_NUMGET_SIGNOFF]+2)
			{ *_Ptr++ = *_First++; }	// gather plus or minus sign
#else
		else if (*_First == _Atoms[_NUMGET_SIGNOFF + 1])
			{ *_Ptr++ = '+'; ++_First; }	// gather plus sign
		else if (*_First == _Atoms[_NUMGET_SIGNOFF])
			{ *_Ptr++ = '-'; ++_First; }	// gather minus sign
#endif

#if defined(__ghs)
		bool _Seendigit = false;	// seen a digit in input
		if (_First != _Last && *_First == _Atoms[0])
			{	// leading zero, look for 0x, 0X
				if ((++_First != _Last) &&
					(*_First == _Atoms[_NUMGET_XOFF + 1] || *_First == _Atoms[_NUMGET_XOFF]))
					return (_Getffldx(_Ptr, ++_First, _Last, _Iosbase, _Phexexp, false));
				_Seendigit = true;
			}
#endif
		char *_Leading = _Ptr;	// remember backstop
		*_Ptr++ = '0';	// backstop carries from sticky bit

#if !defined(__ghs)
		bool _Seendigit = false;	// seen a digit in input
#endif
		int _Significant = 0;	// number of significant digits
		int _Pten = 0;	// power of 10 multiplier
		size_t _Idx;

		const char *_Pg = &_Grouping[0];
#if defined(__GHS_FASTER)
		bool _NoGroup = (*_Pg == CHAR_MAX || *_Pg <= '\0');
#else
		if (*_Pg == CHAR_MAX || *_Pg <= '\0')
			for (; _First != _Last
				&& (_Idx = _Find_elem(_Atoms, *_First)) < 10;
					_Seendigit = true, ++_First)
				if (_MAX_SIG_DIG <= _Significant)
					{	// enough digits, scale by 10 and update _Sticky
					++_Pten;
					if (0 < _Idx)
						_Sticky = true;
					}
				else if (_Idx == 0 && _Significant == 0)
					;	// drop leading zeros
				else
					{	// save a significant digit
					*_Ptr++ = _Src[_Idx];
					++_Significant;
					}
		else
#endif
			{	// grouping specified, gather digits and group sizes
			const _Elem _Kseparator = _Grouping.size() == 0
				? (_Elem)0 : _Punct_fac.thousands_sep();
			string _Groups((size_t)1, '\0');
			size_t _Group = 0;

#if defined(__GHS_FASTER)
			for (; _First != _Last; ++_First)
				{
				const _Elem ch = *_First;
				if ((_Idx = _GetDigit(ch)) < 10)
					{	// got a digit, add to group size
					_Seendigit = true;
					if (_MAX_SIG_DIG <= _Significant)
						{	// enough digits, scale by 10 and update _Sticky
						++_Pten;
						if (0 < _Idx)
							_Sticky = true;
						}
					else if (_Idx == 0 && _Significant == 0)
						;	// drop leading zeros
					else
						{	// save a significant digit
						*_Ptr++ = _Src[_Idx];
						++_Significant;
						}
					if (_Groups[_Group] != CHAR_MAX)
						++_Groups[_Group];
					}
				else if (_Groups[_Group] == '\0'
					|| _NoGroup
					|| _Kseparator == (_Elem)0
					|| ch != _Kseparator)
					break;	// not a group separator, done
				else
					{	// add a new group to _Groups string
					_Groups.append((size_t)1, '\0');
					++_Group;
					}
				}
#else
			for (; _First != _Last; ++_First)
				if ((_Idx = _Find_elem(_Atoms, *_First)) < 10)
					{	// got a digit, add to group size
					_Seendigit = true;
					if (_MAX_SIG_DIG <= _Significant)
						{	// enough digits, scale by 10 and update _Sticky
						++_Pten;
						if (0 < _Idx)
							_Sticky = true;
						}
					else if (_Idx == 0 && _Significant == 0)
						;	// drop leading zeros
					else
						{	// save a significant digit
						*_Ptr++ = _Src[_Idx];
						++_Significant;
						}
					if (_Groups[_Group] != CHAR_MAX)
						++_Groups[_Group];
					}
				else if (_Groups[_Group] == '\0'
					|| _Kseparator == (_Elem)0
					|| *_First != _Kseparator)
					break;	// not a group separator, done
				else
					{	// add a new group to _Groups string
					_Groups.append((size_t)1, '\0');
					++_Group;
					}
#endif
			if (_Group == 0)
				;	// no thousands separators seen
			else if ('\0' < _Groups[_Group])
				++_Group;	// add trailing group to group count
			else
				_Bad = true;	// trailing separator, fail

			while (!_Bad && 0 < _Group)
				if (*_Pg == CHAR_MAX)
					break;	// end of grouping constraints to check
				else if ((0 < --_Group && *_Pg != _Groups[_Group])
					|| (0 == _Group && *_Pg < _Groups[_Group]))
					_Bad = true;	// bad group size, fail
				else if ('\0' < _Pg[1])
					++_Pg;	// group size okay, advance to next test
			}

		if (_First != _Last && *_First == _Punct_fac.decimal_point())
			{ *_Ptr++ = localeconv()->decimal_point[0]; ++_First; }	// add .

		if (_Significant == 0)
			{	// 0000. so far
			for (; _First != _Last && *_First == _Atoms[0];
				_Seendigit = true, ++_First)
				--_Pten;	// just count leading fraction zeros
			if (_Pten < 0)
				{ *_Ptr++ = '0'; ++_Pten; }	// put one back
			}

		for (; _First != _Last
#if defined(__GHS_FASTER)
				&& (_Idx = _GetDigit(*_First)) < 10;
#else
				&& (_Idx = _Find_elem(_Atoms, *_First)) < 10;
#endif
				_Seendigit = true, ++_First)
			if (_Significant < _MAX_SIG_DIG)
				{	// save a significant fraction digit
				*_Ptr++ = _Src[_Idx];
				++_Significant;
				}
			else if (0 < _Idx)
				_Sticky = true;	// just update _Sticky

		if (_Sticky)
			{	// increment ls digit in memory of those lost
			char *_Px = _Ptr;
			for (; --_Px != _Leading; )
				{	// add in carry
				if (*_Px == localeconv()->decimal_point[0])
					;	// skip over decimal point
				else if (*_Px != '9')
					{	// carry stops here
					++*_Px;
					break;
					}
				else
					*_Px = '0';	// propagate carry
				}

			if (_Px == _Leading)
				{	// change "999..." to "1000..." and scale _Pten
				*_Px = '1';
				++_Pten;
				}
			}

		if (_Seendigit && _First != _Last
#if defined(__GHS_FASTER)
			&& ((*_First | 0x20) == _Atoms[_NUMGET_EOFF + 1]))
#else
			&& (*_First == _Atoms[_NUMGET_EOFF + 1]
				|| *_First == _Atoms[_NUMGET_EOFF]))
#endif
			{	// 'e' or 'E', collect exponent
			*_Ptr++ = 'e'; ++_First;
			_Seendigit = false; _Significant = 0;

			if (_First == _Last)
				;	// 'e' or 'E' is last element
#if defined(__GHS_FASTER)
			else if ((2 | (2 + (_Elem)*_First)) == _Atoms[_NUMGET_SIGNOFF]+2)
				{ *_Ptr++ = *_First++; }	// gather plus or minus sign
#else
			else if (*_First == _Atoms[_NUMGET_SIGNOFF + 1])
				{ *_Ptr++ = '+'; ++_First; }	// gather plus sign
			else if (*_First == _Atoms[_NUMGET_SIGNOFF])
				{ *_Ptr++ = '-'; ++_First; }	// gather minus sign
#endif
			for (; _First != _Last && *_First == _Atoms[0]; )
				{ _Seendigit = true; ++_First; }	// strip leading zeros
			if (_Seendigit)
				*_Ptr++ = '0';	// put one back
			for (; _First != _Last
#if defined(__GHS_FASTER)
				&& (_Idx = _GetDigit(*_First)) < 10;
#else
				&& (_Idx = _Find_elem(_Atoms, *_First)) < 10;
#endif
				_Seendigit = true, ++_First)
				if (_Significant < _MAX_EXP_DIG)
					{	// save a significant exponent digit
					*_Ptr++ = _Src[_Idx];
					++_Significant;
					}
			}

		if (_Bad || !_Seendigit)
			_Ptr = _Ac;	// roll back pointer to indicate failure
		*_Ptr = '\0';
		return (_Pten);
		}

	int _Getffldx(char *_Ac,
		_InIt& _First, _InIt &_Last,
#if defined(__ghs)
		ios_base& _Iosbase, int *_Phexexp, bool _AllowS0X = true) const
#else
		ios_base& _Iosbase, int *_Phexexp) const
#endif
		{	// get hex floating-point field from [_First, _Last) into _Ac
		const _Mypunct& _Punct_fac = use_facet< _Mypunct >(_Iosbase.getloc());
		const string _Grouping = _Punct_fac.grouping();

		enum {
			_NUMGET_SIGNOFF = 22,
			_NUMGET_XOFF = 24,
			_NUMGET_POFF = 26};
		static const char _Src[] = {"0123456789ABCDEFabcdef-+XxPp"};
		_Elem _Atoms[sizeof (_Src)];
		const ctype<_Elem>& _Ctype_fac =
			use_facet< ctype<_Elem> >(_Iosbase.getloc());
		_Ctype_fac.widen(&_Src[0], &_Src[sizeof (_Src)], _Atoms);

		char *_Ptr = _Ac;
		bool _Bad = false;
		size_t _Idx;

#if defined(__ghs)
		if (!_AllowS0X || _First == _Last)
#else
		if (_First == _Last)
#endif
			;	// empty field
		else if (*_First == _Atoms[_NUMGET_SIGNOFF + 1])
			*_Ptr++ = '+', ++_First;	// gather plus sign
		else if (*_First == _Atoms[_NUMGET_SIGNOFF])
			*_Ptr++ = '-', ++_First;	// gather minus sign

		*_Ptr++ = '0';
		*_Ptr++ = 'x';

		bool _Seendigit = false;	// seen a digit in input
		int _Significant = 0;	// number of significant digits
		int _Phex = 0;	// power of 10 multiplier
#if defined(__ghs)
		if (!_AllowS0X || _First == _Last || *_First != _Atoms[0])
#else
		if (_First == _Last || *_First != _Atoms[0])
#endif
			;
		else if (++_First != _Last
			&& (*_First == _Atoms[_NUMGET_XOFF + 1]
				|| *_First == _Atoms[_NUMGET_XOFF]))
			++_First;	// discard any 0x or 0X
		else
			_Seendigit = true;	// '0' not followed by 'x' or 'X'

		const char *_Pg = &_Grouping[0];
		if (*_Pg == CHAR_MAX || *_Pg <= '\0')
			for (; _First != _Last
				&& (_Idx = _Find_elem(_Atoms, *_First)) < _NUMGET_SIGNOFF;
					_Seendigit = true, ++_First)
				if (_MAX_SIG_DIG <= _Significant)
					++_Phex;	// just scale by 10
				else if (_Idx == 0 && _Significant == 0)
					;	// drop leading zeros
				else
					{	// save a significant digit
					*_Ptr++ = _Src[_Idx];
					++_Significant;
					}
		else
			{	// grouping specified, gather digits and group sizes
			const _Elem _Kseparator = _Grouping.size() == 0
				? (_Elem)0 : _Punct_fac.thousands_sep();
			string _Groups((size_t)1, '\0');
			size_t _Group = 0;

			for (; _First != _Last; ++_First)
				if ((_Idx = _Find_elem(_Atoms, *_First)) < _NUMGET_SIGNOFF)
					{	// got a digit, add to group size
					_Seendigit = true;
					if (_MAX_SIG_DIG <= _Significant)
						++_Phex;	// just scale by 10
					else if (_Idx == 0 && _Significant == 0)
						;	// drop leading zeros
					else
						{	// save a significant digit
						*_Ptr++ = _Src[_Idx];
						++_Significant;
						}
					if (_Groups[_Group] != CHAR_MAX)
						++_Groups[_Group];
					}
				else if (_Groups[_Group] == '\0'
					|| _Kseparator == (_Elem)0
					|| *_First != _Kseparator)
					break;	// not a group separator, done
				else
					{	// add a new group to _Groups string
					_Groups.append((size_t)1, '\0');
					++_Group;
					}
			if (_Group == 0)
				;	// no thousands separators seen
			else if ('\0' < _Groups[_Group])
				++_Group;	// add trailing group to group count
			else
				_Bad = true;	// trailing separator, fail

			while (!_Bad && 0 < _Group)
				if (*_Pg == CHAR_MAX)
					break;	// end of grouping constraints to check
				else if ((0 < --_Group && *_Pg != _Groups[_Group])
					|| (0 == _Group && *_Pg < _Groups[_Group]))
					_Bad = true;	// bad group size, fail
				else if ('\0' < _Pg[1])
					++_Pg;	// group size okay, advance to next test
			}

		if (_Seendigit && _Significant == 0)
			*_Ptr++ = '0';	// save at least one leading digit

		if (_First != _Last && *_First == _Punct_fac.decimal_point())
			*_Ptr++ = localeconv()->decimal_point[0], ++_First;	// add .

		if (_Significant == 0)
			{	// 0000. so far
			for (; _First != _Last && *_First == _Atoms[0];
				_Seendigit = true, ++_First)
				--_Phex;	// just count leading fraction zeros
			if (_Phex < 0)
				*_Ptr++ = '0', ++_Phex;	// put one back
			}

		for (; _First != _Last
				&& (_Idx = _Find_elem(_Atoms, *_First)) < _NUMGET_SIGNOFF;
				_Seendigit = true, ++_First)
			if (_Significant < _MAX_SIG_DIG)
				{	// save a significant fraction digit
				*_Ptr++ = _Src[_Idx];
				++_Significant;
				}

		if (_Seendigit && _First != _Last
			&& (*_First == _Atoms[_NUMGET_POFF + 1]
				|| *_First == _Atoms[_NUMGET_POFF]))
			{	// 'p' or 'P', collect exponent
			*_Ptr++ = 'p', ++_First;
			_Seendigit = false, _Significant = 0;

			if (_First == _Last)
				;	// 'p' or 'P' is last element
			else if (*_First == _Atoms[_NUMGET_SIGNOFF + 1])
				*_Ptr++ = '+', ++_First;	// gather plus sign
			else if (*_First == _Atoms[_NUMGET_SIGNOFF])
				*_Ptr++ = '-', ++_First;	// gather minus sign
			for (; _First != _Last && *_First == _Atoms[0]; )
				_Seendigit = true, ++_First;	// strip leading zeros
			if (_Seendigit)
				*_Ptr++ = '0';	// put one back
			for (; _First != _Last
				&& (_Idx = _Find_elem(_Atoms, *_First)) < _NUMGET_SIGNOFF;
				_Seendigit = true, ++_First)
				if (_Significant < _MAX_EXP_DIG)
					{	// save a significant exponent digit
					*_Ptr++ = _Src[_Idx];
					++_Significant;
					}
			}

		if (_Bad || !_Seendigit)
			_Ptr = _Ac;	// roll back pointer to indicate failure
		*_Ptr = '\0';
		*_Phexexp = _Phex;	// power of 16 multiplier
		return (0);	// power of 10 multiplier
		}
	};

#if defined(__ghs) && defined(__ghs_shared_object_support)
template<class _Elem,
	class _InIt>
	num_get<_Elem, _InIt>::~num_get() _NOEXCEPT
		{	// destroy the object
		}
#endif /* __ghs && defined(__ghs_shared_object_support) */

		// STATIC num_get::id OBJECT
template<class _Elem,
	class _InIt>
	locale::id num_get<_Elem, _InIt>::id;

		// TEMPLATE CLASS num_put
template<class _Elem,
	class _OutIt = ostreambuf_iterator<_Elem, char_traits<_Elem> > >
	class num_put
		: public locale::facet
	{	// facet for converting encoded numbers to text
public:
	typedef numpunct<_Elem> _Mypunct;
	typedef basic_string<_Elem, char_traits<_Elem>, allocator<_Elem> >
		_Mystr;

	static size_t _Getcat(const locale::facet **_Ppf = 0,
		const locale *_Ploc = 0)
		{	// return locale category mask and construct standard facet
		if (_Ppf != 0 && *_Ppf == 0)
#if defined(__ghs) && !_HAS_EXCEPTIONS
			*_Ppf = (num_put<_Elem, _OutIt> *)_CHECK_LIB_ALLOC(
				new num_put<_Elem, _OutIt>(
				_Locinfo(_Ploc->c_str())));
#else  /* defined(__ghs) && !_HAS_EXCEPTIONS */
			*_Ppf = new num_put<_Elem, _OutIt>(
				_Locinfo(_Ploc->c_str()));
#endif /* defined(__ghs) && !_HAS_EXCEPTIONS */
		return (_X_NUMERIC);
		}

	static locale::id id;	// unique facet id

protected:
#ifdef __ghs
	__noinline
#endif /* __ghs */
	_VIRTUAL ~num_put() _NOEXCEPT
#if defined(__ghs) && defined(__ghs_shared_object_support)
				;
#else /* !(__ghs && defined(__ghs_shared_object_support)) */
		{	// destroy the object
		}
#endif /* !(__ghs && defined(__ghs_shared_object_support)) */

	void _Init(const _Locinfo&)
		{	// initialize from _Locinfo object
		}

public:
	explicit num_put(size_t _Refs = 0)
		: locale::facet(_Refs)
		{	// construct from current locale
		_BEGIN_LOCINFO(_Lobj)
			_Init(_Lobj);
		_END_LOCINFO()
		}

	num_put(const _Locinfo& _Lobj, size_t _Refs = 0)
		: locale::facet(_Refs)
		{	// construct from specified locale
		_Init(_Lobj);
		}

	typedef _Elem char_type;
	typedef _OutIt iter_type;

	_OutIt put(_OutIt _Dest,
		ios_base& _Iosbase, _Elem _Fill, bool _Val) const
		{	// put formatted bool to _Dest
		return (do_put(_Dest, _Iosbase, _Fill, _Val));
		}

	_OutIt put(_OutIt _Dest,
		ios_base& _Iosbase, _Elem _Fill, long _Val) const
		{	// put formatted long to _Dest
		return (do_put(_Dest, _Iosbase, _Fill, _Val));
		}

	_OutIt put(_OutIt _Dest,
		ios_base& _Iosbase, _Elem _Fill, unsigned long _Val) const
		{	// put formatted unsigned long to _Dest
		return (do_put(_Dest, _Iosbase, _Fill, _Val));
		}

 #ifdef _LONGLONG
	_OutIt put(_OutIt _Dest,
		ios_base& _Iosbase, _Elem _Fill, _LONGLONG _Val) const
		{	// put formatted long long to _Dest
		return (do_put(_Dest, _Iosbase, _Fill, _Val));
		}

	_OutIt put(_OutIt _Dest,
		ios_base& _Iosbase, _Elem _Fill, _ULONGLONG _Val) const
		{	// put formatted unsigned long long to _Dest
		return (do_put(_Dest, _Iosbase, _Fill, _Val));
		}
 #endif /* _LONGLONG */

#if !(defined(__ghs) || defined(__SC3__)) || !defined(__NoFloat)
	_OutIt put(_OutIt _Dest,
		ios_base& _Iosbase, _Elem _Fill, double _Val) const
		{	// put formatted double to _Dest
		return (do_put(_Dest, _Iosbase, _Fill, _Val));
		}

	_OutIt put(_OutIt _Dest,
		ios_base& _Iosbase, _Elem _Fill, long double _Val) const
		{	// put formatted long double to _Dest
		return (do_put(_Dest, _Iosbase, _Fill, _Val));
		}
#endif // !defined(__ghs) || !defined(__NoFloat)

	_OutIt put(_OutIt _Dest,
		ios_base& _Iosbase, _Elem _Fill, const void *_Val) const
		{	// put formatted void pointer to _Dest
		return (do_put(_Dest, _Iosbase, _Fill, _Val));
		}

protected:
#if defined(__ghs)
	__noinline
#endif /* __ghs */
	_VIRTUAL _OutIt do_put(_OutIt _Dest,
		ios_base& _Iosbase, _Elem _Fill, bool _Val) const
		{	// put formatted bool to _Dest
		_DEBUG_POINTER(_Dest);
		if (!(_Iosbase.flags() & ios_base::boolalpha))
			return (do_put(_Dest, _Iosbase, _Fill, (long)_Val));
		else
			{	// put "false" or "true"
			const _Mypunct& _Punct_fac = use_facet< _Mypunct >(_Iosbase.getloc());
			_Mystr _Str;
			if (_Val)
				_Str.assign(_Punct_fac.truename());
			else
				_Str.assign(_Punct_fac.falsename());

			size_t _Fillcount = _Iosbase.width() <= 0
				|| (size_t)_Iosbase.width() <= _Str.size()
					? 0 : (size_t)_Iosbase.width() - _Str.size();

			if ((_Iosbase.flags() & ios_base::adjustfield) != ios_base::left)
				{	// put leading fill
				_Dest = _Rep(_Dest, _Fill, _Fillcount);
				_Fillcount = 0;
				}
			_Dest = _Put(_Dest, _Str.c_str(), _Str.size());	// put field
			_Iosbase.width(0);
			return (_Rep(_Dest, _Fill, _Fillcount));	// put trailing fill
			}
		}

#if defined(__ghs)
	__noinline
#endif /* __ghs */
	_VIRTUAL _OutIt do_put(_OutIt _Dest,
		ios_base& _Iosbase, _Elem _Fill, long _Val) const
		{	// put formatted long to _Dest
		char _Buf[2 * _MAX_INT_DIG], _Fmt[6];
		return (_Iput(_Dest, _Iosbase, _Fill, _Buf,
			_CSTD sprintf(_Buf, _Ifmt(_Fmt, "ld",
				_Iosbase.flags()), _Val)));
		}

#if defined(__ghs)
	__noinline
#endif /* __ghs */
	_VIRTUAL _OutIt do_put(_OutIt _Dest,
		ios_base& _Iosbase, _Elem _Fill, unsigned long _Val) const
		{	// put formatted unsigned long to _Dest
		char _Buf[2 * _MAX_INT_DIG], _Fmt[6];
		return (_Iput(_Dest, _Iosbase, _Fill, _Buf,
			_CSTD sprintf(_Buf, _Ifmt(_Fmt, "lu",
				_Iosbase.flags()), _Val)));
		}

 #ifdef _LONGLONG
#if defined(__ghs)
	__noinline
#endif /* __ghs */
	_VIRTUAL _OutIt do_put(_OutIt _Dest,
		ios_base& _Iosbase, _Elem _Fill, _LONGLONG _Val) const
		{	// put formatted long long to _Dest
		char _Buf[2 * _MAX_INT_DIG], _Fmt[8];
		return (_Iput(_Dest, _Iosbase, _Fill, _Buf,
			_CSTD sprintf(_Buf, _Ifmt(_Fmt, "Ld",
				_Iosbase.flags()), _Val)));
		}

#if defined(__ghs)
	__noinline
#endif /* __ghs */
	_VIRTUAL _OutIt do_put(_OutIt _Dest,
		ios_base& _Iosbase, _Elem _Fill, _ULONGLONG _Val) const
		{	// put formatted unsigned long long to _Dest
		char _Buf[2 * _MAX_INT_DIG], _Fmt[8];
		return (_Iput(_Dest, _Iosbase, _Fill, _Buf,
			_CSTD sprintf(_Buf, _Ifmt(_Fmt, "Lu",
				_Iosbase.flags()), _Val)));
		}
 #else
	/* If we do not have 'long long' support, we still need to preserve
	   the number and order of virtual functions. */
	struct __dummy_type1{};
	struct __dummy_type2{};
	_VIRTUAL void do_put(__dummy_type1) { }
	_VIRTUAL void do_put(__dummy_type2) { }
 #endif /* _LONGLONG */

#if !((defined(__ghs) || defined(__SC3__)) && defined(__NoFloat))
#if defined(__ghs)
	__noinline
#endif /* __ghs */
	_VIRTUAL _OutIt do_put(_OutIt _Dest,
		ios_base& _Iosbase, _Elem _Fill, double _Val) const
		{	// put formatted double to _Dest
		string _Buf;
		char _Fmt[8];
		bool _Isfixed = (_Iosbase.flags() & ios_base::floatfield)
			== ios_base::fixed;
		bool _Ishex = (_Iosbase.flags() & ios_base::floatfield)
			== (ios_base::fixed | ios_base::scientific);
		streamsize _Precision = _Ishex ? -1 : _Iosbase.precision();
		size_t _Bufsize = (size_t)_Precision;
		if (_Isfixed && 1e10 < _CSTD fabs(_Val))
			{	// f or F format
			int _Ptwo;
			(void)_CSTD frexp(_Val, &_Ptwo);
			_Bufsize += _CSTD abs(_Ptwo) * 30103L / 100000L;
			}
		_Buf.resize(_Bufsize + 50);	// add fudge factor

		// PJP-P04; added int cast to _Precision
		int _Ngen = _CSTD sprintf((char *)_Buf.c_str(),
			_Ffmt(_Fmt, 0, _Iosbase.flags()), (int)_Precision, _Val);
		return (_Fput(_Dest, _Iosbase, _Fill, _Buf.c_str(), _Ngen));
		}

#if defined(__ghs)
	__noinline
#endif /* __ghs */
	_VIRTUAL _OutIt do_put(_OutIt _Dest,
		ios_base& _Iosbase, _Elem _Fill, long double _Val) const
		{	// put formatted long double to _Dest
		string _Buf;
		char _Fmt[8];
		bool _Isfixed = (_Iosbase.flags() & ios_base::floatfield)
			== ios_base::fixed;
#if defined(__ghs)
		bool _Ishex = (_Iosbase.flags() & ios_base::floatfield)
			== (ios_base::fixed | ios_base::scientific);
		streamsize _Precision = _Ishex ? -1 : _Iosbase.precision();
#else
		streamsize _Precision = _Iosbase.precision() <= 0 && !_Isfixed
			? 6 : _Iosbase.precision();	// desired precision
#endif
		size_t _Bufsize = (size_t)_Precision;
		if (_Isfixed && 1e10 < _CSTD fabsl(_Val))
			{	// f or F format
			int _Ptwo;
			(void)_CSTD frexpl(_Val, &_Ptwo);
			_Bufsize += _CSTD abs(_Ptwo) * 30103L / 100000L;
			}
		_Buf.resize(_Bufsize + 50);	// add fudge factor

 #if (defined(__ghs) || defined(__SC3__)) && (__LDBL_SIZE < 12)
/* 'long double' is sometimes implemented as 'double'.
 * On Solaris X86, the Sun libraries expect 'long double' to be 80-bits
 * wide and sprintf() will raise an exception if it is told it is getting
 * a long double ('L') but only passed a double. The solution is to never
 * tell sprintf() that it's getting a long double.
 */
		int _Ngen = _CSTD sprintf((char *)_Buf.c_str(),
			_Ffmt(_Fmt, 0, _Iosbase.flags()), (int)_Precision, _Val);
 #else
		int _Ngen = _CSTD sprintf((char *)_Buf.c_str(),
			_Ffmt(_Fmt, 'L', _Iosbase.flags()), (int)_Precision, _Val);
 #endif /* __ghs && (__LDBL_SIZE < 12) */
		return (_Fput(_Dest, _Iosbase, _Fill, _Buf.c_str(), _Ngen));
		}
#else
	/* If we do not have floating point support, we still need to preserve
	   the number and order of virtual functions. */
	struct __dummy_type3{};
	struct __dummy_type4{};
	_VIRTUAL _OutIt do_put(__dummy_type3) { };
	_VIRTUAL _OutIt do_put(__dummy_type4) { };
#endif /* !(__ghs && __NoFloat) */

#if defined(__ghs)
	__noinline
#endif /* __ghs */
	_VIRTUAL _OutIt do_put(_OutIt _Dest,
		ios_base& _Iosbase, _Elem _Fill, const void *_Val) const
		{	// put formatted void pointer to _Dest
 #ifdef _LONGLONG
		char _Buf[2 * _MAX_INT_DIG], _Fmt[8];
		_ULONGLONG _Off = (_ULONGLONG)((char *)_Val - (char *)0);
		if (sizeof (void *) == sizeof (unsigned long))
			_Off = (unsigned long)_Off;
#if defined(__ghs)
		else if (sizeof (void *) == sizeof (unsigned int))
			_Off = (unsigned int)_Off;
#endif
		return (_Iput(_Dest, _Iosbase, _Fill, _Buf,
			_CSTD sprintf(_Buf, _Ifmt(_Fmt, "Lu",
				ios_base::hex), _Off)));

 #else /* _LONGLONG */
		char _Buf[2 * _MAX_INT_DIG], _Fmt[6];
		unsigned long _Off = (unsigned long)((char *)_Val - (char *)0);
		return (_Iput(_Dest, _Iosbase, _Fill, _Buf,
			_CSTD sprintf(_Buf, _Ifmt(_Fmt, "lu",
				ios_base::hex), _Off)));
 #endif /* _LONGLONG */
		}

private:
#if defined(__ghs)
	__noinline
#endif /* __ghs */
	char *_Ffmt(char *_Fmt,
		char _Spec, ios_base::fmtflags _Flags) const
		{	// generate sprintf format for floating-point
		char *_Ptr = _Fmt;
		*_Ptr++ = '%';

		if (_Flags & ios_base::showpos)
			*_Ptr++ = '+';
		if (_Flags & ios_base::showpoint)
			*_Ptr++ = '#';
		*_Ptr++ = '.';
		*_Ptr++ = '*';	// for precision argument
		if (_Spec != '\0')
			*_Ptr++ = _Spec;	// 'L' qualifier for long double only

		ios_base::fmtflags _Ffl = _Flags & ios_base::floatfield;
		if (_Flags & ios_base::uppercase)
			*_Ptr++ = _Ffl == ios_base::fixed ? 'f'
				: _Ffl == ios_base::hexfloat ? 'A'	// added with TR1
				: _Ffl == ios_base::scientific ? 'E' : 'G';	// specifier
		else
			*_Ptr++ = _Ffl == ios_base::fixed ? 'f'
				: _Ffl == ios_base::hexfloat ? 'a'	// added with TR1
				: _Ffl == ios_base::scientific ? 'e' : 'g';	// specifier

		*_Ptr = '\0';
		return (_Fmt);
		}

#if defined(__ghs)
	__noinline
#endif /* __ghs */
	_OutIt _Fput(_OutIt _Dest,
		ios_base& _Iosbase, _Elem _Fill, const char *_Buf,
			size_t _Count) const
		{	// put formatted floating-point to _Dest
		_DEBUG_POINTER(_Dest);
#if defined(__GHS_FASTER)
		size_t _Prefix = 0 < _Count && ((*_Buf + 2)|2) == '-'+2 ? 1 : 0;
#else
		size_t _Prefix = 0 < _Count && (*_Buf == '+' || *_Buf == '-')
			? 1 : 0;
#endif
		bool _Isnan_inf = _Buf[_Prefix] == 'i' || _Buf[_Prefix] == 'I'
			|| _Buf[_Prefix] == 'n' || _Buf[_Prefix] == 'N';
		const char *_Exps;
		if ((_Iosbase.flags() & ios_base::floatfield) != ios_base::hexfloat)
			_Exps = "eE";
		else
			{	// correct for hexadecimal floating-point
			_Exps = "pP";
			if (_Prefix + 2 <= _Count && _Buf[_Prefix] == '0'
				&& (_Buf[_Prefix + 1] == 'x' || _Buf[_Prefix + 1] == 'X'))
				_Prefix += 2;
			}
		const size_t _Eoff =
			_CSTD strcspn(&_Buf[0], _Exps);	// find exponent
		char _Dp[2] = {"."};
#if defined(__ghs) || defined(__SC3__)
		_Dp[0] = localeconv()->decimal_point[0];
#else
		_Dp[0] = _CSTD localeconv()->decimal_point[0];
#endif
		const size_t _Poff =
			_CSTD strcspn(&_Buf[0], &_Dp[0]);	// find decimal point

		const ctype<_Elem>& _Ctype_fac =
			use_facet< ctype<_Elem> >(_Iosbase.getloc());
		_Mystr _Groupstring(_Count, _Elem(0));	// reserve space
		_Ctype_fac.widen(&_Buf[0], &_Buf[_Count], &_Groupstring[0]);

		const _Mypunct& _Punct_fac = use_facet< _Mypunct >(_Iosbase.getloc());
		const string _Grouping = _Punct_fac.grouping();
		const _Elem _Kseparator = _Punct_fac.thousands_sep();

		if (_Poff != _Count)
			_Groupstring[_Poff] = _Punct_fac.decimal_point();

		size_t _Off = _Poff == _Count ? _Eoff : _Poff;
		const char *_Pg = &_Grouping[0];
		while (*_Pg != CHAR_MAX && '\0' < *_Pg
			&& (size_t)*_Pg < _Off - _Prefix
			&& !_Isnan_inf)
			{	// add thousands separator
			_Groupstring.insert(_Off -= *_Pg, (size_t)1, _Kseparator);
			if ('\0' < _Pg[1])
				++_Pg;	// not last group, advance
			}

		_Count = _Groupstring.size();
		size_t _Fillcount = _Iosbase.width() <= 0
			|| (size_t)_Iosbase.width() <= _Count
				? 0 : (size_t)_Iosbase.width() - _Count;

		ios_base::fmtflags _Adjustfield =
			_Iosbase.flags() & ios_base::adjustfield;
		if (_Adjustfield != ios_base::left
			&& _Adjustfield != ios_base::internal)
			{	// put leading fill
			_Dest = _Rep(_Dest, _Fill, _Fillcount);
			_Fillcount = 0;
			_Dest = _Put(_Dest, &_Groupstring[0], _Prefix);
			}
		else if (_Adjustfield == ios_base::internal)
			{	// put internal fill
			_Dest = _Put(_Dest, &_Groupstring[0], _Prefix);
			_Dest = _Rep(_Dest, _Fill, _Fillcount);
			_Fillcount = 0;
			}
		else
			_Dest = _Put(_Dest, &_Groupstring[0], _Prefix);

		_Dest = _Put(_Dest, &_Groupstring[_Prefix], _Count - _Prefix);
		_Iosbase.width(0);
		return (_Rep(_Dest, _Fill, _Fillcount));	// put trailing fill
		}

#if defined(__ghs)
	__noinline
#endif /* __ghs */
	char *_Ifmt(char *_Fmt,
		const char *_Spec, ios_base::fmtflags _Flags) const
		{	// generate sprintf format for integer
		char *_Ptr = _Fmt;
		*_Ptr++ = '%';

		if (_Flags & ios_base::showpos)
			*_Ptr++ = '+';
		if (_Flags & ios_base::showbase)
			*_Ptr++ = '#';
		if (_Spec[0] != 'L')
			*_Ptr++ = _Spec[0];	// qualifier
		else

 #if _HAS_DINKUM_CLIB
			{	/* change L to ll */
			*_Ptr++ = 'l';
			*_Ptr++ = 'l';
			}

 #else /* _HAS_DINKUM_CLIB */
#if !defined(__windows)
			{	/* change L to ll */
			*_Ptr++ = 'l';
			*_Ptr++ = 'l';
			}
#else
			{	/* change L to I64 */
			*_Ptr++ = 'I';
			*_Ptr++ = '6';
			*_Ptr++ = '4';
			}
#endif
 #endif /* _HAS_DINKUM_CLIB */

		ios_base::fmtflags _Basefield = _Flags & ios_base::basefield;
		*_Ptr++ = _Basefield == ios_base::oct ? 'o'
			: _Basefield != ios_base::hex ? _Spec[1]	// 'd' or 'u'
			: _Flags & ios_base::uppercase ? 'X' : 'x';
		*_Ptr = '\0';
		return (_Fmt);
		}

#if defined(__ghs)
	__noinline
#endif /* __ghs */
	_OutIt _Iput(_OutIt _Dest,
		ios_base& _Iosbase, _Elem _Fill, char *_Buf, size_t _Count) const
		{	// put formatted integer to _Dest
		_DEBUG_POINTER(_Dest);
		size_t _Prefix = 0 < _Count && (*_Buf == '+' || *_Buf == '-')
			? 1 : 0;
		if ((_Iosbase.flags() & ios_base::basefield) == ios_base::hex
			&& _Prefix + 2 <= _Count && _Buf[_Prefix] == '0'
			&& (_Buf[_Prefix + 1] == 'x' || _Buf[_Prefix + 1] == 'X'))
			_Prefix += 2;

		const ctype<_Elem>& _Ctype_fac =
			use_facet< ctype<_Elem> >(_Iosbase.getloc());
		_Mystr _Groupstring(_Count, _Elem(0));	// reserve space
		_Ctype_fac.widen(&_Buf[0], &_Buf[_Count], &_Groupstring[0]);

		const _Mypunct& _Punct_fac = use_facet< _Mypunct >(_Iosbase.getloc());
		const string _Grouping = _Punct_fac.grouping();
		const char *_Pg = &_Grouping[0];
		if (*_Pg != CHAR_MAX && '\0' < *_Pg)
			{	// grouping specified, add thousands separators
			const _Elem _Kseparator = _Punct_fac.thousands_sep();
			while (*_Pg != CHAR_MAX && '\0' < *_Pg
				&& (size_t)*_Pg < _Count - _Prefix)
				{	// insert thousands separator
				_Count -= *_Pg;
				_Groupstring.insert(_Count, 1, _Kseparator);
				if ('\0' < _Pg[1])
					++_Pg;	// not last group, advance
				}
			}

		_Count = _Groupstring.size();
		size_t _Fillcount = _Iosbase.width() <= 0
			|| (size_t)_Iosbase.width() <= _Count
				? 0 : (size_t)_Iosbase.width() - _Count;

		ios_base::fmtflags _Adjustfield =
			_Iosbase.flags() & ios_base::adjustfield;
		if (_Adjustfield != ios_base::left
			&& _Adjustfield != ios_base::internal)
			{	// put leading fill
			_Dest = _Rep(_Dest, _Fill, _Fillcount);
			_Fillcount = 0;
			_Dest = _Put(_Dest, &_Groupstring[0], _Prefix);
			}
		else if (_Adjustfield == ios_base::internal)
			{	// put internal fill
			_Dest = _Put(_Dest, &_Groupstring[0], _Prefix);
			_Dest = _Rep(_Dest, _Fill, _Fillcount);
			_Fillcount = 0;
			}
		else
			_Dest = _Put(_Dest, &_Groupstring[0], _Prefix);

		_Dest = _Put(_Dest, &_Groupstring[_Prefix], _Count - _Prefix);
		_Iosbase.width(0);
		return (_Rep(_Dest, _Fill, _Fillcount));	// put trailing fill
		}

#if defined(__ghs)
	__noinline
#endif /* __ghs */
	_OutIt _Put(_OutIt _Dest,
		const _Elem *_Ptr, size_t _Count) const
		{	// put [_Ptr, _Ptr + _Count) to _Dest
#if defined(__ghs)
		for (; 0 < _Count; --_Count, ((void)++_Dest), ++_Ptr)
#else
		for (; 0 < _Count; --_Count, ++_Dest, ++_Ptr)
#endif /* defined(__ghs) */
			*_Dest = *_Ptr;
		return (_Dest);
		}

#if defined(__ghs)
	__noinline
#endif /* __ghs */
	_OutIt _Rep(_OutIt _Dest,
		_Elem _Ch, size_t _Count) const
		{	// put _Count * _Ch to _Dest
		for (; 0 < _Count; --_Count, ++_Dest)
			*_Dest = _Ch;
		return (_Dest);
		}
	};

#if defined(__ghs) && defined(__ghs_shared_object_support)
template<class _Elem,
	class _OutIt>
	num_put<_Elem, _OutIt>::~num_put() _NOEXCEPT
		{	// destroy the object
		}
#endif /* __ghs && defined(__ghs_shared_object_support) */

		// STATIC num_put::id OBJECT
template<class _Elem,
	class _OutIt>
	locale::id num_put<_Elem, _OutIt>::id;
_STD_END

 #if defined(__ghs)
  #if defined(__ghs_max_pack_value)
   #pragma pack(pop)
  #endif /* defined(__ghs_max_pack_value) */
  #pragma ghs enddata
  #pragma ghs end_cxx_lib_header
 #endif /* defined(__ghs) */

#endif /* _XLOCNUM_ */

/*
 * Copyright (c) by P.J. Plauger. All rights reserved.
 * Consult your license regarding permissions and restrictions.
V8.03b/17:0063 */
