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 32174679Sdas/* $FreeBSD$ */ 33174679Sdas 34112158Sdas#include "gdtoaimp.h" 35112158Sdas 36112158Sdas#undef _0 37112158Sdas#undef _1 38112158Sdas 39112158Sdas/* one or the other of IEEE_MC68k or IEEE_8087 should be #defined */ 40112158Sdas 41112158Sdas#ifdef IEEE_MC68k 42112158Sdas#define _0 0 43112158Sdas#define _1 1 44112158Sdas#define _2 2 45112158Sdas#define _3 3 46112158Sdas#define _4 4 47112158Sdas#endif 48112158Sdas#ifdef IEEE_8087 49112158Sdas#define _0 4 50112158Sdas#define _1 3 51112158Sdas#define _2 2 52112158Sdas#define _3 1 53112158Sdas#define _4 0 54112158Sdas#endif 55112158Sdas 56112158Sdas void 57112158Sdas#ifdef KR_headers 58112158SdasULtox(L, bits, exp, k) UShort *L; ULong *bits; Long exp; int k; 59112158Sdas#else 60112158SdasULtox(UShort *L, ULong *bits, Long exp, int k) 61112158Sdas#endif 62112158Sdas{ 63112158Sdas switch(k & STRTOG_Retmask) { 64112158Sdas case STRTOG_NoNumber: 65112158Sdas case STRTOG_Zero: 66112158Sdas L[0] = L[1] = L[2] = L[3] = L[4] = 0; 67112158Sdas break; 68112158Sdas 69165743Sdas case STRTOG_Denormal: 70165743Sdas L[_0] = 0; 71165743Sdas goto normal_bits; 72165743Sdas 73112158Sdas case STRTOG_Normal: 74165743Sdas L[_0] = exp + 0x3fff + 63; 75165743Sdas normal_bits: 76112158Sdas L[_4] = (UShort)bits[0]; 77112158Sdas L[_3] = (UShort)(bits[0] >> 16); 78112158Sdas L[_2] = (UShort)bits[1]; 79174690Sdas L[_1] = (UShort)(bits[1] >> 16); 80174690Sdas break; 81174690Sdas 82174690Sdas case STRTOG_NaNbits: 83174690Sdas L[_0] = exp + 0x3fff + 63; 84174690Sdas L[_4] = (UShort)bits[0]; 85174690Sdas L[_3] = (UShort)(bits[0] >> 16); 86174690Sdas L[_2] = (UShort)bits[1]; 87174679Sdas L[_1] = (UShort)((bits[1] >> 16) | (3 << 14)); 88112158Sdas break; 89112158Sdas 90112158Sdas case STRTOG_Infinite: 91112158Sdas L[_0] = 0x7fff; 92219557Sdas L[_1] = 0x8000; 93219557Sdas L[_2] = L[_3] = L[_4] = 0; 94112158Sdas break; 95112158Sdas 96112158Sdas case STRTOG_NaN: 97165743Sdas L[0] = ldus_QNAN0; 98165743Sdas L[1] = ldus_QNAN1; 99165743Sdas L[2] = ldus_QNAN2; 100165743Sdas L[3] = ldus_QNAN3; 101165743Sdas L[4] = ldus_QNAN4; 102112158Sdas } 103112158Sdas if (k & STRTOG_Neg) 104112158Sdas L[_0] |= 0x8000; 105112158Sdas } 106112158Sdas 107112158Sdas int 108112158Sdas#ifdef KR_headers 109227753Stheravenstrtorx_l(s, sp, rounding, L, locale) CONST char *s; char **sp; int rounding; 110227753Stheravenvoid *L; locale_t locale; 111112158Sdas#else 112227753Stheravenstrtorx_l(CONST char *s, char **sp, int rounding, void *L, locale_t locale) 113112158Sdas#endif 114112158Sdas{ 115112158Sdas static FPI fpi0 = { 64, 1-16383-64+1, 32766 - 16383 - 64 + 1, 1, SI }; 116112158Sdas FPI *fpi, fpi1; 117112158Sdas ULong bits[2]; 118112158Sdas Long exp; 119112158Sdas int k; 120112158Sdas 121112158Sdas fpi = &fpi0; 122112158Sdas if (rounding != FPI_Round_near) { 123112158Sdas fpi1 = fpi0; 124112158Sdas fpi1.rounding = rounding; 125112158Sdas fpi = &fpi1; 126112158Sdas } 127227753Stheraven k = strtodg_l(s, sp, fpi, &exp, bits, locale); 128112158Sdas ULtox((UShort*)L, bits, exp, k); 129112158Sdas return k; 130112158Sdas } 131