Subversion Repositories tendra.SVN

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
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
$Author: release $
33
$Date: 1998/01/17 15:55:47 $
34
$Revision: 1.1.1.1 $
35
$Log: f64.c,v $
36
 * Revision 1.1.1.1  1998/01/17  15:55:47  release
37
 * First version to be checked into rolling release.
38
 *
39
 * Revision 1.1  1995/04/06  10:44:05  currie
40
 * Initial revision
41
 *
42
***********************************************************************/
43
 
44
 
45
 
46
#include "config.h"
47
#include "common_types.h"
48
#include "flpttypes.h"
49
#include "messages_c.h"
50
#include "flpt.h"
51
#include "basicread.h"
52
#include "expmacs.h"
53
#include "exp.h"
54
 
55
#include "f64.h"
56
 
57
 
58
 
59
/* PROCEDURES */
60
 
61
flt64 flt_to_f64
62
    PROTO_N ( (fp, sg, ov) )
63
    PROTO_T ( flpt fp X int sg X int * ov )
64
{
65
  flt * f = &flptnos[fp];
66
  flt64 res;
67
  int i = f->exp;
68
  *ov = 0;
69
 
70
  if (f->sign == 0 || i<0) {
71
    res.big = 0;
72
    res.small = 0;
73
  }
74
  else {
75
    res.big = 0;
76
    res.small = f->mant[i];
77
    if (i>0)
78
      res.small += (unsigned int)(f->mant[i-1] << 16);
79
    if (i>1)
80
      res.big = (int)f->mant[i-2];
81
    if (i>2)
82
      res.big += (int)(f->mant[i-3] << 16);
83
    if (i>3 || (sg && res.big < 0))
84
      *ov = 1;
85
  };
86
 
87
  if (f->sign == -1)  {
88
    res.small = ~res.small;
89
    res.big = ~res.big;
90
    if (res.small == 0xffffffff) {
91
      ++res.big;
92
    };
93
    ++res.small;
94
  };
95
 
96
  return res;
97
}
98
 
99
flpt f64_to_flt
100
    PROTO_N ( (a, sg) )
101
    PROTO_T ( flt64 a X int sg )
102
{
103
  flpt r = new_flpt();
104
  flt * res = &flptnos[r];
105
  flt_zero(res);
106
 
107
  if (a.big == 0 && a.small == 0)  {
108
    return r;
109
  };
110
 
111
  if (sg && a.big < 0) {
112
    a.small = ~a.small;
113
    a.big = ~a.big;
114
    if (a.small == 0xffffffff) {
115
      ++a.big;
116
    };
117
    ++a.small;
118
    res->sign = -1;
119
  }
120
  else
121
    res->sign = 1;
122
 
123
  if (a.big == 0) {
124
    if ((a.small & 0xffff0000) == 0) {
125
      res->exp = 0;
126
      res->mant[0] = (unsigned short)(a.small & 0xffff);
127
    }
128
    else {
129
      res->exp = 1;
130
      res->mant[0] = (unsigned short)((a.small & 0xffff0000) >> 16);
131
      res->mant[1] = (unsigned short)(a.small & 0xffff);
132
    };
133
  }
134
  else {
135
    if ((a.big & (int)0xffff0000) == 0) {
136
      res->exp = 2;
137
      res->mant[0] = (unsigned short)(a.big & 0xffff);
138
      res->mant[1] = (unsigned short)((a.small & 0xffff0000) >> 16);
139
      res->mant[2] = (unsigned short)(a.small & 0xffff);
140
    }
141
    else {
142
      res->exp = 3;
143
      res->mant[0] = (unsigned short)(((unsigned int)a.big >> 16) & 0xffff);
144
      res->mant[1] = (unsigned short)(a.big & 0xffff);
145
      res->mant[2] = (unsigned short)((a.small & 0xffff0000) >> 16);
146
      res->mant[3] = (unsigned short)(a.small & 0xffff);
147
    };
148
  };
149
 
150
  return r;
151
}
152
 
153
int f64_to_flpt
154
    PROTO_N ( (a, sg, pr, sz) )
155
    PROTO_T ( flt64 a X int sg X int * pr X int sz )
156
{
157
  int t = (int)a.small;
158
  *pr = 0;
159
 
160
  if (sg && (t >> 31) == a.big)
161
    return t;
162
 
163
  if (!sg && a.big == 0 && ((a.small & 0x80000000) == 0 || sz <= 32))
164
    return t;
165
 
166
  *pr = 1;
167
  return  f64_to_flt(a, sg);
168
}
169
 
170
 
171
flt64 int_to_f64
172
    PROTO_N ( (i, sg) )
173
    PROTO_T ( int i X int sg )
174
{
175
  flt64 res;
176
  res.small = (unsigned int)i;
177
  if (sg && i < 0)
178
    res.big = -1;
179
  else
180
    res.big = 0;
181
  return res;
182
}
183
 
184
flt64 exp_to_f64
185
    PROTO_N ( (e) )
186
    PROTO_T ( exp e )
187
{
188
  int ov;
189
  if (isbigval(e))
190
    return flt_to_f64(no(e), is_signed(sh(e)), &ov);
191
  return int_to_f64(no(e), is_signed(sh(e)));
192
}
193
 
194