/****************************************************************12The author of this software is David M. Gay.34Copyright (C) 1998, 2000 by Lucent Technologies5All Rights Reserved67Permission to use, copy, modify, and distribute this software and8its documentation for any purpose and without fee is hereby9granted, provided that the above copyright notice appear in all10copies and that both that the copyright notice and this11permission notice and warranty disclaimer appear in supporting12documentation, and that the name of Lucent or any of its entities13not be used in advertising or publicity pertaining to14distribution of the software without specific, written prior15permission.1617LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,18INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.19IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY20SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES21WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER22IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,23ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF24THIS SOFTWARE.2526****************************************************************/2728/* Please send bug reports to David M. Gay (dmg at acm dot org,29* with " at " changed at "@" and " dot " changed to "."). */3031/* $FreeBSD$ */3233#include "gdtoaimp.h"3435#undef _036#undef _13738/* one or the other of IEEE_MC68k or IEEE_8087 should be #defined */3940#ifdef IEEE_MC68k41#define _0 042#define _1 143#define _2 244#define _3 345#define _4 446#endif47#ifdef IEEE_808748#define _0 449#define _1 350#define _2 251#define _3 152#define _4 053#endif5455void56#ifdef KR_headers57ULtox(L, bits, exp, k) UShort *L; ULong *bits; Long exp; int k;58#else59ULtox(UShort *L, ULong *bits, Long exp, int k)60#endif61{62switch(k & STRTOG_Retmask) {63case STRTOG_NoNumber:64case STRTOG_Zero:65L[0] = L[1] = L[2] = L[3] = L[4] = 0;66break;6768case STRTOG_Denormal:69L[_0] = 0;70goto normal_bits;7172case STRTOG_Normal:73L[_0] = exp + 0x3fff + 63;74normal_bits:75L[_4] = (UShort)bits[0];76L[_3] = (UShort)(bits[0] >> 16);77L[_2] = (UShort)bits[1];78L[_1] = (UShort)(bits[1] >> 16);79break;8081case STRTOG_NaNbits:82L[_0] = exp + 0x3fff + 63;83L[_4] = (UShort)bits[0];84L[_3] = (UShort)(bits[0] >> 16);85L[_2] = (UShort)bits[1];86L[_1] = (UShort)((bits[1] >> 16) | (3 << 14));87break;8889case STRTOG_Infinite:90L[_0] = 0x7fff;91L[_1] = 0x8000;92L[_2] = L[_3] = L[_4] = 0;93break;9495case STRTOG_NaN:96L[0] = ldus_QNAN0;97L[1] = ldus_QNAN1;98L[2] = ldus_QNAN2;99L[3] = ldus_QNAN3;100L[4] = ldus_QNAN4;101}102if (k & STRTOG_Neg)103L[_0] |= 0x8000;104}105106int107#ifdef KR_headers108strtorx_l(s, sp, rounding, L, locale) CONST char *s; char **sp; int rounding;109void *L; locale_t locale;110#else111strtorx_l(CONST char *s, char **sp, int rounding, void *L, locale_t locale)112#endif113{114static FPI fpi0 = { 64, 1-16383-64+1, 32766 - 16383 - 64 + 1, 1, SI };115FPI *fpi, fpi1;116ULong bits[2];117Long exp;118int k;119120fpi = &fpi0;121if (rounding != FPI_Round_near) {122fpi1 = fpi0;123fpi1.rounding = rounding;124fpi = &fpi1;125}126k = strtodg_l(s, sp, fpi, &exp, bits, locale);127ULtox((UShort*)L, bits, exp, k);128return k;129}130131132