xref: /netbsd-src/lib/libc/gdtoa/strtoIQ.c (revision 9a9a41227b42868f516d4f928b32562ad0f5bc3b)
1*9a9a4122Sriastradh /* $NetBSD: strtoIQ.c,v 1.3 2019/08/01 02:27:43 riastradh Exp $ */
27684d5e0Skleink 
37684d5e0Skleink /****************************************************************
47684d5e0Skleink 
57684d5e0Skleink The author of this software is David M. Gay.
67684d5e0Skleink 
77684d5e0Skleink Copyright (C) 1998 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  int
377684d5e0Skleink #ifdef KR_headers
strtoIQ(s,sp,a,b)387684d5e0Skleink strtoIQ(s, sp, a, b) CONST char *s; char **sp; void *a; void *b;
397684d5e0Skleink #else
407684d5e0Skleink strtoIQ(CONST char *s, char **sp, void *a, void *b)
417684d5e0Skleink #endif
427684d5e0Skleink {
43*9a9a4122Sriastradh 	static CONST FPI fpi = { 113, 1-16383-113+1, 32766-16383-113+1, 1, SI };
447684d5e0Skleink 	Long exp[2];
457684d5e0Skleink 	Bigint *B[2];
467684d5e0Skleink 	int k, rv[2];
477684d5e0Skleink 	ULong *L = (ULong *)a, *M = (ULong *)b;
487684d5e0Skleink 
497684d5e0Skleink 	B[0] = Balloc(2);
50ab625449Schristos 	if (B[0] == NULL)
51ab625449Schristos 		return STRTOG_NoMemory;
527684d5e0Skleink 	B[0]->wds = 4;
537684d5e0Skleink 	k = strtoIg(s, sp, &fpi, exp, B, rv);
54ab625449Schristos 	if (k == STRTOG_NoMemory)
55ab625449Schristos 		return k;
567684d5e0Skleink 	ULtoQ(L, B[0]->x, exp[0], rv[0]);
577684d5e0Skleink 	Bfree(B[0]);
587684d5e0Skleink 	if (B[1]) {
597684d5e0Skleink 		ULtoQ(M, B[1]->x, exp[1], rv[1]);
607684d5e0Skleink 		Bfree(B[1]);
617684d5e0Skleink 		}
627684d5e0Skleink 	else {
637684d5e0Skleink 		M[0] = L[0];
647684d5e0Skleink 		M[1] = L[1];
657684d5e0Skleink 		M[2] = L[2];
667684d5e0Skleink 		M[3] = L[3];
677684d5e0Skleink 		}
687684d5e0Skleink 	return k;
697684d5e0Skleink 	}
70