master
  1/****************************************************************
  2
  3The author of this software is David M. Gay.
  4
  5Copyright (C) 1998, 2000 by Lucent Technologies
  6All Rights Reserved
  7
  8Permission to use, copy, modify, and distribute this software and
  9its documentation for any purpose and without fee is hereby
 10granted, provided that the above copyright notice appear in all
 11copies and that both that the copyright notice and this
 12permission notice and warranty disclaimer appear in supporting
 13documentation, and that the name of Lucent or any of its entities
 14not be used in advertising or publicity pertaining to
 15distribution of the software without specific, written prior
 16permission.
 17
 18LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
 19INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
 20IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
 21SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 22WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
 23IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
 24ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
 25THIS SOFTWARE.
 26
 27****************************************************************/
 28
 29/* Please send bug reports to David M. Gay (dmg at acm dot org,
 30 * with " at " changed at "@" and " dot " changed to ".").	*/
 31
 32#include "gdtoaimp.h"
 33
 34 extern UShort NanDflt_ldus_D2A[5];
 35
 36#undef _0
 37#undef _1
 38
 39/* one or the other of IEEE_MC68k or IEEE_8087 should be #defined */
 40
 41#ifdef IEEE_MC68k
 42#define _0 0
 43#define _1 1
 44#define _2 2
 45#define _3 3
 46#define _4 4
 47#endif
 48#ifdef IEEE_8087
 49#define _0 4
 50#define _1 3
 51#define _2 2
 52#define _3 1
 53#define _4 0
 54#endif
 55
 56#if __SIZEOF_LONG_DOUBLE__ == __SIZEOF_DOUBLE__
 57/* For ARM, where long double == double, provide the long double function as
 58 * an alias for __strtod. Do this in a separate object file from other
 59 * functions, to avoid linker conflicts if object files import both 'strtold'
 60 * from libucrt*.a and the object file providing '__strtod'. */
 61long double __cdecl
 62strtold (const char * __restrict__ src, char ** __restrict__ endptr)
 63{
 64  return __mingw_strtod(src, endptr);
 65}
 66
 67/* This is specific to the x86 80 bit long doubles. */
 68#elif defined(_AMD64_) || defined(__x86_64__) || \
 69  defined(_X86_) || defined(__i386__)
 70
 71typedef union lD {
 72	UShort L[5];
 73	long double D;
 74} lD;
 75
 76static int __strtopx (const char *s, char **sp, lD *V)
 77{
 78	static FPI fpi0 = { 64, 1-16383-64+1, 32766 - 16383 - 64 + 1, 1, SI,
 79			   Int_max /*unused*/ };
 80	ULong bits[2];
 81	Long expo;
 82	int k;
 83	UShort *L = & (V->L[0]);
 84#ifdef Honor_FLT_ROUNDS
 85#include "gdtoa_fltrnds.h"
 86#else
 87#define fpi &fpi0
 88#endif
 89	V->D = 0.0L;
 90
 91	k = __strtodg(s, sp, fpi, &expo, bits);
 92	switch(k & STRTOG_Retmask) {
 93	  case STRTOG_NoNumber:
 94	  case STRTOG_Zero:
 95		L[0] = L[1] = L[2] = L[3] = L[4] = 0;
 96		break;
 97
 98	  case STRTOG_Denormal:
 99		L[_0] = 0;
100		goto normal_bits;
101
102	  case STRTOG_Normal:
103	  case STRTOG_NaNbits:
104		L[_0] = expo + 0x3fff + 63;
105 normal_bits:
106		L[_4] = (UShort)bits[0];
107		L[_3] = (UShort)(bits[0] >> 16);
108		L[_2] = (UShort)bits[1];
109		L[_1] = (UShort)(bits[1] >> 16);
110		break;
111
112	  case STRTOG_Infinite:
113		L[_0] = 0x7fff;
114		L[_1] = 0x8000;
115		L[_2] = L[_3] = L[_4] = 0;
116		break;
117
118	  case STRTOG_NaN:
119		L[_4] = NanDflt_ldus_D2A[0];
120		L[_3] = NanDflt_ldus_D2A[1];
121		L[_2] = NanDflt_ldus_D2A[2];
122		L[_1] = NanDflt_ldus_D2A[3];
123		L[_0] = NanDflt_ldus_D2A[4];
124	}
125	if (k & STRTOG_Neg)
126		L[_0] |= 0x8000;
127	return k;
128}
129
130long double __cdecl
131__strtold (const char * __restrict__ src, char ** __restrict__ endptr)
132{
133	lD ret;
134	ret.D = 0.0L;
135	__strtopx(src, endptr,  &ret);
136	return ret.D;
137}
138
139long double __cdecl
140__mingw_strtold (const char * __restrict__ src, char ** __restrict__ endptr)
141  __attribute__((alias("__strtold")));
142
143long double __cdecl
144strtold (const char * __restrict__ src, char ** __restrict__ endptr)
145  __attribute__((alias("__strtold")));
146
147#endif