1 /* $NetBSD: smisc.c,v 1.2 2006/01/25 15:27:42 kleink Exp $ */
3 /****************************************************************
5 The author of this software is David M. Gay.
7 Copyright (C) 1998, 1999 by Lucent Technologies
10 Permission to use, copy, modify, and distribute this software and
11 its documentation for any purpose and without fee is hereby
12 granted, provided that the above copyright notice appear in all
13 copies and that both that the copyright notice and this
14 permission notice and warranty disclaimer appear in supporting
15 documentation, and that the name of Lucent or any of its entities
16 not be used in advertising or publicity pertaining to
17 distribution of the software without specific, written prior
20 LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
21 INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
22 IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
23 SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
24 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
25 IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
26 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
29 ****************************************************************/
31 /* Please send bug reports to David M. Gay (dmg at acm dot org,
32 * with " at " changed at "@" and " dot " changed to "."). */
39 (s
, nd0
, nd
, y9
) CONST
char *s
; int nd0
, nd
; ULong y9
;
41 (CONST
char *s
, int nd0
, int nd
, ULong y9
)
49 for(k
= 0, y
= 1; x
> y
; y
<<= 1, k
++) ;
60 b
->x
[0] = y9
& 0xffff;
61 b
->wds
= (b
->x
[1] = y9
>> 16) ? 2 : 1;
68 b
= multadd(b
, 10, *s
++ - '0');
77 b
= multadd(b
, 10, *s
++ - '0');
89 (Bigint
*a
, Bigint
*b
)
95 dval(da
) = b2d(a
, &ka
);
96 dval(db
) = b2d(b
, &kb
);
97 k
= ka
- kb
+ ULbits
*(a
->wds
- b
->wds
);
100 word0(da
) += (k
>> 2)*Exp_msk1
;
106 word0(db
) += (k
>> 2)*Exp_msk1
;
112 word0(da
) += k
*Exp_msk1
;
115 word0(db
) += k
*Exp_msk1
;
118 return dval(da
) / dval(db
);
126 (sp
, t
) CONST
char **sp
, *t
;
128 (CONST
char **sp
, CONST
char *t
)
134 while( (d
= *t
++) !=0) {
135 if ((c
= *++s
) >= 'A' && c
<= 'Z')
143 #endif /* INFNAN_CHECK */
147 copybits(c
, n
, b
) ULong
*c
; int n
; Bigint
*b
;
149 copybits(ULong
*c
, int n
, Bigint
*b
)
157 ce
= c
+ ((unsigned int)(n
-1) >> kshift
) + 1;
166 for(xe
= x
+ (nw
- nw1
); x
< xe
; x
+= 2)
167 Storeinc(c
, x
[1], x
[0]);
177 any_on(b
, k
) Bigint
*b
; int k
;
179 any_on(Bigint
*b
, int k
)
183 ULong
*x
, *x0
, x1
, x2
;
187 n
= (unsigned int)k
>> kshift
;
190 else if (n
< nwds
&& (k
&= kmask
)) {