1 /* $NetBSD: smisc.c,v 1.5 2012/03/13 21:13:34 christos 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
, dplen
) CONST
char *s
; int dplen
, nd0
, nd
; ULong y9
;
41 (CONST
char *s
, int nd0
, int nd
, ULong y9
, size_t dplen
)
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');
88 (Bigint
*a
, Bigint
*b
)
94 dval(&da
) = b2d(a
, &ka
);
95 dval(&db
) = b2d(b
, &kb
);
96 k
= ka
- kb
+ ULbits
*(a
->wds
- b
->wds
);
99 word0(&da
) += (k
>> 2)*Exp_msk1
;
105 word0(&db
) += (k
>> 2)*Exp_msk1
;
111 word0(&da
) += k
*Exp_msk1
;
114 word0(&db
) += k
*Exp_msk1
;
117 return dval(&da
) / dval(&db
);
125 (sp
, t
) CONST
char **sp
, *t
;
127 (CONST
char **sp
, CONST
char *t
)
133 while( (d
= *t
++) !=0) {
134 if ((c
= *++s
) >= 'A' && c
<= 'Z')
142 #endif /* INFNAN_CHECK */
146 copybits(c
, n
, b
) ULong
*c
; int n
; Bigint
*b
;
148 copybits(ULong
*c
, int n
, Bigint
*b
)
156 ce
= c
+ ((unsigned int)(n
-1) >> kshift
) + 1;
165 for(xe
= x
+ (nw
- nw1
); x
< xe
; x
+= 2)
166 Storeinc(c
, x
[1], x
[0]);
176 any_on(b
, k
) Bigint
*b
; int k
;
178 any_on(Bigint
*b
, int k
)
182 ULong
*x
, *x0
, x1
, x2
;
186 n
= (unsigned int)k
>> kshift
;
189 else if (n
< nwds
&& (k
&= kmask
)) {