Subversion Repositories tendra.SVN

Rev

Rev 5 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 5 Rev 6
Line -... Line 1...
-
 
1
/*
-
 
2
 * Copyright (c) 2002-2005 The TenDRA Project <http://www.tendra.org/>.
-
 
3
 * All rights reserved.
-
 
4
 *
-
 
5
 * Redistribution and use in source and binary forms, with or without
-
 
6
 * modification, are permitted provided that the following conditions are met:
-
 
7
 *
-
 
8
 * 1. Redistributions of source code must retain the above copyright notice,
-
 
9
 *    this list of conditions and the following disclaimer.
-
 
10
 * 2. Redistributions in binary form must reproduce the above copyright notice,
-
 
11
 *    this list of conditions and the following disclaimer in the documentation
-
 
12
 *    and/or other materials provided with the distribution.
-
 
13
 * 3. Neither the name of The TenDRA Project nor the names of its contributors
-
 
14
 *    may be used to endorse or promote products derived from this software
-
 
15
 *    without specific, prior written permission.
-
 
16
 *
-
 
17
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
-
 
18
 * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
-
 
19
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-
 
20
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
-
 
21
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
-
 
22
 * EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-
 
23
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
-
 
24
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-
 
25
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
-
 
26
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
-
 
27
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
 
28
 *
-
 
29
 * $Id$
-
 
30
 */
1
/*
31
/*
2
    		 Crown Copyright (c) 1997
32
    		 Crown Copyright (c) 1997
3
 
33
 
4
    This TenDRA(r) Computer Program is subject to Copyright
34
    This TenDRA(r) Computer Program is subject to Copyright
5
    owned by the United Kingdom Secretary of State for Defence
35
    owned by the United Kingdom Secretary of State for Defence
Line 33... Line 63...
33
$Date: 1998/01/17 15:55:47 $
63
$Date: 1998/01/17 15:55:47 $
34
$Revision: 1.1.1.1 $
64
$Revision: 1.1.1.1 $
35
$Log: f64.c,v $
65
$Log: f64.c,v $
36
 * Revision 1.1.1.1  1998/01/17  15:55:47  release
66
 * Revision 1.1.1.1  1998/01/17  15:55:47  release
37
 * First version to be checked into rolling release.
67
 * First version to be checked into rolling release.
38
 *
68
 *
39
 * Revision 1.1  1995/04/06  10:44:05  currie
69
 * Revision 1.1  1995/04/06  10:44:05  currie
40
 * Initial revision
70
 * Initial revision
41
 *
71
 *
42
***********************************************************************/
72
***********************************************************************/
43
 
73
 
44
 
74
 
45
 
75
 
46
#include "config.h"
76
#include "config.h"
47
#include "common_types.h"
77
#include "common_types.h"
48
#include "flpttypes.h"
78
#include "flpttypes.h"
49
#include "messages_c.h"
79
#include "messages_c.h"
Line 53... Line 83...
53
#include "exp.h"
83
#include "exp.h"
54
 
84
 
55
#include "f64.h"
85
#include "f64.h"
56
 
86
 
57
 
87
 
58
 
88
 
59
/* PROCEDURES */
89
/* PROCEDURES */
60
 
90
 
61
flt64 flt_to_f64
91
flt64
62
    PROTO_N ( (fp, sg, ov) )
-
 
63
    PROTO_T ( flpt fp X int sg X int * ov )
92
flt_to_f64(flpt fp, int sg, int *ov)
64
{
93
{
65
  flt * f = &flptnos[fp];
94
  flt *f = &flptnos[fp];
66
  flt64 res;
95
  flt64 res;
67
  int i = f->exp;
96
  int i = f->exp;
68
  *ov = 0;
97
  *ov = 0;
69
 
98
 
70
  if (f->sign == 0 || i<0) {
99
  if (f->sign == 0 || i < 0) {
71
    res.big = 0;
100
    res.big = 0;
72
    res.small = 0;
101
    res.small = 0;
73
  }
-
 
74
  else {
102
  } else {
75
    res.big = 0;
103
    res.big = 0;
76
    res.small = f->mant[i];
104
    res.small = f->mant[i];
77
    if (i>0)
105
    if (i > 0) {
78
      res.small += (unsigned int)(f->mant[i-1] << 16);
106
      res.small += (unsigned int)(f->mant[i - 1] << 16);
-
 
107
    }
79
    if (i>1)
108
    if (i > 1) {
80
      res.big = (int)f->mant[i-2];
109
      res.big = (int)f->mant[i - 2];
-
 
110
    }
81
    if (i>2)
111
    if (i > 2) {
82
      res.big += (int)(f->mant[i-3] << 16);
112
      res.big += (int)(f->mant[i - 3] << 16);
-
 
113
    }
83
    if (i>3 || (sg && res.big < 0))
114
    if (i > 3 || (sg && res.big < 0)) {
84
      *ov = 1;
115
      *ov = 1;
-
 
116
    }
85
  };
117
  }
86
 
118
 
87
  if (f->sign == -1)  {
119
  if (f->sign == -1) {
88
    res.small = ~res.small;
120
    res.small = ~res.small;
89
    res.big = ~res.big;
121
    res.big = ~res.big;
90
    if (res.small == 0xffffffff) {
122
    if (res.small == 0xffffffff) {
91
      ++res.big;
123
      ++res.big;
92
    };
124
    }
93
    ++res.small;
125
    ++res.small;
94
  };
126
  }
95
 
127
 
96
  return res;
128
  return res;
97
}
129
}
98
 
130
 
-
 
131
 
99
flpt f64_to_flt
132
flpt
100
    PROTO_N ( (a, sg) )
-
 
101
    PROTO_T ( flt64 a X int sg )
133
f64_to_flt(flt64 a, int sg)
102
{
134
{
103
  flpt r = new_flpt();
135
  flpt r = new_flpt();
104
  flt * res = &flptnos[r];
136
  flt *res = &flptnos[r];
105
  flt_zero(res);
137
  flt_zero(res);
106
 
138
 
107
  if (a.big == 0 && a.small == 0)  {
139
  if (a.big == 0 && a.small == 0) {
108
    return r;
140
    return r;
109
  };
141
  }
110
 
142
 
111
  if (sg && a.big < 0) {
143
  if (sg && a.big < 0) {
112
    a.small = ~a.small;
144
    a.small = ~a.small;
113
    a.big = ~a.big;
145
    a.big = ~a.big;
114
    if (a.small == 0xffffffff) {
146
    if (a.small == 0xffffffff) {
115
      ++a.big;
147
      ++a.big;
116
    };
148
    }
117
    ++a.small;
149
    ++a.small;
118
    res->sign = -1;
150
    res->sign = -1;
119
  }
-
 
120
  else
151
  } else {
121
    res->sign = 1;
152
    res->sign = 1;
-
 
153
  }
122
 
154
 
123
  if (a.big == 0) {
155
  if (a.big == 0) {
124
    if ((a.small & 0xffff0000) == 0) {
156
    if ((a.small & 0xffff0000) == 0) {
125
      res->exp = 0;
157
      res->exp = 0;
126
      res->mant[0] = (unsigned short)(a.small & 0xffff);
158
      res->mant[0] = (unsigned short)(a.small & 0xffff);
127
    }
-
 
128
    else {
159
    } else {
129
      res->exp = 1;
160
      res->exp = 1;
130
      res->mant[0] = (unsigned short)((a.small & 0xffff0000) >> 16);
161
      res->mant[0] = (unsigned short)((a.small & 0xffff0000) >> 16);
131
      res->mant[1] = (unsigned short)(a.small & 0xffff);
162
      res->mant[1] = (unsigned short)(a.small & 0xffff);
132
    };
163
    }
133
  }
-
 
134
  else {
164
  } else {
135
    if ((a.big & (int)0xffff0000) == 0) {
165
    if ((a.big & (int)0xffff0000) == 0) {
136
      res->exp = 2;
166
      res->exp = 2;
137
      res->mant[0] = (unsigned short)(a.big & 0xffff);
167
      res->mant[0] = (unsigned short)(a.big & 0xffff);
138
      res->mant[1] = (unsigned short)((a.small & 0xffff0000) >> 16);
168
      res->mant[1] = (unsigned short)((a.small & 0xffff0000) >> 16);
139
      res->mant[2] = (unsigned short)(a.small & 0xffff);
169
      res->mant[2] = (unsigned short)(a.small & 0xffff);
140
    }
-
 
141
    else {
170
    } else {
142
      res->exp = 3;
171
      res->exp = 3;
143
      res->mant[0] = (unsigned short)(((unsigned int)a.big >> 16) & 0xffff);
172
      res->mant[0] = (unsigned short)(((unsigned int)a.big >> 16) & 0xffff);
144
      res->mant[1] = (unsigned short)(a.big & 0xffff);
173
      res->mant[1] = (unsigned short)(a.big & 0xffff);
145
      res->mant[2] = (unsigned short)((a.small & 0xffff0000) >> 16);
174
      res->mant[2] = (unsigned short)((a.small & 0xffff0000) >> 16);
146
      res->mant[3] = (unsigned short)(a.small & 0xffff);
175
      res->mant[3] = (unsigned short)(a.small & 0xffff);
147
    };
176
    }
148
  };
177
  }
149
 
178
 
150
  return r;
179
  return r;
151
}
180
}
152
 
181
 
-
 
182
 
153
int f64_to_flpt
183
int
154
    PROTO_N ( (a, sg, pr, sz) )
-
 
155
    PROTO_T ( flt64 a X int sg X int * pr X int sz )
184
f64_to_flpt(flt64 a, int sg, int *pr, int sz)
156
{
185
{
157
  int t = (int)a.small;
186
  int t = (int)a.small;
158
  *pr = 0;
187
  *pr = 0;
159
 
188
 
160
  if (sg && (t >> 31) == a.big)
189
  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;
190
    return t;
-
 
191
  }
-
 
192
 
-
 
193
  if (!sg && a.big == 0 && ((a.small & 0x80000000) == 0 || sz <= 32)) {
-
 
194
    return t;
-
 
195
  }
165
 
196
 
166
  *pr = 1;
197
  *pr = 1;
167
  return  f64_to_flt(a, sg);
198
  return f64_to_flt(a, sg);
168
}
199
}
169
 
200
 
170
 
201
 
171
flt64 int_to_f64
202
flt64
172
    PROTO_N ( (i, sg) )
-
 
173
    PROTO_T ( int i X int sg )
203
int_to_f64(int i, int sg)
174
{
204
{
175
  flt64 res;
205
  flt64 res;
176
  res.small = (unsigned int)i;
206
  res.small = (unsigned int)i;
177
  if (sg && i < 0)
207
  if (sg && i < 0) {
178
    res.big = -1;
208
    res.big = -1;
179
  else
209
  } else {
180
    res.big = 0;
210
    res.big = 0;
-
 
211
  }
181
  return res;
212
  return res;
182
}
213
}
-
 
214
 
183
 
215
 
184
flt64 exp_to_f64
216
flt64
185
    PROTO_N ( (e) )
-
 
186
    PROTO_T ( exp e )
217
exp_to_f64(exp e)
187
{
218
{
188
  int ov;
219
  int ov;
189
  if (isbigval(e))
220
  if (isbigval(e)) {
190
    return flt_to_f64(no(e), is_signed(sh(e)), &ov);
221
    return flt_to_f64(no(e), is_signed(sh(e)), &ov);
-
 
222
  }
191
  return int_to_f64(no(e), is_signed(sh(e)));
223
  return int_to_f64(no(e), is_signed(sh(e)));
192
}
224
}
193
 
-
 
194
 
-