strtopQ.c revision 112158
114062Swpaul/****************************************************************
214062Swpaul
314062SwpaulThe author of this software is David M. Gay.
414062Swpaul
514062SwpaulCopyright (C) 1998, 2000 by Lucent Technologies
614062SwpaulAll Rights Reserved
714062Swpaul
814062SwpaulPermission to use, copy, modify, and distribute this software and
914062Swpaulits documentation for any purpose and without fee is hereby
1014062Swpaulgranted, provided that the above copyright notice appear in all
1114062Swpaulcopies and that both that the copyright notice and this
1214062Swpaulpermission notice and warranty disclaimer appear in supporting
1314062Swpauldocumentation, and that the name of Lucent or any of its entities
1414062Swpaulnot be used in advertising or publicity pertaining to
1514062Swpauldistribution of the software without specific, written prior
1614062Swpaulpermission.
1714062Swpaul
1814062SwpaulLUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
1914062SwpaulINCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
2014062SwpaulIN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
2114062SwpaulSPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
2214062SwpaulWHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
2314062SwpaulIN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
2414062SwpaulARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
2514062SwpaulTHIS SOFTWARE.
2614062Swpaul
2714062Swpaul****************************************************************/
2814062Swpaul
2914062Swpaul/* Please send bug reports to
3014062Swpaul	David M. Gay
3150479Speter	Bell Laboratories, Room 2C-463
3214062Swpaul	600 Mountain Avenue
3314062Swpaul	Murray Hill, NJ 07974-0636
3414062Swpaul	U.S.A.
3514062Swpaul	dmg@bell-labs.com
3614062Swpaul */
3714062Swpaul
3814062Swpaul#include "gdtoaimp.h"
3914062Swpaul
4068965Sru#undef _0
4114062Swpaul#undef _1
4214062Swpaul
4314062Swpaul/* one or the other of IEEE_MC68k or IEEE_8087 should be #defined */
4414062Swpaul
4514062Swpaul#ifdef IEEE_MC68k
4614062Swpaul#define _0 0
4714062Swpaul#define _1 1
4816134Swpaul#define _2 2
4914062Swpaul#define _3 3
5014241Swpaul#endif
5114062Swpaul#ifdef IEEE_8087
5214062Swpaul#define _0 3
5314062Swpaul#define _1 2
5430377Scharnier#define _2 1
5599968Scharnier#define _3 0
5614062Swpaul#endif
5714062Swpaul
5814062Swpaul int
5914062Swpaul#ifdef KR_headers
6014062SwpaulstrtopQ(s, sp, V) CONST char *s; char **sp; void *V;
6199968Scharnier#else
6299968ScharnierstrtopQ(CONST char *s, char **sp, void *V)
6399968Scharnier#endif
6414062Swpaul{
6514062Swpaul#ifdef Sudden_Underflow
6614062Swpaul	static FPI fpi = { 113, 1-16383-113+1, 32766 - 16383 - 113 + 1, 1, 1 };
6714062Swpaul#else
6814062Swpaul	static FPI fpi = { 113, 1-16383-113+1, 32766 - 16383 - 113 + 1, 1, 0 };
6914062Swpaul#endif
7014062Swpaul	ULong bits[4];
7114062Swpaul	Long exp;
7214062Swpaul	int k;
7314062Swpaul	ULong *L = (ULong*)V;
7430377Scharnier
7599968Scharnier	k = strtodg(s, sp, &fpi, &exp, bits);
7614062Swpaul	switch(k & STRTOG_Retmask) {
7757673Ssheldonh	  case STRTOG_NoNumber:
7857673Ssheldonh	  case STRTOG_Zero:
7914062Swpaul		L[0] = L[1] = L[2] = L[3] = 0;
8014062Swpaul		break;
8114062Swpaul
8214062Swpaul	  case STRTOG_Normal:
8314062Swpaul	  case STRTOG_NaNbits:
8414062Swpaul		L[_3] = bits[0];
8557695Ssheldonh		L[_2] = bits[1];
86141846Sru		L[_1] = bits[2];
8714062Swpaul		L[_0] = (bits[3] & ~0x10000) | ((exp + 0x3fff + 112) << 16);
8857695Ssheldonh		break;
8957695Ssheldonh
9014241Swpaul	  case STRTOG_Denormal:
9114241Swpaul		L[_3] = bits[0];
9214241Swpaul		L[_2] = bits[1];
9314241Swpaul		L[_1] = bits[2];
9414241Swpaul		L[_0] = bits[3];
9514241Swpaul		break;
9614241Swpaul
9730377Scharnier	  case STRTOG_Infinite:
9899968Scharnier		L[_0] = 0x7fff0000;
9971102Sru		L[_1] = L[_2] = L[_3] = 0;
10014241Swpaul		break;
10114241Swpaul
102141851Sru	  case STRTOG_NaN:
10314062Swpaul		L[_0] = 0x7fffffff;
10414062Swpaul		L[_1] = L[_2] = L[_3] = (ULong)-1;
10514062Swpaul	  }
10614062Swpaul	if (k & STRTOG_Neg)
10714062Swpaul		L[_0] |= 0x80000000L;
10814062Swpaul	return k;
10914062Swpaul	}
11057695Ssheldonh