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 "xlocale_private.h" 33 34#include "gdtoaimp.h" 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 int 57#ifdef KR_headers 58strtopx(s, sp, V, loc) CONST char *s; char **sp; void *V; locale_t loc; 59#else 60strtopx(CONST char *s, char **sp, void *V, locale_t loc) 61#endif 62{ 63 static FPI fpi0 = { 64, 1-16383-64+1, 32766 - 16383 - 64 + 1, 1, SI }; 64 ULong bits[2]; 65 Long exp; 66 int k; 67 UShort *L = (UShort*)V; 68#ifdef Honor_FLT_ROUNDS 69#include "gdtoa_fltrnds.h" 70#else 71#define fpi &fpi0 72#endif 73 74 k = strtodg(s, sp, fpi, &exp, bits, loc); 75 switch(k & STRTOG_Retmask) { 76 case STRTOG_NoNumber: 77 L[0] = L[1] = L[2] = L[3] = L[4] = 0; 78 return k; // avoid setting sign 79 80 case STRTOG_Zero: 81 L[0] = L[1] = L[2] = L[3] = L[4] = 0; 82 break; 83 84 case STRTOG_Denormal: 85 L[_0] = 0; 86 goto normal_bits; 87 88 case STRTOG_Normal: 89 case STRTOG_NaNbits: 90 L[_0] = exp + 0x3fff + 63; 91 normal_bits: 92 L[_4] = (UShort)bits[0]; 93 L[_3] = (UShort)(bits[0] >> 16); 94 L[_2] = (UShort)bits[1]; 95 L[_1] = (UShort)(bits[1] >> 16); 96 break; 97 98 case STRTOG_Infinite: 99 L[_0] = 0x7fff; 100 L[_1] = 0x8000; 101 L[_2] = L[_3] = L[_4] = 0; 102 break; 103 104 case STRTOG_NaN: 105 L[0] = ldus_QNAN0; 106 L[1] = ldus_QNAN1; 107 L[2] = ldus_QNAN2; 108 L[3] = ldus_QNAN3; 109 L[4] = ldus_QNAN4; 110 } 111 if (k & STRTOG_Neg) 112 L[_0] |= 0x8000; 113 return k; 114 } 115