1*61e56760Schristos /* $NetBSD: strtorxL.c,v 1.4 2011/03/20 23:15:35 christos Exp $ */
27684d5e0Skleink
37684d5e0Skleink /****************************************************************
47684d5e0Skleink
57684d5e0Skleink The author of this software is David M. Gay.
67684d5e0Skleink
77684d5e0Skleink Copyright (C) 1998, 2000 by Lucent Technologies
87684d5e0Skleink All Rights Reserved
97684d5e0Skleink
107684d5e0Skleink Permission to use, copy, modify, and distribute this software and
117684d5e0Skleink its documentation for any purpose and without fee is hereby
127684d5e0Skleink granted, provided that the above copyright notice appear in all
137684d5e0Skleink copies and that both that the copyright notice and this
147684d5e0Skleink permission notice and warranty disclaimer appear in supporting
157684d5e0Skleink documentation, and that the name of Lucent or any of its entities
167684d5e0Skleink not be used in advertising or publicity pertaining to
177684d5e0Skleink distribution of the software without specific, written prior
187684d5e0Skleink permission.
197684d5e0Skleink
207684d5e0Skleink LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
217684d5e0Skleink INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
227684d5e0Skleink IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
237684d5e0Skleink SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
247684d5e0Skleink WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
257684d5e0Skleink IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
267684d5e0Skleink ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
277684d5e0Skleink THIS SOFTWARE.
287684d5e0Skleink
297684d5e0Skleink ****************************************************************/
307684d5e0Skleink
317684d5e0Skleink /* Please send bug reports to David M. Gay (dmg at acm dot org,
327684d5e0Skleink * with " at " changed at "@" and " dot " changed to "."). */
337684d5e0Skleink
347684d5e0Skleink #include "gdtoaimp.h"
357684d5e0Skleink
367684d5e0Skleink #undef _0
377684d5e0Skleink #undef _1
387684d5e0Skleink
39ac898a26Skleink /* one or the other of IEEE_BIG_ENDIAN or IEEE_LITTLE_ENDIAN should be #defined */
407684d5e0Skleink
41ac898a26Skleink #ifdef IEEE_BIG_ENDIAN
427684d5e0Skleink #define _0 0
437684d5e0Skleink #define _1 1
447684d5e0Skleink #define _2 2
457684d5e0Skleink #endif
46ac898a26Skleink #ifdef IEEE_LITTLE_ENDIAN
477684d5e0Skleink #define _0 2
487684d5e0Skleink #define _1 1
497684d5e0Skleink #define _2 0
507684d5e0Skleink #endif
517684d5e0Skleink
527684d5e0Skleink void
537684d5e0Skleink #ifdef KR_headers
ULtoxL(L,bits,expt,k)54*61e56760Schristos ULtoxL(L, bits, expt, k) ULong *L; ULong *bits; Long expt; int k;
557684d5e0Skleink #else
56*61e56760Schristos ULtoxL(ULong *L, ULong *bits, Long expt, int k)
577684d5e0Skleink #endif
587684d5e0Skleink {
597684d5e0Skleink switch(k & STRTOG_Retmask) {
607684d5e0Skleink case STRTOG_NoNumber:
617684d5e0Skleink case STRTOG_Zero:
627684d5e0Skleink L[0] = L[1] = L[2] = 0;
637684d5e0Skleink break;
647684d5e0Skleink
657684d5e0Skleink case STRTOG_Normal:
667684d5e0Skleink case STRTOG_Denormal:
677684d5e0Skleink case STRTOG_NaNbits:
68*61e56760Schristos L[_0] = (expt + 0x3fff + 63) << 16;
697684d5e0Skleink L[_1] = bits[1];
707684d5e0Skleink L[_2] = bits[0];
717684d5e0Skleink break;
727684d5e0Skleink
737684d5e0Skleink case STRTOG_Infinite:
747684d5e0Skleink L[_0] = 0x7fff << 16;
75*61e56760Schristos L[_1] = 0x80000000;
76*61e56760Schristos L[_2] = 0;
777684d5e0Skleink break;
787684d5e0Skleink
797684d5e0Skleink case STRTOG_NaN:
807684d5e0Skleink L[0] = ld_QNAN0;
817684d5e0Skleink L[1] = ld_QNAN1;
827684d5e0Skleink L[2] = ld_QNAN2;
837684d5e0Skleink }
847684d5e0Skleink if (k & STRTOG_Neg)
857684d5e0Skleink L[_0] |= 0x80000000L;
867684d5e0Skleink }
877684d5e0Skleink
887684d5e0Skleink int
897684d5e0Skleink #ifdef KR_headers
strtorxL(s,sp,rounding,L)907684d5e0Skleink strtorxL(s, sp, rounding, L) CONST char *s; char **sp; int rounding; void *L;
917684d5e0Skleink #else
927684d5e0Skleink strtorxL(CONST char *s, char **sp, int rounding, void *L)
937684d5e0Skleink #endif
947684d5e0Skleink {
95*61e56760Schristos static CONST FPI fpi0 = { 64, 1-16383-64+1, 32766 - 16383 - 64 + 1, 1, SI };
96*61e56760Schristos CONST FPI *fpi;
97*61e56760Schristos FPI fpi1;
987684d5e0Skleink ULong bits[2];
99*61e56760Schristos Long expt;
1007684d5e0Skleink int k;
1017684d5e0Skleink
1027684d5e0Skleink fpi = &fpi0;
1037684d5e0Skleink if (rounding != FPI_Round_near) {
1047684d5e0Skleink fpi1 = fpi0;
1057684d5e0Skleink fpi1.rounding = rounding;
1067684d5e0Skleink fpi = &fpi1;
1077684d5e0Skleink }
108*61e56760Schristos k = strtodg(s, sp, fpi, &expt, bits);
109ab625449Schristos if (k == STRTOG_NoMemory)
110ab625449Schristos return k;
111*61e56760Schristos ULtoxL((ULong*)L, bits, expt, k);
1127684d5e0Skleink return k;
1137684d5e0Skleink }
114