11.6Sjoerg/* $NetBSD: strtopxL.c,v 1.6 2013/04/18 21:54:11 joerg Exp $ */
21.1Skleink
31.1Skleink/****************************************************************
41.1Skleink
51.1SkleinkThe author of this software is David M. Gay.
61.1Skleink
71.1SkleinkCopyright (C) 1998, 2000 by Lucent Technologies
81.1SkleinkAll Rights Reserved
91.1Skleink
101.1SkleinkPermission to use, copy, modify, and distribute this software and
111.1Skleinkits documentation for any purpose and without fee is hereby
121.1Skleinkgranted, provided that the above copyright notice appear in all
131.1Skleinkcopies and that both that the copyright notice and this
141.1Skleinkpermission notice and warranty disclaimer appear in supporting
151.1Skleinkdocumentation, and that the name of Lucent or any of its entities
161.1Skleinknot be used in advertising or publicity pertaining to
171.1Skleinkdistribution of the software without specific, written prior
181.1Skleinkpermission.
191.1Skleink
201.1SkleinkLUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
211.1SkleinkINCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
221.1SkleinkIN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
231.1SkleinkSPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
241.1SkleinkWHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
251.1SkleinkIN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
261.1SkleinkARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
271.1SkleinkTHIS SOFTWARE.
281.1Skleink
291.1Skleink****************************************************************/
301.1Skleink
311.1Skleink/* Please send bug reports to David M. Gay (dmg at acm dot org,
321.1Skleink * with " at " changed at "@" and " dot " changed to ".").	*/
331.1Skleink
341.1Skleink#include "gdtoaimp.h"
351.1Skleink
361.1Skleink#undef _0
371.1Skleink#undef _1
381.1Skleink
391.2Skleink/* one or the other of IEEE_BIG_ENDIAN or IEEE_LITTLE_ENDIAN should be #defined */
401.1Skleink
411.2Skleink#ifdef IEEE_BIG_ENDIAN
421.1Skleink#define _0 0
431.1Skleink#define _1 1
441.1Skleink#define _2 2
451.1Skleink#endif
461.2Skleink#ifdef IEEE_LITTLE_ENDIAN
471.1Skleink#define _0 2
481.1Skleink#define _1 1
491.1Skleink#define _2 0
501.1Skleink#endif
511.1Skleink
521.1Skleink int
531.6SjoergstrtopxL(CONST char *s, char **sp, void *V, locale_t loc)
541.1Skleink{
551.5Schristos	static CONST FPI fpi0 = { 64, 1-16383-64+1, 32766 - 16383 - 64 + 1, 1, SI };
561.1Skleink	ULong bits[2];
571.3Skleink	Long expt;
581.1Skleink	int k;
591.1Skleink	ULong *L = (ULong*)V;
601.5Schristos#ifdef Honor_FLT_ROUNDS
611.5Schristos#include "gdtoa_fltrnds.h"
621.5Schristos#else
631.5Schristos#define fpi &fpi0
641.5Schristos#endif
651.1Skleink
661.6Sjoerg	k = strtodg(s, sp, fpi, &expt, bits, loc);
671.4Schristos	if (k == STRTOG_NoMemory)
681.4Schristos		return k;
691.1Skleink	switch(k & STRTOG_Retmask) {
701.1Skleink	  case STRTOG_NoNumber:
711.1Skleink	  case STRTOG_Zero:
721.1Skleink		L[0] = L[1] = L[2] = 0;
731.1Skleink		break;
741.1Skleink
751.1Skleink	  case STRTOG_Normal:
761.1Skleink	  case STRTOG_Denormal:
771.1Skleink	  case STRTOG_NaNbits:
781.1Skleink		L[_2] = bits[0];
791.1Skleink		L[_1] = bits[1];
801.3Skleink		L[_0] = (expt + 0x3fff + 63) << 16;
811.1Skleink		break;
821.1Skleink
831.1Skleink	  case STRTOG_Infinite:
841.1Skleink		L[_0] = 0x7fff << 16;
851.5Schristos		L[_1] = 0x80000000;
861.5Schristos		L[_2] = 0;
871.1Skleink		break;
881.1Skleink
891.1Skleink	  case STRTOG_NaN:
901.1Skleink		L[0] = ld_QNAN0;
911.1Skleink		L[1] = ld_QNAN1;
921.1Skleink		L[2] = ld_QNAN2;
931.1Skleink	  }
941.1Skleink	if (k & STRTOG_Neg)
951.1Skleink		L[_0] |= 0x80000000L;
961.1Skleink	return k;
971.1Skleink	}
98