strtopQ.c revision 187808
1112158Sdas/**************************************************************** 2112158Sdas 3112158SdasThe author of this software is David M. Gay. 4112158Sdas 5112158SdasCopyright (C) 1998, 2000 by Lucent Technologies 6112158SdasAll Rights Reserved 7112158Sdas 8112158SdasPermission to use, copy, modify, and distribute this software and 9112158Sdasits documentation for any purpose and without fee is hereby 10112158Sdasgranted, provided that the above copyright notice appear in all 11112158Sdascopies and that both that the copyright notice and this 12112158Sdaspermission notice and warranty disclaimer appear in supporting 13112158Sdasdocumentation, and that the name of Lucent or any of its entities 14112158Sdasnot be used in advertising or publicity pertaining to 15112158Sdasdistribution of the software without specific, written prior 16112158Sdaspermission. 17112158Sdas 18112158SdasLUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, 19112158SdasINCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. 20112158SdasIN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY 21112158SdasSPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 22112158SdasWHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER 23112158SdasIN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, 24112158SdasARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF 25112158SdasTHIS SOFTWARE. 26112158Sdas 27112158Sdas****************************************************************/ 28112158Sdas 29165743Sdas/* Please send bug reports to David M. Gay (dmg at acm dot org, 30165743Sdas * with " at " changed at "@" and " dot " changed to "."). */ 31112158Sdas 32112158Sdas#include "gdtoaimp.h" 33112158Sdas 34112158Sdas#undef _0 35112158Sdas#undef _1 36112158Sdas 37112158Sdas/* one or the other of IEEE_MC68k or IEEE_8087 should be #defined */ 38112158Sdas 39112158Sdas#ifdef IEEE_MC68k 40112158Sdas#define _0 0 41112158Sdas#define _1 1 42112158Sdas#define _2 2 43112158Sdas#define _3 3 44112158Sdas#endif 45112158Sdas#ifdef IEEE_8087 46112158Sdas#define _0 3 47112158Sdas#define _1 2 48112158Sdas#define _2 1 49112158Sdas#define _3 0 50112158Sdas#endif 51112158Sdas 52112158Sdas int 53112158Sdas#ifdef KR_headers 54112158SdasstrtopQ(s, sp, V) CONST char *s; char **sp; void *V; 55112158Sdas#else 56112158SdasstrtopQ(CONST char *s, char **sp, void *V) 57112158Sdas#endif 58112158Sdas{ 59187808Sdas static FPI fpi0 = { 113, 1-16383-113+1, 32766 - 16383 - 113 + 1, 1, SI }; 60112158Sdas ULong bits[4]; 61112158Sdas Long exp; 62112158Sdas int k; 63112158Sdas ULong *L = (ULong*)V; 64187808Sdas#ifdef Honor_FLT_ROUNDS 65187808Sdas#include "gdtoa_fltrnds.h" 66187808Sdas#else 67187808Sdas#define fpi &fpi0 68187808Sdas#endif 69112158Sdas 70187808Sdas k = strtodg(s, sp, fpi, &exp, bits); 71112158Sdas switch(k & STRTOG_Retmask) { 72112158Sdas case STRTOG_NoNumber: 73112158Sdas case STRTOG_Zero: 74112158Sdas L[0] = L[1] = L[2] = L[3] = 0; 75112158Sdas break; 76112158Sdas 77112158Sdas case STRTOG_Normal: 78112158Sdas case STRTOG_NaNbits: 79112158Sdas L[_3] = bits[0]; 80112158Sdas L[_2] = bits[1]; 81112158Sdas L[_1] = bits[2]; 82112158Sdas L[_0] = (bits[3] & ~0x10000) | ((exp + 0x3fff + 112) << 16); 83112158Sdas break; 84112158Sdas 85112158Sdas case STRTOG_Denormal: 86112158Sdas L[_3] = bits[0]; 87112158Sdas L[_2] = bits[1]; 88112158Sdas L[_1] = bits[2]; 89112158Sdas L[_0] = bits[3]; 90112158Sdas break; 91112158Sdas 92112158Sdas case STRTOG_Infinite: 93112158Sdas L[_0] = 0x7fff0000; 94112158Sdas L[_1] = L[_2] = L[_3] = 0; 95112158Sdas break; 96112158Sdas 97112158Sdas case STRTOG_NaN: 98165743Sdas L[0] = ld_QNAN0; 99165743Sdas L[1] = ld_QNAN1; 100165743Sdas L[2] = ld_QNAN2; 101165743Sdas L[3] = ld_QNAN3; 102112158Sdas } 103112158Sdas if (k & STRTOG_Neg) 104112158Sdas L[_0] |= 0x80000000L; 105112158Sdas return k; 106112158Sdas } 107