xref: /freebsd/contrib/gdtoa/strtoIQ.c (revision cc36ccd13b36b705dfb09d90e8de63e49734f8d4)
1cc36ccd1SDavid Schultz /****************************************************************
2cc36ccd1SDavid Schultz 
3cc36ccd1SDavid Schultz The author of this software is David M. Gay.
4cc36ccd1SDavid Schultz 
5cc36ccd1SDavid Schultz Copyright (C) 1998 by Lucent Technologies
6cc36ccd1SDavid Schultz All Rights Reserved
7cc36ccd1SDavid Schultz 
8cc36ccd1SDavid Schultz Permission to use, copy, modify, and distribute this software and
9cc36ccd1SDavid Schultz its documentation for any purpose and without fee is hereby
10cc36ccd1SDavid Schultz granted, provided that the above copyright notice appear in all
11cc36ccd1SDavid Schultz copies and that both that the copyright notice and this
12cc36ccd1SDavid Schultz permission notice and warranty disclaimer appear in supporting
13cc36ccd1SDavid Schultz documentation, and that the name of Lucent or any of its entities
14cc36ccd1SDavid Schultz not be used in advertising or publicity pertaining to
15cc36ccd1SDavid Schultz distribution of the software without specific, written prior
16cc36ccd1SDavid Schultz permission.
17cc36ccd1SDavid Schultz 
18cc36ccd1SDavid Schultz LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
19cc36ccd1SDavid Schultz INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
20cc36ccd1SDavid Schultz IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
21cc36ccd1SDavid Schultz SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
22cc36ccd1SDavid Schultz WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
23cc36ccd1SDavid Schultz IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
24cc36ccd1SDavid Schultz ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
25cc36ccd1SDavid Schultz THIS SOFTWARE.
26cc36ccd1SDavid Schultz 
27cc36ccd1SDavid Schultz ****************************************************************/
28cc36ccd1SDavid Schultz 
29cc36ccd1SDavid Schultz /* Please send bug reports to
30cc36ccd1SDavid Schultz 	David M. Gay
31cc36ccd1SDavid Schultz 	Bell Laboratories, Room 2C-463
32cc36ccd1SDavid Schultz 	600 Mountain Avenue
33cc36ccd1SDavid Schultz 	Murray Hill, NJ 07974-0636
34cc36ccd1SDavid Schultz 	U.S.A.
35cc36ccd1SDavid Schultz 	dmg@bell-labs.com
36cc36ccd1SDavid Schultz  */
37cc36ccd1SDavid Schultz 
38cc36ccd1SDavid Schultz #include "gdtoaimp.h"
39cc36ccd1SDavid Schultz 
40cc36ccd1SDavid Schultz  int
41cc36ccd1SDavid Schultz #ifdef KR_headers
42cc36ccd1SDavid Schultz strtoIQ(s, sp, a, b) CONST char *s; char **sp; void *a; void *b;
43cc36ccd1SDavid Schultz #else
44cc36ccd1SDavid Schultz strtoIQ(CONST char *s, char **sp, void *a, void *b)
45cc36ccd1SDavid Schultz #endif
46cc36ccd1SDavid Schultz {
47cc36ccd1SDavid Schultz 	static FPI fpi = { 113, 1-16383-113+1, 32766-16383-113+1, 1, SI };
48cc36ccd1SDavid Schultz 	Long exp[2];
49cc36ccd1SDavid Schultz 	Bigint *B[2];
50cc36ccd1SDavid Schultz 	int k, rv[2];
51cc36ccd1SDavid Schultz 	ULong *L = (ULong *)a, *M = (ULong *)b;
52cc36ccd1SDavid Schultz 
53cc36ccd1SDavid Schultz 	B[0] = Balloc(2);
54cc36ccd1SDavid Schultz 	B[0]->wds = 4;
55cc36ccd1SDavid Schultz 	k = strtoIg(s, sp, &fpi, exp, B, rv);
56cc36ccd1SDavid Schultz 	ULtoQ(L, B[0]->x, exp[0], rv[0]);
57cc36ccd1SDavid Schultz 	Bfree(B[0]);
58cc36ccd1SDavid Schultz 	if (B[1]) {
59cc36ccd1SDavid Schultz 		ULtoQ(M, B[1]->x, exp[1], rv[1]);
60cc36ccd1SDavid Schultz 		Bfree(B[1]);
61cc36ccd1SDavid Schultz 		}
62cc36ccd1SDavid Schultz 	else {
63cc36ccd1SDavid Schultz 		M[0] = L[0];
64cc36ccd1SDavid Schultz 		M[1] = L[1];
65cc36ccd1SDavid Schultz 		M[2] = L[2];
66cc36ccd1SDavid Schultz 		M[3] = L[3];
67cc36ccd1SDavid Schultz 		}
68cc36ccd1SDavid Schultz 	return k;
69cc36ccd1SDavid Schultz 	}
70