2 |
7u83 |
1 |
/*
|
|
|
2 |
Crown Copyright (c) 1997
|
|
|
3 |
|
|
|
4 |
This TenDRA(r) Computer Program is subject to Copyright
|
|
|
5 |
owned by the United Kingdom Secretary of State for Defence
|
|
|
6 |
acting through the Defence Evaluation and Research Agency
|
|
|
7 |
(DERA). It is made available to Recipients with a
|
|
|
8 |
royalty-free licence for its use, reproduction, transfer
|
|
|
9 |
to other parties and amendment for any purpose not excluding
|
|
|
10 |
product development provided that any such use et cetera
|
|
|
11 |
shall be deemed to be acceptance of the following conditions:-
|
|
|
12 |
|
|
|
13 |
(1) Its Recipients shall ensure that this Notice is
|
|
|
14 |
reproduced upon any copies or amended versions of it;
|
|
|
15 |
|
|
|
16 |
(2) Any amended version of it shall be clearly marked to
|
|
|
17 |
show both the nature of and the organisation responsible
|
|
|
18 |
for the relevant amendment or amendments;
|
|
|
19 |
|
|
|
20 |
(3) Its onward transfer from a recipient to another
|
|
|
21 |
party shall be deemed to be that party's acceptance of
|
|
|
22 |
these conditions;
|
|
|
23 |
|
|
|
24 |
(4) DERA gives no warranty or assurance as to its
|
|
|
25 |
quality or suitability for any purpose and DERA accepts
|
|
|
26 |
no liability whatsoever in relation to any use to which
|
|
|
27 |
it may be put.
|
|
|
28 |
*/
|
|
|
29 |
|
|
|
30 |
|
|
|
31 |
/*
|
|
|
32 |
** float.c
|
|
|
33 |
*/
|
|
|
34 |
|
|
|
35 |
#include "config.h"
|
|
|
36 |
#include "common_types.h"
|
|
|
37 |
#include "flpttypes.h"
|
|
|
38 |
#include "flpt.h"
|
|
|
39 |
#include "expmacs.h"
|
|
|
40 |
#include "shapemacs.h"
|
|
|
41 |
#include "tags.h"
|
|
|
42 |
#include "float.h"
|
|
|
43 |
#define is_negative(x) (x.sign<0)
|
|
|
44 |
|
|
|
45 |
|
|
|
46 |
/*
|
|
|
47 |
This function takes an exp _e_ corresponding to a real_tag, and
|
|
|
48 |
returns the floating point value referenced, by reading it from
|
|
|
49 |
the flptnos[] array in the correct format.
|
|
|
50 |
*/
|
|
|
51 |
#if (FBASE == 10)
|
|
|
52 |
char * floating_value
|
|
|
53 |
PROTO_N ( ( e ) )
|
|
|
54 |
PROTO_T ( exp e )
|
|
|
55 |
{
|
|
|
56 |
int ref = no(e);
|
|
|
57 |
unsigned char *frac = (flptnos[ref].mant);
|
|
|
58 |
char *result = (char*)xcalloc(128,sizeof(char*));
|
|
|
59 |
int n,j;
|
|
|
60 |
int pos=0;
|
|
|
61 |
|
|
|
62 |
/* find end of value */
|
|
|
63 |
for(n=MANT_SIZE-1;(n>1) && (frac[n]==0);n--);
|
|
|
64 |
if( is_negative(flptnos[ref]) )
|
|
|
65 |
result[pos++]='-';
|
|
|
66 |
result[pos++]=frac[0]+'0';
|
|
|
67 |
result[pos++]='.';
|
|
|
68 |
for(j=1;j<=n;++pos,++j)
|
|
|
69 |
result[pos] = frac[j]+'0';
|
|
|
70 |
if(flptnos[ref].exp != 0){
|
|
|
71 |
char *expstr=(char*)xcalloc(20,sizeof(char));
|
|
|
72 |
sprintf(expstr,"E%ld",flptnos[ref].exp);
|
|
|
73 |
strcat(result,expstr);
|
|
|
74 |
}
|
|
|
75 |
return result;
|
|
|
76 |
}
|
|
|
77 |
#endif
|
|
|
78 |
|
|
|
79 |
|
|
|
80 |
|
|
|
81 |
/*
|
|
|
82 |
Return true if the floating point constant produced by the
|
|
|
83 |
make_floating construct is an IEEE denormal. Denormals are
|
|
|
84 |
identified by having a non-zero fraction and a zero exponent.
|
|
|
85 |
*/
|
|
|
86 |
bool is_denormal
|
|
|
87 |
PROTO_N ( ( e ) )
|
|
|
88 |
PROTO_T ( exp e )
|
|
|
89 |
{
|
|
|
90 |
int fraction;
|
|
|
91 |
int exponent;
|
|
|
92 |
int fv = name(sh(e)) - shrealhd;
|
|
|
93 |
bool result;
|
|
|
94 |
r2l ieeeflt = real2longs_IEEE(&flptnos[no(e)],fv);
|
|
|
95 |
Assert(name(e) == real_tag);
|
|
|
96 |
switch(name(sh(e))){
|
|
|
97 |
case shrealhd:
|
|
|
98 |
exponent = ieeeflt.i1 & 0x7f800000;
|
|
|
99 |
fraction = ieeeflt.i1 & ~0xff800000;
|
|
|
100 |
break;
|
|
|
101 |
case realhd:
|
|
|
102 |
exponent = ieeeflt.i2 & 0x7ff00000;
|
|
|
103 |
fraction = (ieeeflt.i2 & ~0xfff00000) | ieeeflt.i1;
|
|
|
104 |
break;
|
|
|
105 |
default:
|
|
|
106 |
failer("Invalid floating point variety");
|
|
|
107 |
break;
|
|
|
108 |
}
|
|
|
109 |
result = (exponent == 0) && (fraction != 0);
|
|
|
110 |
return result;
|
|
|
111 |
}
|
|
|
112 |
|
|
|
113 |
|
|
|
114 |
|
|
|
115 |
|