* Copyright (c) 1982 Regents of the University of California
static char sccsid
[] = "@(#)bignum1.c 4.4 %G%";
* Construct a floating point number
Bignum
as_atof(numbuf
, radix
, ovfp
)
number
.num_num
.numFd_float
.Fd_value
= atof(numbuf
);
number
= bigatof(numbuf
, radix
);
if (errno
== ERANGE
&& passno
== 2){
yywarning("Floating conversion over/underflowed\n");
Bignum
as_atoi(ccp
, radix
, ovfp
)
reg
char *ccp
; /* character cp */
bcp
= CH_FIELD(n_n
); (void)numclear(bcp
);
tcp
= CH_FIELD(t_n
); (void)numclear(tcp
);
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7':
case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
ovf
|= numshift(3, bcp
, bcp
);
ovf
|= numshift(4, bcp
, bcp
);
ovf
|= numshift(1, tcp
, bcp
);
ovf
|= numshift(3, bcp
, bcp
);
ovf
|= numaddv(bcp
, tcp
, bcp
);
ovf
|= numaddd(bcp
, bcp
, val
);
ovf
&= ~(OVF_MAXINT
| OVF_POSOVF
);
ovf
|= numnegate(bcp
, bcp
);
* find the highest set unit of the number
for (i
= 0; i
< CH_N
; i
++){
static u_char tagtab
[4][16] = {
TYPO
, TYPO
, TYPO
, TYPO
, TYPO
, TYPO
, TYPO
, TYPO
},
* i indexes to the null chunk; make it point to the
n_n
.num_tag
= tagtab
[HOC
][i
];
assert(n_n
.num_tag
!= 0, "Botch width computation");
if (src
[HOC
] == SIGNBIT
){
for (i
= HOC
- 1; i
>= 0; --i
){
* check if the number is clear
return(!isunequal(dst
, CH_FIELD(Znumber
)));
int isunequal(src1
, src2
)
Ovf
numshift(n
, dst
, src
)
reg u_int carryi
, carryo
;
carryo
= (value
>> (CH_BITS
- n
)) & mask
;
return(carryi
? OVF_LSHIFT
: 0);
value
&= ONES(CH_BITS
- n
);
carryi
= carryo
<< (CH_BITS
- n
);
return(carryi
? OVF_LSHIFT
: 0);
Ovf
numaddd(dst
, src1
, val
)
return (numaddv(dst
, src1
, CH_FIELD(work
)));
Ovf
numaddv(dst
, src1
, src2
)
reg chptr dst
, src1
, src2
;
if (value
< A
|| value
< B
)
return(carry
? OVF_ADDV
: 0);
ovf
= num1comp(dst
, src
) ;
ovf
|= numaddd(dst
, dst
, 1);
* Determine if floating point numbers are
* capable of being represented as a one byte immediate literal constant
* If it is, then stuff the value into *valuep.
* argtype is how the instruction will interpret the number.
int slitflt(number
, argtype
, valuep
)
Bignum number
; /* number presented */
int argtype
; /* what the instruction expects */
unpacked
= bignumunpack(number
, &ovf
);
assert(ovf
== 0, "overflow in unpacking floating #!?");
if (unpacked
.num_exponent
< 0)
if (unpacked
.num_exponent
> ONES(EXPPREC
))
for (i
= 0; i
< HOC
; i
++){
if (CH_FIELD(unpacked
)[i
])
if ((CH_FIELD(unpacked
)[HOC
]) & ONES(CH_BITS
- MANTPREC
))
*valuep
= (unpacked
.num_exponent
& ONES(EXPPREC
)) << MANTPREC
;
mask
= (CH_FIELD(unpacked
)[HOC
]) >> (CH_BITS
- MANTPREC
);
*valuep
&= ONES(MANTPREC
+ EXPPREC
);
* Output a big number to txtfil
* Called only when passno == 2
* The conversion specifies the width of the number to be written out.
* The width is supplied from either an initialized data directive
* (for example .float, .double), or from the operand size
* defined by an operator.
* If the number is of type quad or octal,
* we just write it out; this allows one to specify bit
* patterns for floating point numbers.
* If the number is one of the floating types and the conversion
* is not the same type, then we complain, but do the conversion anyway.
* The conversion is strict.
bignumwrite(number
, toconv
)
int toconv
; /* one of TYP[QO FDGH] */
bp
= &number
.num_uint
[0];
number
= intconvert(number
, toconv
);
number
= floatconvert(number
, toconv
);
bwrite((char *)bp
, ty_nbyte
[toconv
], txtfil
);