Subversion Repositories tendra.SVN

Rev

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

Rev 2 Rev 7
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 41... Line 71...
41
 *
71
 *
42
***********************************************************************/
72
***********************************************************************/
43
 
73
 
44
 
74
 
45
 
75
 
46
  /* This file consists of the floating point and complex operations
76
/* This file consists of the floating point and complex operations
47
     extracted from install_fns.c, to reduce compilation unit sizes
77
   extracted from install_fns.c, to reduce compilation unit sizes */
48
  */
-
 
49
 
78
 
50
#include "config.h"
79
#include "config.h"
51
#include <ctype.h>
80
#include <ctype.h>
52
#include <time.h>
81
#include <time.h>
53
#include "common_types.h"
82
#include "common_types.h"
Line 78... Line 107...
78
#include "readglob.h"
107
#include "readglob.h"
79
#include "case_opt.h"
108
#include "case_opt.h"
80
#include "install_fns.h"
109
#include "install_fns.h"
81
#include "externs.h"
110
#include "externs.h"
82
 
111
 
83
 
112
 
84
extern shape shcomplexsh;
113
extern shape shcomplexsh;
85
extern shape complexsh;
114
extern shape complexsh;
86
extern shape complexdoublesh;
115
extern shape complexdoublesh;
87
exp_list reorder_list PROTO_S ( ( exp_list, int ) ) ;
116
exp_list reorder_list(exp_list, int);
88
exp me_contents PROTO_S ( ( exp ) ) ;
117
exp me_contents(exp);
89
extern int eq_et PROTO_S ( ( error_treatment, error_treatment ) ) ;
118
extern int eq_et(error_treatment, error_treatment);
90
extern exp TDFcallaux PROTO_S ( ( error_treatment, exp, char *, shape ) ) ;
119
extern exp TDFcallaux(error_treatment, exp, char *, shape);
91
extern exp find_named_tg PROTO_S ( ( char *, shape ) ) ;
120
extern exp find_named_tg(char *, shape);
92
 
-
 
93
static exp me_complete_chain PROTO_S ( ( exp, exp, exp ) ) ;
-
 
94
static exp push PROTO_S ( ( exp, exp ) ) ;
-
 
95
static void square_x_iy PROTO_S ( ( error_treatment, exp *, exp *, exp ) ) ;
-
 
96
static void mult_w_by_z PROTO_S ( ( error_treatment, exp *, exp *, exp, exp, exp ) ) ;
-
 
97
static exp make_comp_1_z PROTO_S ( ( floating_variety, error_treatment, exp, exp, exp, exp, exp, exp ) ) ;
-
 
98
static exp f_bin_floating_plus PROTO_S ( ( error_treatment, exp, exp ) ) ;
-
 
99
static exp f_bin_floating_mult PROTO_S ( ( error_treatment, exp, exp ) ) ;
-
 
100
static exp real_power PROTO_S ( ( error_treatment, exp, exp ) ) ;
-
 
101
 
-
 
102
 
121
 
-
 
122
static exp me_complete_chain(exp, exp, exp);
-
 
123
static exp push(exp, exp);
-
 
124
static void square_x_iy(error_treatment, exp *, exp *, exp);
-
 
125
static void mult_w_by_z(error_treatment, exp *, exp *, exp, exp, exp);
-
 
126
static exp make_comp_1_z(floating_variety, error_treatment, exp, exp, exp, exp,
-
 
127
			 exp, exp);
-
 
128
static exp f_bin_floating_plus(error_treatment, exp, exp);
-
 
129
static exp f_bin_floating_mult(error_treatment, exp, exp);
-
 
130
static exp real_power(error_treatment, exp, exp);
103
 
131
 
-
 
132
 
-
 
133
 
-
 
134
exp
104
exp f_change_floating_variety
135
f_change_floating_variety(error_treatment flpt_err, floating_variety r,
105
    PROTO_N ( (flpt_err, r, arg1) )
136
			  exp arg1)
106
    PROTO_T ( error_treatment flpt_err X floating_variety r X exp arg1 )
-
 
107
{
137
{
108
  if (name(sh(arg1)) == bothd)
138
  if (name(sh(arg1)) == bothd) {
109
    return arg1;
139
    return arg1;
-
 
140
  }
110
 
141
 
111
#if check_shape
142
#if check_shape
112
  if ( ! ( (is_complex(sh(arg1)) && is_complex(f_floating(r)) ) ||
143
  if (!((is_complex(sh(arg1)) && is_complex(f_floating(r))) ||
113
	   (is_float(sh(arg1)) && is_float(f_floating(r)) )
144
	(is_float(sh(arg1)) && is_float(f_floating(r))))) {
114
	 )
-
 
115
     )
-
 
116
    failer(CHSH_CHFL);
145
    failer(CHSH_CHFL);
-
 
146
  }
117
#endif
147
#endif
118
 if (eq_shape(f_floating(r), sh(arg1)))		/* i.e. does nothing */
148
 if (eq_shape(f_floating(r), sh(arg1))) {	/* i.e. does nothing */
119
    return arg1;	/* Discard the other bits ? */
149
    return arg1;	/* Discard the other bits ? */
-
 
150
 }
120
 
151
 
121
#if substitute_complex
152
#if substitute_complex
122
  if (is_complex(sh(arg1)))
153
  if (is_complex(sh(arg1))) {
123
  {
-
 
124
    shape complex_shape = sh(arg1);
154
    shape complex_shape = sh(arg1);
125
    floating_variety real_fv = f_float_of_complex (f_floating(r));
155
    floating_variety real_fv = f_float_of_complex(f_floating(r));
126
 
156
 
127
    exp c1 = me_startid (complex_shape, arg1, 0);
157
    exp c1 = me_startid(complex_shape, arg1, 0);
128
 
158
 
129
    exp obtain1_c1 = me_obtain(c1);		/* contents of arg1 */
159
    exp obtain1_c1 = me_obtain(c1);		/* contents of arg1 */
130
    exp obtain2_c1 = me_obtain(c1);
160
    exp obtain2_c1 = me_obtain(c1);
131
 
161
 
132
    exp x = f_real_part      (obtain1_c1);		/* re(arg1) */
162
    exp x = f_real_part(obtain1_c1);		/* re(arg1) */
133
    exp y = f_imaginary_part (obtain2_c1);		/* im(arg1) */
163
    exp y = f_imaginary_part(obtain2_c1);	/* im(arg1) */
134
 
164
 
135
    exp new_x = f_change_floating_variety (flpt_err, real_fv, x);
165
    exp new_x = f_change_floating_variety(flpt_err, real_fv, x);
136
    exp new_y = f_change_floating_variety (flpt_err, real_fv, y);
166
    exp new_y = f_change_floating_variety(flpt_err, real_fv, y);
137
 
167
 
138
    exp make_comp = f_make_complex (r, new_x, new_y);
168
    exp make_comp = f_make_complex(r, new_x, new_y);
139
    c1 = me_complete_id (c1, make_comp);		/* Does a 'hold_check' */
169
    c1 = me_complete_id(c1, make_comp);	/* Does a 'hold_check' */
140
 
170
 
141
    return c1;
171
    return c1;
142
  };
172
  }
143
#endif  /* substitute complex */
173
#endif  /* substitute complex */
144
 
174
 
145
#if ishppa
175
#if ishppa
146
  {
176
  {
147
    exp t = me_c1(f_floating(r), flpt_err, arg1, chfl_tag);
177
    exp t = me_c1(f_floating(r), flpt_err, arg1, chfl_tag);
148
    if (!optop(t) && name(sh(t))==doublehd) {
178
    if (!optop(t) && name(sh(t)) == doublehd) {
149
      exp id = me_startid(sh(t),t,0);
179
      exp id = me_startid(sh(t), t, 0);
150
      exp tmp = me_complete_id(id,me_obtain(id));
180
      exp tmp = me_complete_id(id, me_obtain(id));
151
      return tmp;
181
      return tmp;
152
     }
-
 
153
    else
182
     } else {
154
      return t;
183
      return t;
-
 
184
     }
155
  }
185
  }
156
#endif
186
#endif
157
  return me_c1(f_floating(r), flpt_err, arg1, chfl_tag);
187
  return me_c1(f_floating(r), flpt_err, arg1, chfl_tag);
158
}
188
}
159
 
189
 
160
 
190
 
161
 
191
 
162
exp f_complex_conjugate
192
exp
163
    PROTO_N ( (arg1) )
-
 
164
    PROTO_T ( exp arg1 )
193
f_complex_conjugate(exp arg1)
165
{
194
{
166
  if (name(sh(arg1)) == bothd)
195
  if (name(sh(arg1)) == bothd) {
167
    return arg1;
196
    return arg1;
-
 
197
  }
168
#if check_shape
198
#if check_shape
169
  if (!is_complex(sh(arg1)))
199
  if (!is_complex(sh(arg1))) {
170
    failer(CHSH_CONJUGATE);
200
    failer(CHSH_CONJUGATE);
-
 
201
  }
171
#endif
202
#endif
172
 
203
 
173
#if substitute_complex
204
#if substitute_complex
174
  {
205
  {
175
    shape complex_shape = sh(arg1);                     /* shape of our complex numbers */
206
    shape complex_shape = sh(arg1);	/* shape of our complex numbers */
176
    floating_variety real_fv = f_float_of_complex(complex_shape);
207
    floating_variety real_fv = f_float_of_complex(complex_shape);
177
    shape real_shape = f_floating(real_fv);
208
    shape real_shape = f_floating(real_fv);
178
    floating_variety complex_fv = f_complex_of_float(real_shape);
209
    floating_variety complex_fv = f_complex_of_float(real_shape);
179
 
210
 
180
    exp c1 = me_startid(complex_shape, arg1, 0);
211
    exp c1 = me_startid(complex_shape, arg1, 0);
181
 
212
 
182
    exp obtain1_c1 = hold_check(me_obtain(c1));                     /* contents of arg1 */
213
    exp obtain1_c1 = hold_check(me_obtain(c1));		/* contents of arg1 */
183
    exp obtain2_c1 = hold_check(me_obtain(c1));
214
    exp obtain2_c1 = hold_check(me_obtain(c1));
184
 
215
 
185
    exp x1 = f_real_part(obtain1_c1);                                       /* re(arg1) */
216
    exp x1 = f_real_part(obtain1_c1);			/* re(arg1) */
186
    exp y1 = f_imaginary_part(obtain2_c1);                                  /* im(arg1) */
217
    exp y1 = f_imaginary_part(obtain2_c1);		/* im(arg1) */
187
 
218
 
188
    exp neg_im = f_floating_negate(f_impossible, y1);                           /* - im(arg1) */
219
    exp neg_im = f_floating_negate(f_impossible, y1);	/* - im(arg1) */
189
    exp make_comp = f_make_complex(complex_fv, x1, neg_im);
220
    exp make_comp = f_make_complex(complex_fv, x1, neg_im);
190
 
221
 
191
    c1 = me_complete_id(c1, make_comp);
222
    c1 = me_complete_id(c1, make_comp);
192
 
223
 
193
    return c1;
224
    return c1;
Line 196... Line 227...
196
  return me_u3(sh(arg1), arg1, conj_tag);
227
  return me_u3(sh(arg1), arg1, conj_tag);
197
#endif
228
#endif
198
}
229
}
199
 
230
 
200
 
231
 
201
 
232
 
202
exp f_float_int
233
exp
203
    PROTO_N ( (flpt_err, f, arg1) )
-
 
204
    PROTO_T ( error_treatment flpt_err X floating_variety f X exp arg1 )
234
f_float_int(error_treatment flpt_err, floating_variety f, exp arg1)
205
{
235
{
206
  if (name(sh(arg1)) == bothd)
236
  if (name(sh(arg1)) == bothd) {
207
    return arg1;
237
    return arg1;
-
 
238
  }
208
 
239
 
209
#if check_shape
240
#if check_shape
210
  if (!is_integer(sh(arg1)))
241
  if (!is_integer(sh(arg1))) {
211
    failer(CHSH_FLINT);
242
    failer(CHSH_FLINT);
-
 
243
  }
212
#endif
244
#endif
213
 
245
 
214
    if (is_complex(f_floating(f))) {
246
    if (is_complex(f_floating(f))) {
215
	flpt fzero_copy = new_flpt();
247
	flpt fzero_copy = new_flpt();
216
	floating_variety fv = f_float_of_complex(f_floating(f));
248
	floating_variety fv = f_float_of_complex(f_floating(f));
217
	shape real_shape = f_floating(fv);
249
	shape real_shape = f_floating(fv);
218
	exp zero;
250
	exp zero;
219
	exp res = f_float_int(flpt_err, fv, arg1);
251
	exp res = f_float_int(flpt_err, fv, arg1);
220
	res = hold_check(res);
252
	res = hold_check(res);
221
	flt_copy (flptnos[fzero_no], &flptnos[fzero_copy]);
253
	flt_copy(flptnos[fzero_no], &flptnos[fzero_copy]);
222
	zero = getexp(real_shape, nilexp, 1, nilexp, nilexp, 0,
254
	zero = getexp(real_shape, nilexp, 1, nilexp, nilexp, 0, fzero_copy,
223
			fzero_copy,  real_tag);
255
		      real_tag);
224
	return f_make_complex(f, res, zero);
256
	return f_make_complex(f, res, zero);
225
    }
257
    }
226
#if !has64bits
258
#if !has64bits
227
  if ((name(arg1)!=val_tag || flpt_err.err_code > 2)
259
  if ((name(arg1) != val_tag || flpt_err.err_code > 2) &&
228
		 && shape_size(sh(arg1))> 32) {
260
      shape_size(sh(arg1)) > 32) {
229
#if use_long_double
261
#if use_long_double
230
	exp z = TDFcallaux(flpt_err, arg1,
262
	exp z = TDFcallaux(flpt_err, arg1, (is_signed(sh(arg1)) ?
231
		(is_signed(sh(arg1))?"__TDFUs_float":"__TDFUu_float"), doublesh);
263
					    "__TDFUs_float" : "__TDFUu_float"),
-
 
264
			   doublesh);
232
	z = hold_check(z);
265
	z = hold_check(z);
233
	if (f != doublefv) {
266
	if (f != doublefv) {
234
		z = me_c1(f_floating(f), flpt_err, z, chfl_tag);
267
		z = me_c1(f_floating(f), flpt_err, z, chfl_tag);
235
	}
268
	}
236
	return z;
269
	return z;
237
#else
270
#else
238
	exp z = TDFcallaux(flpt_err, arg1,
271
	exp z = TDFcallaux(flpt_err, arg1, (is_signed(sh(arg1)) ?
239
		(is_signed(sh(arg1))?"__TDFUs_float":"__TDFUu_float"), realsh);
272
					    "__TDFUs_float" : "__TDFUu_float"),
-
 
273
			   realsh);
240
	z = hold_check(z);
274
	z = hold_check(z);
241
	if (f != realfv) {
275
	if (f != realfv) {
242
		z = me_c1(f_floating(f), flpt_err, z, chfl_tag);
276
		z = me_c1(f_floating(f), flpt_err, z, chfl_tag);
243
	}
277
	}
244
	return z;
278
	return z;
Line 247... Line 281...
247
#endif
281
#endif
248
  return me_c1(f_floating(f), flpt_err, arg1, float_tag);
282
  return me_c1(f_floating(f), flpt_err, arg1, float_tag);
249
}
283
}
250
 
284
 
251
 
285
 
252
exp f_floating_abs
286
exp
253
    PROTO_N ( (ov_err, arg1) )
-
 
254
    PROTO_T ( error_treatment ov_err X exp arg1 )
287
f_floating_abs(error_treatment ov_err, exp arg1)
255
{
288
{
256
  if (name(sh(arg1)) == bothd)
289
  if (name(sh(arg1)) == bothd) {
257
    return arg1;
290
    return arg1;
-
 
291
  }
258
 
292
 
259
#if check_shape
293
#if check_shape
260
  if (!is_float(sh(arg1)))
294
  if (!is_float(sh(arg1))) {
261
    failer(CHSH_FLABS);
295
    failer(CHSH_FLABS);
-
 
296
  }
262
#endif
297
#endif
263
 
298
 
264
#if ishppa
299
#if ishppa
265
  {
300
  {
266
    exp r = me_u1(ov_err, arg1, fabs_tag);
301
    exp r = me_u1(ov_err, arg1, fabs_tag);
267
    if (!optop(r) && name(sh(r))==doublehd) {
302
    if (!optop(r) && name(sh(r)) == doublehd) {
268
      exp id = me_startid(sh(r),r,0);
303
      exp id = me_startid(sh(r), r, 0);
269
      exp tmp = me_complete_id(id,me_obtain(id));
304
      exp tmp = me_complete_id(id, me_obtain(id));
270
      return tmp;
305
      return tmp;
271
     }
-
 
272
    else
306
     } else {
273
      return r;
307
      return r;
-
 
308
     }
274
  }
309
  }
275
#endif
310
#endif
276
  return me_u1(ov_err, arg1, fabs_tag);
311
  return me_u1(ov_err, arg1, fabs_tag);
277
}
312
}
278
 
313
 
279
 
314
 
280
exp f_floating_div
315
exp
281
    PROTO_N ( (ov_err, arg1, arg2) )
-
 
282
    PROTO_T ( error_treatment ov_err X exp arg1 X exp arg2 )
316
f_floating_div(error_treatment ov_err, exp arg1, exp arg2)
283
{
317
{
284
  if (name(sh(arg1)) == bothd)
318
  if (name(sh(arg1)) == bothd) {
285
    { kill_exp(arg2,arg2); return arg1; }
319
    kill_exp(arg2, arg2);
-
 
320
    return arg1;
-
 
321
  }
286
  if (name(sh(arg2)) == bothd)
322
  if (name(sh(arg2)) == bothd) {
287
    { kill_exp(arg1,arg1); return arg2; }
323
    kill_exp(arg1, arg1);
-
 
324
    return arg2;
-
 
325
  }
288
 
326
 
289
#if check_shape
327
#if check_shape
290
  if (! ((is_float(sh(arg1)) || is_complex(sh(arg1))) && eq_shape(sh(arg1), sh(arg2))) )
328
  if (!((is_float(sh(arg1)) || is_complex(sh(arg1))) &&
-
 
329
	eq_shape(sh(arg1), sh(arg2)))) {
291
    failer(CHSH_FLDIV);
330
    failer(CHSH_FLDIV);
-
 
331
  }
292
#endif
332
#endif
293
 
333
 
294
/* PAB changes - 21 October 1994 */
334
/* PAB changes - 21 October 1994 */
295
#if substitute_complex
335
#if substitute_complex
296
  if (is_complex(sh(arg1))) {
336
  if (is_complex(sh(arg1))) {
297
 
337
 
298
      shape complex_shape = sh(arg1);                     /* shape of our complex numbers */
338
      shape complex_shape = sh(arg1);	/* shape of our complex numbers */
299
      floating_variety real_fv = f_float_of_complex(complex_shape);
339
      floating_variety real_fv = f_float_of_complex(complex_shape);
300
      shape real_shape = f_floating(real_fv);
340
      shape real_shape = f_floating(real_fv);
301
      floating_variety complex_fv = f_complex_of_float(real_shape);
341
      floating_variety complex_fv = f_complex_of_float(real_shape);
302
 
342
 
303
      exp z1 = me_startid(complex_shape, arg1, 0);
343
      exp z1 = me_startid(complex_shape, arg1, 0);
304
      exp z2 = me_startid(complex_shape, arg2, 0);
344
      exp z2 = me_startid(complex_shape, arg2, 0);
305
 
345
 
306
      exp obtain1_z1 = hold_check(me_obtain(z1));                     /* contents of arg1 */
346
      exp obtain1_z1 = hold_check(me_obtain(z1));	/* contents of arg1 */
307
      exp obtain2_z1 = hold_check(me_obtain(z1));
347
      exp obtain2_z1 = hold_check(me_obtain(z1));
308
      exp obtain1_z2 = hold_check(me_obtain(z2));                     /* contents of arg2 */
348
      exp obtain1_z2 = hold_check(me_obtain(z2));	/* contents of arg2 */
309
      exp obtain2_z2 = hold_check(me_obtain(z2));
349
      exp obtain2_z2 = hold_check(me_obtain(z2));
310
 
350
 
311
      exp z1_re = f_real_part(obtain1_z1);                           /* re(arg1) */
351
      exp z1_re = f_real_part(obtain1_z1);		/* re(arg1) */
312
      exp z2_re = f_real_part(obtain1_z2);                           /* re(arg2) */
352
      exp z2_re = f_real_part(obtain1_z2);		/* re(arg2) */
313
      exp z1_im = f_imaginary_part(obtain2_z1);                      /* im(arg1) */
353
      exp z1_im = f_imaginary_part(obtain2_z1);		/* im(arg1) */
314
      exp z2_im = f_imaginary_part(obtain2_z2);                      /* im(arg2) */
354
      exp z2_im = f_imaginary_part(obtain2_z2);		/* im(arg2) */
315
 
355
 
316
      exp x1 = me_startid(real_shape, z1_re, 0);
356
      exp x1 = me_startid(real_shape, z1_re, 0);
317
      exp x2 = me_startid(real_shape, z2_re, 0);
357
      exp x2 = me_startid(real_shape, z2_re, 0);
318
      exp y1 = me_startid(real_shape, z1_im, 0);
358
      exp y1 = me_startid(real_shape, z1_im, 0);
319
      exp y2 = me_startid(real_shape, z2_im, 0);
359
      exp y2 = me_startid(real_shape, z2_im, 0);
320
 
360
 
321
      exp obtain1_x1 = hold_check(me_obtain(x1));                     /* x1 is used twice */
361
      exp obtain1_x1 = hold_check(me_obtain(x1)); /* x1 is used twice */
322
      exp obtain2_x1 = hold_check(me_obtain(x1));
362
      exp obtain2_x1 = hold_check(me_obtain(x1));
323
      exp obtain1_y1 = hold_check(me_obtain(y1));                     /* y1 is used twice */
363
      exp obtain1_y1 = hold_check(me_obtain(y1)); /* y1 is used twice */
324
      exp obtain2_y1 = hold_check(me_obtain(y1));
364
      exp obtain2_y1 = hold_check(me_obtain(y1));
325
 
365
 
326
      exp obtain1_x2 = hold_check(me_obtain(x2));                /* x2 is used four times */
366
      exp obtain1_x2 = hold_check(me_obtain(x2)); /* x2 is used four times */
327
      exp obtain2_x2 = hold_check(me_obtain(x2));
367
      exp obtain2_x2 = hold_check(me_obtain(x2));
328
      exp obtain3_x2 = hold_check(me_obtain(x2));
368
      exp obtain3_x2 = hold_check(me_obtain(x2));
329
      exp obtain4_x2 = hold_check(me_obtain(x2));
369
      exp obtain4_x2 = hold_check(me_obtain(x2));
330
      exp obtain1_y2 = hold_check(me_obtain(y2));                /* y2 is used four times */
370
      exp obtain1_y2 = hold_check(me_obtain(y2)); /* y2 is used four times */
331
      exp obtain2_y2 = hold_check(me_obtain(y2));
371
      exp obtain2_y2 = hold_check(me_obtain(y2));
332
      exp obtain3_y2 = hold_check(me_obtain(y2));
372
      exp obtain3_y2 = hold_check(me_obtain(y2));
333
      exp obtain4_y2 = hold_check(me_obtain(y2));
373
      exp obtain4_y2 = hold_check(me_obtain(y2));
334
 
374
 
335
      exp mult_x2_x2 = f_bin_floating_mult(ov_err, obtain1_x2, obtain2_x2);
375
      exp mult_x2_x2 = f_bin_floating_mult(ov_err, obtain1_x2, obtain2_x2);
336
      exp mult_y2_y2 = f_bin_floating_mult(ov_err, obtain1_y2, obtain2_y2);
376
      exp mult_y2_y2 = f_bin_floating_mult(ov_err, obtain1_y2, obtain2_y2);
337
      exp mult_x1_x2 = f_bin_floating_mult(ov_err, obtain1_x1, obtain3_x2);
377
      exp mult_x1_x2 = f_bin_floating_mult(ov_err, obtain1_x1, obtain3_x2);
338
      exp mult_y1_y2 = f_bin_floating_mult(ov_err, obtain1_y1, obtain3_y2);
378
      exp mult_y1_y2 = f_bin_floating_mult(ov_err, obtain1_y1, obtain3_y2);
339
      exp mult_y1_x2 = f_bin_floating_mult(ov_err, obtain2_y1, obtain4_x2);
379
      exp mult_y1_x2 = f_bin_floating_mult(ov_err, obtain2_y1, obtain4_x2);
340
      exp mult_x1_y2 = f_bin_floating_mult(ov_err, obtain2_x1, obtain4_y2);
380
      exp mult_x1_y2 = f_bin_floating_mult(ov_err, obtain2_x1, obtain4_y2);
341
 
381
 
342
      exp plus1  = f_bin_floating_plus(ov_err, mult_x2_x2, mult_y2_y2);
382
      exp plus1 = f_bin_floating_plus(ov_err, mult_x2_x2, mult_y2_y2);
343
      exp plus2  = f_bin_floating_plus(ov_err, mult_x1_x2, mult_y1_y2);
383
      exp plus2 = f_bin_floating_plus(ov_err, mult_x1_x2, mult_y1_y2);
344
      exp minus1 = f_floating_minus(ov_err, mult_y1_x2, mult_x1_y2);
384
      exp minus1 = f_floating_minus(ov_err, mult_y1_x2, mult_x1_y2);
345
 
385
 
346
      exp denom = me_startid(real_shape, plus1, 0);
386
      exp denom = me_startid(real_shape, plus1, 0);
347
 
387
 
348
      exp obtain_denom1 = hold_check(me_obtain(denom));
388
      exp obtain_denom1 = hold_check(me_obtain(denom));
349
      exp obtain_denom2 = hold_check(me_obtain(denom));
389
      exp obtain_denom2 = hold_check(me_obtain(denom));
350
 
390
 
351
      exp answer_re = f_floating_div(ov_err, plus2,  obtain_denom1);
391
      exp answer_re = f_floating_div(ov_err, plus2, obtain_denom1);
352
      exp answer_im = f_floating_div(ov_err, minus1, obtain_denom2);
392
      exp answer_im = f_floating_div(ov_err, minus1, obtain_denom2);
353
      exp make_comp = f_make_complex(complex_fv, answer_re, answer_im);
393
      exp make_comp = f_make_complex(complex_fv, answer_re, answer_im);
354
 
394
 
355
      denom = me_complete_id(denom, make_comp);
395
      denom = me_complete_id(denom, make_comp);
356
      y2 = me_complete_id(y2, denom);
396
      y2 = me_complete_id(y2, denom);
Line 359... Line 399...
359
      x1 = me_complete_id(x1, x2);
399
      x1 = me_complete_id(x1, x2);
360
      z2 = me_complete_id(z2, x1);
400
      z2 = me_complete_id(z2, x1);
361
      z1 = me_complete_id(z1, z2);
401
      z1 = me_complete_id(z1, z2);
362
 
402
 
363
      return z1;
403
      return z1;
364
  };
404
  }
365
#endif
405
#endif
366
#if ishppa
406
#if ishppa
367
  {
407
  {
368
    exp r = hold_check(me_b1(ov_err, arg1, arg2, fdiv_tag));
408
    exp r = hold_check(me_b1(ov_err, arg1, arg2, fdiv_tag));
369
    if (!optop(r) && name(sh(r))==doublehd) {
409
    if (!optop(r) && name(sh(r)) == doublehd) {
370
      exp id = me_startid(sh(r),r,0);
410
      exp id = me_startid(sh(r), r, 0);
371
      exp tmp = me_complete_id(id,me_obtain(id));
411
      exp tmp = me_complete_id(id, me_obtain(id));
372
      return tmp;
412
      return tmp;
373
     }
-
 
374
    else
413
     } else {
375
      return r;
414
      return r;
-
 
415
     }
376
  }
416
  }
-
 
417
#endif
-
 
418
  return hold_check(me_b1(ov_err, arg1, arg2, fdiv_tag));
-
 
419
}
-
 
420
 
-
 
421
 
-
 
422
exp
-
 
423
f_floating_maximum(error_treatment flpt_err, exp arg1, exp arg2)
-
 
424
{
-
 
425
  if (name(sh(arg1)) == bothd) {
-
 
426
    kill_exp(arg2, arg2);
-
 
427
    return arg1;
-
 
428
  }
-
 
429
  if (name(sh(arg2)) == bothd) {
-
 
430
    kill_exp(arg1, arg1);
-
 
431
    return arg2;
-
 
432
  }
-
 
433
 
-
 
434
#if check_shape
-
 
435
  if (!is_float(sh(arg1)) || !eq_shape(sh(arg1), sh(arg2))) {
-
 
436
    failer(CHSH_FLMAX);
-
 
437
  }
377
#endif
438
#endif
378
  return  hold_check(me_b1(ov_err, arg1, arg2, fdiv_tag));
439
  return hold_check(me_b1(flpt_err, arg1, arg2, fmax_tag));
379
}
440
}
380
 
441
 
381
 
442
 
382
exp f_floating_maximum
443
exp
383
    PROTO_N ( (flpt_err, arg1, arg2) )
-
 
384
    PROTO_T ( error_treatment flpt_err X exp arg1 X exp arg2 )
444
f_floating_minimum(error_treatment flpt_err, exp arg1, exp arg2)
385
{
445
{
386
  if (name(sh(arg1)) == bothd)
446
  if (name(sh(arg1)) == bothd) {
387
    { kill_exp(arg2,arg2); return arg1; }
447
    kill_exp(arg2, arg2);
-
 
448
    return arg1;
-
 
449
  }
388
  if (name(sh(arg2)) == bothd)
450
  if (name(sh(arg2)) == bothd) {
389
    { kill_exp(arg1,arg1); return arg2; }
451
    kill_exp(arg1, arg1);
-
 
452
    return arg2;
-
 
453
  }
-
 
454
 
390
 
455
 
391
#if check_shape
456
#if check_shape
392
  if (!is_float(sh(arg1)) || !eq_shape(sh(arg1), sh(arg2)))
457
  if (!is_float(sh(arg1)) || !eq_shape(sh(arg1), sh(arg2))) {
393
    failer(CHSH_FLMAX);
-
 
394
#endif
-
 
395
  return  hold_check(me_b1(flpt_err, arg1, arg2, fmax_tag));
-
 
396
}
-
 
397
 
-
 
398
 
-
 
399
exp f_floating_minimum
-
 
400
    PROTO_N ( (flpt_err, arg1, arg2) )
-
 
401
    PROTO_T ( error_treatment flpt_err X exp arg1 X exp arg2 )
-
 
402
{
-
 
403
  if (name(sh(arg1)) == bothd)
-
 
404
    { kill_exp(arg2,arg2); return arg1; }
-
 
405
  if (name(sh(arg2)) == bothd)
-
 
406
    { kill_exp(arg1,arg1); return arg2; }
-
 
407
 
-
 
408
 
-
 
409
#if check_shape
-
 
410
  if (!is_float(sh(arg1)) || !eq_shape(sh(arg1), sh(arg2)))
-
 
411
    failer(CHSH_FLMIN);
458
    failer(CHSH_FLMIN);
-
 
459
  }
412
#endif
460
#endif
413
  return  hold_check(me_b1(flpt_err, arg1, arg2, fmin_tag));
461
  return hold_check(me_b1(flpt_err, arg1, arg2, fmin_tag));
414
}
462
}
415
 
463
 
416
 
464
 
417
 
465
 
418
 
466
 
419
/****************************************************************/
467
/****************************************************************/
420
/*  The following code needs to generate labels for use with    */
468
/*  The following code needs to generate labels for use with    */
421
/*  'cond_tag'.  This is currently implemented using the        */
469
/*  'cond_tag'.  This is currently implemented using the        */
422
/*  knowledge that a label can be obtained by taking a pointer  */
470
/*  knowledge that a label can be obtained by taking a pointer  */
Line 425... Line 473...
425
/*  hack is performed exclusively by the MACRO 'make_label'     */
473
/*  hack is performed exclusively by the MACRO 'make_label'     */
426
/****************************************************************/
474
/****************************************************************/
427
 
475
 
428
#define make_label(EXP) &EXP
476
#define make_label(EXP) &EXP
429
 
477
 
430
 
478
 
431
/************************************************/
479
/************************************************/
432
/*  'is_constant_arg' checks to see if E1 is    */
480
/*  'is_constant_arg' checks to see if E1 is    */
433
/*   a constant that will fit into type 'int'.  */
481
/*   a constant that will fit into type 'int'.  */
434
/************************************************/
482
/************************************************/
435
 
483
 
436
#define is_constant_arg(E1) \
484
#define is_constant_arg(E1)\
437
	((name(E1) == val_tag) && !isbigval(E1) && \
485
	((name(E1) == val_tag) && !isbigval(E1) && \
438
	(is_signed(sh(E1)) || (no(E1) >> 31 == 0)))
486
	(is_signed(sh(E1)) || (no(E1) >> 31 == 0)))
439
 
487
 
440
 
488
 
441
 
489
 
442
exp f_floating_power
490
exp
443
    PROTO_N ( (ov_err, arg1, arg2) )
-
 
444
    PROTO_T ( error_treatment ov_err X exp arg1 X exp arg2 )
491
f_floating_power(error_treatment ov_err, exp arg1, exp arg2)
445
{
492
{
446
  if (name(sh(arg1)) == bothd)
493
  if (name(sh(arg1)) == bothd) {
447
    { kill_exp(arg2,arg2); return arg1; }
494
    kill_exp(arg2,arg2);
-
 
495
    return arg1;
-
 
496
  }
448
  if (name(sh(arg2)) == bothd)
497
  if (name(sh(arg2)) == bothd) {
449
    { kill_exp(arg1,arg1); return arg2; }
498
    kill_exp(arg1,arg1);
-
 
499
    return arg2;
-
 
500
  }
450
 
501
 
451
#if check_shape
502
#if check_shape
452
  if (!( (is_float(sh(arg1)) || is_complex(sh(arg1))) && is_integer(sh(arg2)) ))
503
  if (!((is_float(sh(arg1)) || is_complex(sh(arg1))) &&
-
 
504
	is_integer(sh(arg2)))) {
453
    failer(CHSH_FLPOWER);
505
    failer(CHSH_FLPOWER);
-
 
506
  }
454
#endif
507
#endif
455
 
508
 
456
/* PAB changes - 31 October 1994 */
509
/* PAB changes - 31 October 1994 */
457
 
510
 
458
  /* Gives shorter .s file if n<10 and arg1 is unknown */
511
  /* Gives shorter .s file if n<10 and arg1 is unknown */
459
 
512
 
460
  if (is_complex(sh(arg1))) {
513
  if (is_complex(sh(arg1))) {
461
 
514
 
462
      shape integer_shape = sh(arg2);
515
      shape integer_shape = sh(arg2);
463
      shape complex_shape = sh(arg1);                     /* shape of our complex numbers */
516
      shape complex_shape = sh(arg1);	/* shape of our complex numbers */
464
      floating_variety real_fv = f_float_of_complex(complex_shape);
517
      floating_variety real_fv = f_float_of_complex(complex_shape);
465
      shape real_shape = f_floating(real_fv);
518
      shape real_shape = f_floating(real_fv);
466
      floating_variety complex_fv = f_complex_of_float(real_shape);
519
      floating_variety complex_fv = f_complex_of_float(real_shape);
467
 
520
 
468
      exp sn = me_startid(integer_shape, arg2, 0);
521
      exp sn = me_startid(integer_shape, arg2, 0);
469
 
522
 
470
      if (is_constant_arg(arg2) ||
523
      if (is_constant_arg(arg2) ||
471
	((name(arg2) == name_tag) && (name(son(arg2)) == ident_tag)
524
	((name(arg2) == name_tag) && (name(son(arg2)) == ident_tag)
472
	   && !isvar(son(arg2)) && is_constant_arg(son(son(arg2)))))
525
	   && !isvar(son(arg2)) && is_constant_arg(son(son(arg2))))) {
473
      {                                                              /* we know the power */
526
	  /* we know the power */
474
	  int n;
527
	  int n;
475
	  int exponent;
528
	  int exponent;
476
	  exp z = push (sn, me_startid(complex_shape, arg1, 0));
529
	  exp z = push(sn, me_startid(complex_shape, arg1, 0));
477
 
530
 
478
	  if (is_constant_arg(arg2)) {
531
	  if (is_constant_arg(arg2)) {
479
	      exponent = no(arg2);	/* arg2 is a constant */
532
	      exponent = no(arg2);	/* arg2 is a constant */
480
	  }
-
 
481
	  else {
533
	  } else {
482
	      exponent = no(son(son(arg2)));
534
	      exponent = no(son(son(arg2)));
483
		  /* arg2 identifies a constant */
535
	      /* arg2 identifies a constant */
484
	  }
536
	  }
485
 
537
 
486
	  n = abs(exponent);
538
	  n = abs(exponent);
487
	  if (n == 0) {
539
	  if (n == 0) {
488
 
-
 
489
	      exp  answer_re, answer_im, make_comp;
540
	      exp answer_re, answer_im, make_comp;
490
 
541
 
491
	      flpt fzero_copy = new_flpt();
542
	      flpt fzero_copy = new_flpt();
492
	      flpt fone_copy  = new_flpt();
543
	      flpt fone_copy = new_flpt();
493
 
-
 
494
	      flt_copy (flptnos[fzero_no], &flptnos[fzero_copy]);
-
 
495
	      flt_copy (flptnos[fone_no],  &flptnos[fone_copy]);
-
 
496
 
-
 
497
	      answer_re = getexp(real_shape, nilexp, 1, nilexp, nilexp, 0, fone_copy,  real_tag);
-
 
498
	      answer_im = getexp(real_shape, nilexp, 1, nilexp, nilexp, 0, fzero_copy, real_tag);
-
 
499
 
-
 
500
	      make_comp = f_make_complex(complex_fv, answer_re, answer_im);
-
 
501
	      return  me_complete_chain(z, arg2, make_comp);
-
 
502
 
544
 
-
 
545
	      flt_copy(flptnos[fzero_no], &flptnos[fzero_copy]);
-
 
546
	      flt_copy(flptnos[fone_no], &flptnos[fone_copy]);
-
 
547
 
-
 
548
	      answer_re = getexp(real_shape, nilexp, 1, nilexp, nilexp, 0,
-
 
549
				 fone_copy, real_tag);
-
 
550
	      answer_im = getexp(real_shape, nilexp, 1, nilexp, nilexp, 0,
-
 
551
				 fzero_copy, real_tag);
-
 
552
 
-
 
553
	      make_comp = f_make_complex(complex_fv, answer_re, answer_im);
-
 
554
	      return me_complete_chain(z, arg2, make_comp);
503
	  } else {
555
	  } else {
504
 
-
 
505
	      exp link_next;
556
	      exp link_next;
506
 
557
 
507
	      exp z_re = f_real_part     (me_obtain(z));
558
	      exp z_re = f_real_part(me_obtain(z));
508
	      exp z_im = f_imaginary_part(me_obtain(z));
559
	      exp z_im = f_imaginary_part(me_obtain(z));
509
 
-
 
510
	      exp x = push (z, me_startid(real_shape, z_re, 0));
-
 
511
	      exp y = push (x, me_startid(real_shape, z_im, 0));
-
 
512
 
560
 
-
 
561
	      exp x = push(z, me_startid(real_shape, z_re, 0));
-
 
562
	      exp y = push(x, me_startid(real_shape, z_im, 0));
-
 
563
 
513
	      exp u, v, mylast;;
564
	      exp u, v, mylast;;
514
 
565
 
515
	      while ((n % 2) == 0) {
566
	      while ((n % 2) == 0) {
516
		  mylast = y;
567
		  mylast = y;
517
		  square_x_iy(ov_err, &x, &y, mylast);
568
		  square_x_iy(ov_err, &x, &y, mylast);
518
		  n = n / 2;
569
		  n = n / 2;
519
	      }
570
	      }
520
 
571
 
521
	      if (n == 1) {                                                   /* return z */
572
	      if (n == 1) {
522
 
-
 
-
 
573
		  /* return z */
523
		  if (exponent < 0) {
574
		  if (exponent < 0) {
524
		      link_next = make_comp_1_z(complex_fv, ov_err,
575
		      link_next = make_comp_1_z(complex_fv, ov_err,
525
						me_obtain(x), me_obtain(x), me_obtain(x),
576
						me_obtain(x), me_obtain(x),
-
 
577
						me_obtain(x), me_obtain(y),
526
						me_obtain(y), me_obtain(y), me_obtain(y));
578
						me_obtain(y), me_obtain(y));
527
		  } else {
579
		  } else {
528
		      link_next = f_make_complex(complex_fv, me_obtain(x), me_obtain(y));
580
		      link_next = f_make_complex(complex_fv, me_obtain(x),
-
 
581
						 me_obtain(y));
529
		  }
582
		  }
530
 
-
 
531
		  return me_complete_chain(y, arg2, link_next);             /*  return z  */
-
 
532
 
-
 
533
	      } else {                           	                       /*  w = z  */
-
 
534
 
583
 
-
 
584
		  return me_complete_chain(y, arg2, link_next); /*  return z  */
-
 
585
	      } else {
-
 
586
		  /*  w = z  */
535
		  u = push (y, me_startid(real_shape, me_obtain(x), 0));
587
		  u = push(y, me_startid(real_shape, me_obtain(x), 0));
536
		  v = push (u, me_startid(real_shape, me_obtain(y), 0));
588
		  v = push(u, me_startid(real_shape, me_obtain(y), 0));
537
		  mylast = v;
589
		  mylast = v;
538
	      }
590
	      }
539
 
591
 
540
	      while (n != 1) {
592
	      while (n != 1) {
-
 
593
		  /*  z = z*z  */
541
		  square_x_iy(ov_err, &x, &y, mylast);                         /*  z = z*z  */
594
		  square_x_iy(ov_err, &x, &y, mylast);
542
		  mylast = y;
595
		  mylast = y;
543
		  n = n / 2;
596
		  n = n / 2;
544
		  if ((n % 2) == 1) {
597
		  if ((n % 2) == 1) {
-
 
598
		      /*  w = w*z  */
545
		      mult_w_by_z (ov_err, &u, &v, x, y, mylast);              /*  w = w*z  */
599
		      mult_w_by_z (ov_err, &u, &v, x, y, mylast);
546
		      mylast = v;
600
		      mylast = v;
547
		  }
601
		  }
548
	      }
602
	      }
549
 
603
 
550
	      if (exponent < 0) {
604
	      if (exponent < 0) {
551
		  link_next = make_comp_1_z(complex_fv, ov_err,
605
		  link_next = make_comp_1_z(complex_fv, ov_err,
552
					    me_obtain(u), me_obtain(u), me_obtain(u),
606
					    me_obtain(u), me_obtain(u),
-
 
607
					    me_obtain(u), me_obtain(v),
553
					    me_obtain(v), me_obtain(v), me_obtain(v));
608
					    me_obtain(v), me_obtain(v));
554
	      } else {
609
	      } else {
555
		  link_next = f_make_complex(complex_fv, me_obtain(u), me_obtain(v));
610
		  link_next = f_make_complex(complex_fv, me_obtain(u), me_obtain(v));
556
	      }
611
	      }
-
 
612
	      /* return w */
557
	      return me_complete_chain(v, arg2, link_next);                /*  return w  */
613
	      return me_complete_chain(v, arg2, link_next);
558
	  }
614
	  }
559
 
-
 
560
      } else {
615
      } else {
561
 
-
 
-
 
616
	  /* main building blocks */
562
	  exp  reinitialise_w, main_loop, make_comp;              /* main building blocks */
617
	  exp reinitialise_w, main_loop, make_comp;
563
	  exp  square_z, mult_z_w, half_n, update_w, repeat_body;
618
	  exp square_z, mult_z_w, half_n, update_w, repeat_body;
564
	  exp  seq, seq_zero, make_comp1, make_comp2;
619
	  exp seq, seq_zero, make_comp1, make_comp2;
565
	  exp  real0, real1, x, y, u, v;
620
	  exp real0, real1, x, y, u, v;
566
 
621
 
567
	  exp z  = me_startid(complex_shape, arg1, 0);
622
	  exp z = me_startid(complex_shape, arg1, 0);
568
 
623
 
569
	  exp abs_val_sn = f_abs(ov_err, me_obtain(sn));
624
	  exp abs_val_sn = f_abs(ov_err, me_obtain(sn));
570
	  exp n = me_startid(sh(sn), abs_val_sn, 1);
625
	  exp n = me_startid(sh(sn), abs_val_sn, 1);
571
 
626
 
572
	  exp z_re = f_real_part     (me_obtain(z));
627
	  exp z_re = f_real_part(me_obtain(z));
573
	  exp z_im = f_imaginary_part(me_obtain(z));
628
	  exp z_im = f_imaginary_part(me_obtain(z));
574
 
629
 
575
	  flpt fzero_copy = new_flpt();
630
	  flpt fzero_copy = new_flpt();
576
	  flpt fone_copy  = new_flpt();
631
	  flpt fone_copy = new_flpt();
577
 
632
 
578
	  flt_copy (flptnos[fzero_no], &flptnos[fzero_copy]);
633
	  flt_copy(flptnos[fzero_no], &flptnos[fzero_copy]);
579
	  flt_copy (flptnos[fone_no],  &flptnos[fone_copy]);
634
	  flt_copy(flptnos[fone_no], &flptnos[fone_copy]);
580
 
635
 
581
	  real0 = getexp(real_shape, nilexp, 1, nilexp, nilexp, 0, fzero_copy, real_tag);
636
	  real0 = getexp(real_shape, nilexp, 1, nilexp, nilexp, 0, fzero_copy,
-
 
637
			 real_tag);
582
	  real1 = getexp(real_shape, nilexp, 1, nilexp, nilexp, 0, fone_copy,  real_tag);
638
	  real1 = getexp(real_shape, nilexp, 1, nilexp, nilexp, 0, fone_copy,
-
 
639
			 real_tag);
583
 
640
 
584
	  x = me_startid(real_shape, z_re, 1);                                /* re(arg1) */
641
	  x = me_startid(real_shape, z_re, 1);	/* re(arg1) */
585
	  y = me_startid(real_shape, z_im, 1);                                /* re(arg2) */
642
	  y = me_startid(real_shape, z_im, 1);	/* re(arg2) */
586
 
643
 
587
	  u = me_startid(real_shape, real1, 1);                            /* re(w) = 1.0 */
644
	  u = me_startid(real_shape, real1, 1);	/* re(w) = 1.0 */
588
	  v = me_startid(real_shape, real0, 1);                            /* im(w) = 0.0 */
645
	  v = me_startid(real_shape, real0, 1);	/* im(w) = 0.0 */
589
 
646
 
590
 
647
 
591
	  /*  change value of w to z if n is odd  */
648
	  /*  change value of w to z if n is odd  */
592
 
649
 
593
	  {
650
	  {
594
	      exp constant1  = me_shint(integer_shape, 1);
651
	      exp constant1 = me_shint(integer_shape, 1);
595
	      exp constant2  = me_shint(integer_shape, 2);
652
	      exp constant2 = me_shint(integer_shape, 2);
596
 
653
 
597
	      exp rem_n_2    = f_rem0 (f_impossible, f_impossible,
654
	      exp rem_n_2 = f_rem0(f_impossible, f_impossible, me_contents(n),
598
				       me_contents(n), constant2);
655
				   constant2);
599
 
656
 
600
	      exp assign_u = hold_check(me_b3(f_top, me_obtain(u), me_contents(x), ass_tag));
657
	      exp assign_u = hold_check(me_b3(f_top, me_obtain(u),
-
 
658
					      me_contents(x), ass_tag));
601
	      exp assign_v = hold_check(me_b3(f_top, me_obtain(v), me_contents(y), ass_tag));
659
	      exp assign_v = hold_check(me_b3(f_top, me_obtain(v),
-
 
660
					      me_contents(y), ass_tag));
602
 
661
 
603
	      exp top_cell  = me_l1(f_top, top_tag);
662
	      exp top_cell = me_l1(f_top, top_tag);
604
	      exp alt_labst = hold_check(me_b3(sh(top_cell), me_null(f_top,0,clear_tag),
663
	      exp alt_labst = hold_check(me_b3(sh(top_cell),
-
 
664
					       me_null(f_top, 0, clear_tag),
605
					       top_cell, labst_tag));
665
					       top_cell, labst_tag));
606
 
666
 
607
	      exp is_n_odd = f_integer_test (no_nat_option, f_equal,
667
	      exp is_n_odd = f_integer_test(no_nat_option, f_equal,
608
					     make_label(alt_labst), rem_n_2, constant1);
668
					    make_label(alt_labst), rem_n_2,
-
 
669
					    constant1);
609
 
670
 
610
	      exp seq_zero = hold_check(me_b2(is_n_odd, assign_u, 0));
671
	      exp seq_zero = hold_check(me_b2(is_n_odd, assign_u, 0));
611
	      exp seq = hold_check(me_b3(sh(assign_v), seq_zero, assign_v, seq_tag));
672
	      exp seq = hold_check(me_b3(sh(assign_v), seq_zero, assign_v,
-
 
673
					 seq_tag));
612
 
674
 
613
	      reinitialise_w = hold_check(me_b3(lub_shape(sh(seq),sh(alt_labst)),
675
	      reinitialise_w = hold_check(me_b3(lub_shape(sh(seq),
-
 
676
							  sh(alt_labst)),
614
						seq, alt_labst, cond_tag));
677
						seq, alt_labst, cond_tag));
615
	  }
678
	  }
616
 
679
 
617
 
680
 
618
	  /*  z=z*z  */
681
	  /*  z=z*z  */
619
 
682
 
620
	  {
683
	  {
621
	      exp minus_x_y = f_floating_minus(ov_err, me_contents(x), me_contents(y));
684
	      exp minus_x_y = f_floating_minus(ov_err, me_contents(x),
-
 
685
					       me_contents(y));
622
	      exp  plus_x_y = f_bin_floating_plus(ov_err, me_contents(x), me_contents(y));
686
	      exp  plus_x_y = f_bin_floating_plus(ov_err, me_contents(x),
-
 
687
						  me_contents(y));
623
	      exp  mult_x_y = f_bin_floating_mult(ov_err, me_contents(x), me_contents(y));
688
	      exp  mult_x_y = f_bin_floating_mult(ov_err, me_contents(x),
-
 
689
						  me_contents(y));
624
 
690
 
625
	      exp tmp = me_startid(real_shape, mult_x_y, 0);
691
	      exp tmp = me_startid(real_shape, mult_x_y, 0);
626
 
692
 
627
	      exp answer_re  = f_bin_floating_mult(ov_err, minus_x_y, plus_x_y);
693
	      exp answer_re = f_bin_floating_mult(ov_err, minus_x_y, plus_x_y);
628
	      exp answer_im  = f_bin_floating_plus(ov_err, me_obtain(tmp), me_obtain(tmp));
694
	      exp answer_im = f_bin_floating_plus(ov_err, me_obtain(tmp),
-
 
695
						   me_obtain(tmp));
629
 
696
 
630
	      exp assign_x = hold_check(me_b3(f_top, me_obtain(x), answer_re, ass_tag));
697
	      exp assign_x = hold_check(me_b3(f_top, me_obtain(x), answer_re,
-
 
698
					      ass_tag));
631
	      exp assign_y = hold_check(me_b3(f_top, me_obtain(y), answer_im, ass_tag));
699
	      exp assign_y = hold_check(me_b3(f_top, me_obtain(y), answer_im,
-
 
700
					      ass_tag));
632
 
701
 
633
	      exp seq_zero = hold_check(me_u2(assign_x, 0));
702
	      exp seq_zero = hold_check(me_u2(assign_x, 0));
634
	      exp seq      = hold_check(me_b3(sh(assign_y), seq_zero, assign_y, seq_tag));
703
	      exp seq = hold_check(me_b3(sh(assign_y), seq_zero, assign_y,
-
 
704
					 seq_tag));
635
 
705
 
636
	      square_z = me_complete_id(tmp, seq);
706
	      square_z = me_complete_id(tmp, seq);
637
	  }
707
	  }
638
 
708
 
639
 
709
 
640
	  /*  w=z*w  */
710
	  /*  w=z*w  */
641
 
-
 
642
	  {
711
	  {
643
	      exp mult_x_u = f_bin_floating_mult(ov_err, me_contents(x), me_contents(u));
712
	      exp mult_x_u = f_bin_floating_mult(ov_err, me_contents(x),
-
 
713
						 me_contents(u));
644
	      exp mult_x_v = f_bin_floating_mult(ov_err, me_contents(x), me_contents(v));
714
	      exp mult_x_v = f_bin_floating_mult(ov_err, me_contents(x),
-
 
715
						 me_contents(v));
645
	      exp mult_y_u = f_bin_floating_mult(ov_err, me_contents(y), me_contents(u));
716
	      exp mult_y_u = f_bin_floating_mult(ov_err, me_contents(y),
-
 
717
						 me_contents(u));
646
	      exp mult_y_v = f_bin_floating_mult(ov_err, me_contents(y), me_contents(v));
718
	      exp mult_y_v = f_bin_floating_mult(ov_err, me_contents(y),
-
 
719
						 me_contents(v));
647
 
720
 
648
	      exp tmp = me_startid(real_shape, mult_y_u, 0);
721
	      exp tmp = me_startid(real_shape, mult_y_u, 0);
649
 
722
 
650
	      exp answer_re  = f_floating_minus(ov_err, mult_x_u, mult_y_v);
723
	      exp answer_re = f_floating_minus(ov_err, mult_x_u, mult_y_v);
651
	      exp answer_im  = f_bin_floating_plus(ov_err, mult_x_v, me_obtain(tmp));
724
	      exp answer_im = f_bin_floating_plus(ov_err, mult_x_v,
-
 
725
						  me_obtain(tmp));
652
 
726
 
653
	      exp assign_u = hold_check(me_b3(f_top, me_obtain(u), answer_re, ass_tag));
727
	      exp assign_u = hold_check(me_b3(f_top, me_obtain(u), answer_re,
-
 
728
					      ass_tag));
654
	      exp assign_v = hold_check(me_b3(f_top, me_obtain(v), answer_im, ass_tag));
729
	      exp assign_v = hold_check(me_b3(f_top, me_obtain(v), answer_im,
-
 
730
					      ass_tag));
655
 
731
 
656
	      exp seq_zero = hold_check(me_u2(assign_u, 0));
732
	      exp seq_zero = hold_check(me_u2(assign_u, 0));
657
	      exp seq      = hold_check(me_b3(sh(assign_v), seq_zero, assign_v, seq_tag));
733
	      exp seq = hold_check(me_b3(sh(assign_v), seq_zero, assign_v,
-
 
734
					 seq_tag));
658
 
735
 
659
	      mult_z_w = me_complete_id(tmp, seq);
736
	      mult_z_w = me_complete_id(tmp, seq);
660
	  }
737
	  }
661
 
738
 
662
 
739
 
663
	  /*  n=n/2  */
740
	  /*  n = n / 2  */
-
 
741
 
-
 
742
	  {
-
 
743
	      exp constant2 = me_shint(integer_shape, 2);
-
 
744
 
-
 
745
	      exp answer = f_div0(f_impossible, f_impossible, me_contents(n),
-
 
746
				  constant2);
-
 
747
	      half_n = hold_check(me_b3(f_top, me_obtain(n), answer, ass_tag));
-
 
748
	  }
-
 
749
 
-
 
750
 
-
 
751
	  /*  if n is odd then w = z * w  */
664
 
752
 
665
	  {
753
	  {
-
 
754
	      exp constant1 = me_shint(integer_shape, 1);
666
	      exp constant2  = me_shint(integer_shape, 2);
755
	      exp constant2 = me_shint(integer_shape, 2);
667
 
756
 
668
	      exp answer = f_div0 (f_impossible, f_impossible,
-
 
669
				   me_contents(n), constant2);
-
 
670
	      half_n = hold_check(me_b3(f_top, me_obtain(n), answer, ass_tag));
-
 
671
	  }
-
 
672
 
-
 
673
 
-
 
674
	  /*  if n is odd then w = z*w  */
-
 
675
 
-
 
676
	  {
-
 
677
	      exp constant1  = me_shint(integer_shape, 1);
-
 
678
	      exp constant2  = me_shint(integer_shape, 2);
-
 
679
 
-
 
680
	      exp rem_n_2    = f_rem0 (f_impossible, f_impossible,
757
	      exp rem_n_2 = f_rem0(f_impossible, f_impossible, me_contents(n),
681
				       me_contents(n), constant2);
758
				   constant2);
682
 
759
 
683
	      exp top_cell  = me_l1(f_top, top_tag);
760
	      exp top_cell = me_l1(f_top, top_tag);
684
	      exp alt_labst = hold_check(me_b3(f_top, me_null(f_top,0,clear_tag),
761
	      exp alt_labst = hold_check(me_b3(f_top, me_null(f_top, 0,
-
 
762
							      clear_tag),
685
					       top_cell, labst_tag));
763
					       top_cell, labst_tag));
686
 
764
 
687
	      exp is_n_odd = f_integer_test (no_nat_option, f_equal,
765
	      exp is_n_odd = f_integer_test(no_nat_option, f_equal,
688
					     make_label(alt_labst), rem_n_2, constant1);
766
					    make_label(alt_labst), rem_n_2,
-
 
767
					    constant1);
689
	      exp seq_zero = hold_check(me_u2(is_n_odd, 0));
768
	      exp seq_zero = hold_check(me_u2(is_n_odd, 0));
690
	      exp seq = hold_check(me_b3(sh(mult_z_w), seq_zero, mult_z_w, seq_tag));
769
	      exp seq = hold_check(me_b3(sh(mult_z_w), seq_zero, mult_z_w,
-
 
770
					 seq_tag));
691
 
771
 
692
	      update_w = hold_check(me_b3(lub_shape(sh(seq),sh(alt_labst)),
772
	      update_w = hold_check(me_b3(lub_shape(sh(seq), sh(alt_labst)),
693
					  seq, alt_labst, cond_tag));
773
					  seq, alt_labst, cond_tag));
694
	  }
774
	  }
695
 
775
 
696
 
776
 
697
	  /*  repeat + body  */
777
	  /*  repeat + body  */
698
 
778
 
699
	  {
779
	  {
700
	      exp if_n_equals_1, seq_zero, seq, body_labst;
780
	      exp if_n_equals_1, seq_zero, seq, body_labst;
701
 
781
 
702
	      exp constant1  = me_shint(integer_shape, 1);
782
	      exp constant1 = me_shint(integer_shape, 1);
703
	      exp top_cell   = me_l1(f_top, top_tag);
783
	      exp top_cell = me_l1(f_top, top_tag);
704
 
784
 
705
	      body_labst = hold_check(me_b3(sh(top_cell), me_null(f_top,0,clear_tag),
785
	      body_labst = hold_check(me_b3(sh(top_cell),
-
 
786
					    me_null(f_top, 0, clear_tag),
706
                                            top_cell, labst_tag));
787
					    top_cell, labst_tag));
707
 
788
 
708
	      if_n_equals_1 = f_integer_test (no_nat_option, f_equal, make_label(body_labst),
789
	      if_n_equals_1 = f_integer_test(no_nat_option, f_equal,
-
 
790
					     make_label(body_labst),
709
					      me_contents(n), constant1);
791
					     me_contents(n), constant1);
710
 
792
 
711
	      seq_zero = me_b2(square_z, update_w, 0);
793
	      seq_zero = me_b2(square_z, update_w, 0);
712
	      setbro (square_z, half_n);                   /*  insert half_n between   */
794
	      setbro(square_z, half_n);	/*  insert half_n between   */
713
	      setbro (half_n, update_w);                   /*  square_x and update_w   */
795
	      setbro(half_n, update_w);	/*  square_x and update_w   */
714
	      clearlast (half_n);
796
	      clearlast(half_n);
715
	      seq_zero = hold_check(seq_zero);
797
	      seq_zero = hold_check(seq_zero);
716
 
798
 
717
	      seq = hold_check(me_b3(sh(if_n_equals_1), seq_zero, if_n_equals_1, seq_tag));
799
	      seq = hold_check(me_b3(sh(if_n_equals_1), seq_zero,
-
 
800
				     if_n_equals_1, seq_tag));
718
 
801
 
719
	      setbro(son(body_labst), seq);
802
	      setbro(son(body_labst), seq);
720
	      clearlast(son(body_labst));
803
	      clearlast(son(body_labst));
721
	      setfather(body_labst, seq);
804
	      setfather(body_labst, seq);
722
 
805
 
723
	      repeat_body = hold_check(me_b3(sh(seq), top_cell, body_labst, rep_tag));
806
	      repeat_body = hold_check(me_b3(sh(seq), top_cell, body_labst,
-
 
807
					     rep_tag));
724
	      note_repeat(repeat_body);
808
	      note_repeat(repeat_body);
725
	  }
809
	  }
726
 
810
 
727
 
811
 
728
	  /*  make loop - only done if  mod(n) > 1  */
812
	  /*  make loop - only done if  mod(n) > 1  */
729
 
813
 
730
	  {
814
	  {
731
	      exp constant1  = me_shint(integer_shape, 1);
815
	      exp constant1 = me_shint(integer_shape, 1);
732
 
816
 
733
	      exp top_cell  = me_l1(f_top, top_tag);
817
	      exp top_cell = me_l1(f_top, top_tag);
734
	      exp alt_labst = hold_check(me_b3(f_top, me_null(f_top,0,clear_tag),
818
	      exp alt_labst = hold_check(me_b3(f_top,
-
 
819
					       me_null(f_top, 0, clear_tag),
735
					       top_cell, labst_tag));
820
					       top_cell, labst_tag));
736
 
821
 
737
	      exp is_n_gt_1 = f_integer_test (no_nat_option, f_greater_than,
822
	      exp is_n_gt_1 = f_integer_test(no_nat_option, f_greater_than,
-
 
823
					     make_label(alt_labst),
738
					      make_label(alt_labst), me_contents(n), constant1);
824
					     me_contents(n), constant1);
739
 
825
 
740
	      exp seq_zero = hold_check(me_u2(is_n_gt_1, 0));
826
	      exp seq_zero = hold_check(me_u2(is_n_gt_1, 0));
741
	      exp seq = hold_check(me_b3(sh(repeat_body), seq_zero, repeat_body, seq_tag));
827
	      exp seq = hold_check(me_b3(sh(repeat_body), seq_zero,
-
 
828
					 repeat_body, seq_tag));
742
 
829
 
743
	      main_loop = hold_check(me_b3(lub_shape(sh(seq),sh(alt_labst)),
830
	      main_loop = hold_check(me_b3(lub_shape(sh(seq),sh(alt_labst)),
744
					   seq, alt_labst, cond_tag));
831
					   seq, alt_labst, cond_tag));
745
	  }
832
	  }
746
 
833
 
747
	  make_comp1 = f_make_complex(complex_fv, me_contents(u), me_contents(v));
834
	  make_comp1 = f_make_complex(complex_fv, me_contents(u),
-
 
835
				      me_contents(v));
748
	  make_comp2 = make_comp_1_z(complex_fv, ov_err,
836
	  make_comp2 = make_comp_1_z(complex_fv, ov_err, me_contents(u),
749
                                     me_contents(u), me_contents(u), me_contents(u),
837
				     me_contents(u), me_contents(u),
750
                                     me_contents(v), me_contents(v), me_contents(v));
838
				     me_contents(v), me_contents(v),
-
 
839
				     me_contents(v));
751
 
840
 
752
 
841
 
753
	  /* if arg2 is negative then make_comp2 else make_comp1 */
842
	  /* if arg2 is negative then make_comp2 else make_comp1 */
754
 
843
 
755
	  {
844
	  {
756
	      exp constant0 = me_shint(integer_shape, 0);
845
	      exp constant0 = me_shint(integer_shape, 0);
757
 
846
 
758
	      exp alt_labst = hold_check(me_b3(sh(make_comp1),
847
	      exp alt_labst = hold_check(me_b3(sh(make_comp1),
759
					       me_null(f_top,0,clear_tag),
848
					       me_null(f_top, 0, clear_tag),
760
					       make_comp1, labst_tag));
849
					       make_comp1, labst_tag));
761
 
850
 
762
	      exp is_arg2_negative = f_integer_test (no_nat_option, f_less_than,
851
	      exp is_arg2_negative = f_integer_test(no_nat_option, f_less_than,
763
						     make_label(alt_labst),
852
						    make_label(alt_labst),
764
						     me_obtain(sn), constant0);
853
						    me_obtain(sn), constant0);
765
 
854
 
766
	      exp seq_zero = hold_check(me_u2(is_arg2_negative, 0));
855
	      exp seq_zero = hold_check(me_u2(is_arg2_negative, 0));
767
	      exp seq = hold_check(me_b3(sh(make_comp2), seq_zero, make_comp2, seq_tag));
856
	      exp seq = hold_check(me_b3(sh(make_comp2), seq_zero, make_comp2,
-
 
857
					 seq_tag));
768
 
858
 
769
	      make_comp = hold_check(me_b3(lub_shape(sh(seq),sh(alt_labst)),
859
	      make_comp = hold_check(me_b3(lub_shape(sh(seq),sh(alt_labst)),
770
					   seq, alt_labst, cond_tag));
860
					   seq, alt_labst, cond_tag));
771
	  }
861
	  }
772
 
862
 
773
      seq_zero = hold_check(me_b2(reinitialise_w, main_loop, 0));
863
      seq_zero = hold_check(me_b2(reinitialise_w, main_loop, 0));
774
      seq      = hold_check(me_b3(sh(make_comp), seq_zero, make_comp, seq_tag));
864
      seq = hold_check(me_b3(sh(make_comp), seq_zero, make_comp, seq_tag));
775
 
865
 
776
 
866
 
777
      v  = me_complete_id(v, seq);
867
      v = me_complete_id(v, seq);
778
      u  = me_complete_id(u, v);
868
      u = me_complete_id(u, v);
779
      y  = me_complete_id(y, u);
869
      y = me_complete_id(y, u);
780
      x  = me_complete_id(x, y);
870
      x = me_complete_id(x, y);
781
      n  = me_complete_id(n, x);
871
      n = me_complete_id(n, x);
782
      sn = me_complete_id(sn, n);
872
      sn = me_complete_id(sn, n);
783
      z  = me_complete_id(z, sn);
873
      z = me_complete_id(z, sn);
784
 
874
 
785
      return z;
875
      return z;
786
      }
876
      }
787
  }
877
  }
788
 
878
 
789
  return  real_power(ov_err, arg1, arg2);
879
  return real_power(ov_err, arg1, arg2);
790
}
880
}
791
 
881
 
792
 
882
 
793
exp f_floating_minus
883
exp
794
    PROTO_N ( (ov_err, arg1, arg2) )
-
 
795
    PROTO_T ( error_treatment ov_err X exp arg1 X exp arg2 )
884
f_floating_minus(error_treatment ov_err, exp arg1, exp arg2)
796
{
885
{
797
  if (name(sh(arg1)) == bothd)
886
  if (name(sh(arg1)) == bothd) {
798
    { kill_exp(arg2,arg2); return arg1; }
887
    kill_exp(arg2, arg2);
-
 
888
    return arg1;
-
 
889
  }
799
  if (name(sh(arg2)) == bothd)
890
  if (name(sh(arg2)) == bothd) {
800
    { kill_exp(arg1,arg1); return arg2; }
891
    kill_exp(arg1,arg1);
-
 
892
    return arg2;
-
 
893
  }
801
 
894
 
802
#if check_shape
895
#if check_shape
803
  if (! ((is_float(sh(arg1)) || is_complex(sh(arg1))) && eq_shape(sh(arg1), sh(arg2))) )
896
  if (!((is_float(sh(arg1)) || is_complex(sh(arg1))) &&
-
 
897
	eq_shape(sh(arg1), sh(arg2)))) {
804
    failer(CHSH_FLMINUS);
898
    failer(CHSH_FLMINUS);
-
 
899
  }
805
#endif
900
#endif
806
 
901
 
807
/* PAB changes - 18 October 1994 */
902
/* PAB changes - 18 October 1994 */
808
#if substitute_complex
903
#if substitute_complex
809
  if (is_complex(sh(arg1))) {
904
  if (is_complex(sh(arg1))) {
810
 
-
 
811
      shape complex_shape = sh(arg1);                     /* shape of our complex numbers */
905
      shape complex_shape = sh(arg1);	/* shape of our complex numbers */
812
      floating_variety real_fv = f_float_of_complex(complex_shape);
906
      floating_variety real_fv = f_float_of_complex(complex_shape);
813
      shape real_shape = f_floating(real_fv);
907
      shape real_shape = f_floating(real_fv);
814
      floating_variety complex_fv = f_complex_of_float(real_shape);
908
      floating_variety complex_fv = f_complex_of_float(real_shape);
815
 
909
 
816
      exp z1 = me_startid(complex_shape, arg1, 0);
910
      exp z1 = me_startid(complex_shape, arg1, 0);
817
      exp z2 = me_startid(complex_shape, arg2, 0);
911
      exp z2 = me_startid(complex_shape, arg2, 0);
818
 
912
 
819
      exp x1 = f_real_part     (me_obtain(z1));                      /* re(arg1) */
913
      exp x1 = f_real_part(me_obtain(z1));	/* re(arg1) */
820
      exp x2 = f_real_part     (me_obtain(z2));                      /* re(arg2) */
914
      exp x2 = f_real_part(me_obtain(z2));	/* re(arg2) */
821
      exp y1 = f_imaginary_part(me_obtain(z1));                      /* im(arg1) */
915
      exp y1 = f_imaginary_part(me_obtain(z1));	/* im(arg1) */
822
      exp y2 = f_imaginary_part(me_obtain(z2));                      /* im(arg2) */
916
      exp y2 = f_imaginary_part(me_obtain(z2));	/* im(arg2) */
823
 
917
 
824
      exp minus_re  = f_floating_minus(ov_err, x1, x2);
918
      exp minus_re = f_floating_minus(ov_err, x1, x2);
825
      exp minus_im  = f_floating_minus(ov_err, y1, y2);
919
      exp minus_im = f_floating_minus(ov_err, y1, y2);
826
      exp make_comp = f_make_complex(complex_fv, minus_re, minus_im);
920
      exp make_comp = f_make_complex(complex_fv, minus_re, minus_im);
827
 
921
 
828
      z2 = me_complete_id(z2, make_comp);
922
      z2 = me_complete_id(z2, make_comp);
829
      z1 = me_complete_id(z1, z2);
923
      z1 = me_complete_id(z1, z2);
830
 
924
 
831
      return z1;
925
      return z1;
832
  };
926
  }
833
#endif
927
#endif
834
#if ishppa
928
#if ishppa
835
  {
929
  {
836
    exp r = hold_check(me_b1(ov_err, arg1, arg2, fminus_tag));
930
    exp r = hold_check(me_b1(ov_err, arg1, arg2, fminus_tag));
837
    if (!optop(r) && name(sh(r))==doublehd) {
931
    if (!optop(r) && name(sh(r)) == doublehd) {
838
      exp id = me_startid(sh(r),r,0);
932
      exp id = me_startid(sh(r), r, 0);
839
      exp tmp = me_complete_id(id,me_obtain(id));
933
      exp tmp = me_complete_id(id, me_obtain(id));
840
      return tmp;
934
      return tmp;
841
     }
-
 
842
    else
935
    } else {
843
      return r;
936
      return r;
-
 
937
    }
844
  }
938
  }
845
#endif
939
#endif
846
  return  hold_check(me_b1(ov_err, arg1, arg2, fminus_tag));
940
  return hold_check(me_b1(ov_err, arg1, arg2, fminus_tag));
847
}
941
}
848
 
942
 
849
 
943
 
850
exp f_floating_mult
944
exp
851
    PROTO_N ( (ov_err, arg1) )
-
 
852
    PROTO_T ( error_treatment ov_err X exp_list arg1 )
945
f_floating_mult(error_treatment ov_err, exp_list arg1)
853
{
946
{
854
  exp first = arg1.start;
947
  exp first = arg1.start;
855
  exp r = getexp (sh(first), nilexp, 0, first,
948
  exp r = getexp(sh(first), nilexp, 0, first, nilexp, 0, 0, fmult_tag);
856
                  nilexp,
-
 
857
                  0, 0, fmult_tag);
-
 
858
  if (name(sh(first)) == bothd || arg1.number == 1)
949
  if (name(sh(first)) == bothd || arg1.number == 1) {
859
    return first;
950
    return first;
-
 
951
  }
860
  clear_exp_list(arg1);
952
  clear_exp_list(arg1);
861
  seterrhandle(r, ov_err.err_code);
953
  seterrhandle(r, ov_err.err_code);
862
  if (isov(r))
954
  if (isov(r)) {
863
   setjmp_dest(r, get_lab(ov_err.jmp_dest));
955
    setjmp_dest(r, get_lab(ov_err.jmp_dest));
-
 
956
  }
864
 
957
 
865
#if check_shape
958
#if check_shape
-
 
959
  {
866
  {exp t = first;
960
    exp t = first;
867
   while (1)
961
    while (1) {
868
     {
-
 
869
       if (! ((is_float(sh(t)) || is_complex(sh(t))) && eq_shape(sh(t), sh(first))) )
962
      if (!((is_float(sh(t)) || is_complex(sh(t))) &&
-
 
963
	    eq_shape(sh(t), sh(first)))) {
870
         failer(CHSH_FLMULT);
964
         failer(CHSH_FLMULT);
-
 
965
      }
871
       if (t == arg1.end)
966
      if (t == arg1.end) {
-
 
967
	break;
872
         break;
968
      }
873
       t = bro(t);
969
      t = bro(t);
874
       if (name(sh(t)) == bothd)
970
      if (name(sh(t)) == bothd) {
875
         return t;
971
	return t;
876
     };
972
      }
-
 
973
    }
877
  };
974
  }
878
#endif
975
#endif
879
 
976
 
880
/* PAB changes - 19 October 1994 */
977
/* PAB changes - 19 October 1994 */
881
#if substitute_complex
978
#if substitute_complex
882
  if (is_complex(sh(arg1.start))) {
979
  if (is_complex(sh(arg1.start))) {
883
 
-
 
884
      shape complex_shape = sh(arg1.start);            /* shape of our complex numbers */
980
      shape complex_shape = sh(arg1.start); /* shape of our complex numbers */
885
      floating_variety real_fv = f_float_of_complex(complex_shape);
981
      floating_variety real_fv = f_float_of_complex(complex_shape);
886
      shape real_shape = f_floating(real_fv);
982
      shape real_shape = f_floating(real_fv);
887
      floating_variety complex_fv = f_complex_of_float(real_shape);
983
      floating_variety complex_fv = f_complex_of_float(real_shape);
888
 
984
 
889
      exp  x1, y1, x2, y2, z1, z1_re, z1_im, t, link_next, prod_re, prod_im;
985
      exp x1, y1, x2, y2, z1, z1_re, z1_im, t, link_next, prod_re, prod_im;
890
 
986
 
891
#if 0
987
#if 0
892
      arg1 = reorder_list(arg1, 1);              /* reorder so constants are at the front */
988
      arg1 = reorder_list(arg1, 1); /* reorder so constants are at the front */
893
#endif
989
#endif
894
 
990
 
895
      z1 = me_startid(complex_shape, arg1.start, 0);
991
      z1 = me_startid(complex_shape, arg1.start, 0);
896
 
992
 
897
      z1_re = f_real_part     (me_obtain(z1));                 /* re(arg1.first) */
993
      z1_re = f_real_part(me_obtain(z1));	/* re(arg1.first) */
898
      z1_im = f_imaginary_part(me_obtain(z1));                 /* im(arg1.first) */
994
      z1_im = f_imaginary_part(me_obtain(z1));	/* im(arg1.first) */
899
 
995
 
900
      x1 = push(z1, me_startid(real_shape, z1_re, 0));
996
      x1 = push(z1, me_startid(real_shape, z1_re, 0));
901
      y1 = push(x1, me_startid(real_shape, z1_im, 0));
997
      y1 = push(x1, me_startid(real_shape, z1_im, 0));
902
 
998
 
903
      t = arg1.start;
999
      t = arg1.start;
904
 
1000
 
905
      while (t != arg1.end) {
1001
      while (t != arg1.end) {
906
 
-
 
907
	  t = bro(t);
1002
	  t = bro(t);
908
	  z1 = push(y1, me_startid(complex_shape, t, 0));
1003
	  z1 = push(y1, me_startid(complex_shape, t, 0));
909
 
1004
 
910
	  z1_re = f_real_part     (me_obtain(z1));    /* contents of next */
1005
	  z1_re = f_real_part(me_obtain(z1));		/* contents of next */
911
	  z1_im = f_imaginary_part(me_obtain(z1));    /* list element     */
1006
	  z1_im = f_imaginary_part(me_obtain(z1));	/*   list element   */
912
 
1007
 
913
	  x2 = push(z1, me_startid(real_shape, z1_re, 0));
1008
	  x2 = push(z1, me_startid(real_shape, z1_re, 0));
914
	  y2 = push(x2, me_startid(real_shape, z1_im, 0));
1009
	  y2 = push(x2, me_startid(real_shape, z1_im, 0));
915
 
1010
 
916
	  if (eq_exp(x1,x2) && eq_exp(y1,y2)) {
1011
	  if (eq_exp(x1,x2) && eq_exp(y1,y2)) {
917
 
-
 
918
	      exp minus_x1_x2 = f_floating_minus(ov_err, me_obtain(x1), me_obtain(x2));
1012
	      exp minus_x1_x2 = f_floating_minus(ov_err, me_obtain(x1),
-
 
1013
						 me_obtain(x2));
919
	      exp  plus_x1_x2 = f_bin_floating_plus(ov_err, me_obtain(x1), me_obtain(x2));
1014
	      exp  plus_x1_x2 = f_bin_floating_plus(ov_err, me_obtain(x1),
-
 
1015
						    me_obtain(x2));
920
	      exp  mult_x1_y1 = f_bin_floating_mult(ov_err, me_obtain(x1), me_obtain(y1));
1016
	      exp  mult_x1_y1 = f_bin_floating_mult(ov_err, me_obtain(x1),
-
 
1017
						    me_obtain(y1));
921
 
1018
 
922
	      prod_re = f_bin_floating_mult(ov_err, minus_x1_x2, plus_x1_x2);
1019
	      prod_re = f_bin_floating_mult(ov_err, minus_x1_x2, plus_x1_x2);
923
	      prod_im = f_bin_floating_plus(ov_err,  mult_x1_y1, mult_x1_y1);
1020
	      prod_im = f_bin_floating_plus(ov_err, mult_x1_y1, mult_x1_y1);
924
	  }
-
 
925
 
-
 
926
	  else
1021
	  } else {
927
 
-
 
928
	  {
-
 
929
	      exp mult_x1_x2 = f_bin_floating_mult(ov_err, me_obtain(x1), me_obtain(x2));
1022
	      exp mult_x1_x2 = f_bin_floating_mult(ov_err, me_obtain(x1),
-
 
1023
						   me_obtain(x2));
930
	      exp mult_y1_y2 = f_bin_floating_mult(ov_err, me_obtain(y1), me_obtain(y2));
1024
	      exp mult_y1_y2 = f_bin_floating_mult(ov_err, me_obtain(y1),
-
 
1025
						   me_obtain(y2));
931
	      exp mult_x1_y2 = f_bin_floating_mult(ov_err, me_obtain(x1), me_obtain(y2));
1026
	      exp mult_x1_y2 = f_bin_floating_mult(ov_err, me_obtain(x1),
-
 
1027
						   me_obtain(y2));
932
	      exp mult_x2_y1 = f_bin_floating_mult(ov_err, me_obtain(x2), me_obtain(y1));
1028
	      exp mult_x2_y1 = f_bin_floating_mult(ov_err, me_obtain(x2),
-
 
1029
						   me_obtain(y1));
933
 
1030
 
934
	      prod_re = f_floating_minus(ov_err, mult_x1_x2, mult_y1_y2);
1031
	      prod_re = f_floating_minus(ov_err, mult_x1_x2, mult_y1_y2);
935
	      prod_im = f_bin_floating_plus(ov_err, mult_x1_y2, mult_x2_y1);
1032
	      prod_im = f_bin_floating_plus(ov_err, mult_x1_y2, mult_x2_y1);
936
	  }
1033
	  }
937
 
1034
 
Line 939... Line 1036...
939
	  y1 = push(x1, me_startid(real_shape, prod_im, 0));
1036
	  y1 = push(x1, me_startid(real_shape, prod_im, 0));
940
      }
1037
      }
941
 
1038
 
942
      link_next = f_make_complex(complex_fv, me_obtain(x1), me_obtain(y1));
1039
      link_next = f_make_complex(complex_fv, me_obtain(x1), me_obtain(y1));
943
 
1040
 
944
      return  me_complete_chain(y1, arg1.start, link_next);
1041
      return me_complete_chain(y1, arg1.start, link_next);
945
  }
1042
  }
946
#endif
1043
#endif
947
  setfather (r, arg1.end);
1044
  setfather(r, arg1.end);
948
#if ishppa
1045
#if ishppa
949
  if (!optop(r) && name(sh(r))==doublehd) {
1046
  if (!optop(r) && name(sh(r)) == doublehd) {
950
    exp id = me_startid(sh(r),r,0);
1047
    exp id = me_startid(sh(r), r, 0);
951
    exp tmp = me_complete_id(id,me_obtain(id));
1048
    exp tmp = me_complete_id(id, me_obtain(id));
952
    return tmp;
1049
    return tmp;
953
   }
-
 
954
  else
1050
   } else
955
#endif
1051
#endif
956
  return r;
1052
  return r;
957
}
1053
}
958
 
1054
 
959
 
1055
 
960
exp f_floating_negate
1056
exp
961
    PROTO_N ( (ov_err, arg1) )
-
 
962
    PROTO_T ( error_treatment ov_err X exp arg1 )
1057
f_floating_negate(error_treatment ov_err, exp arg1)
963
{
1058
{
964
  if (name(sh(arg1)) == bothd)
1059
  if (name(sh(arg1)) == bothd) {
965
    return arg1;
1060
    return arg1;
-
 
1061
  }
966
 
1062
 
967
#if check_shape
1063
#if check_shape
968
  if (!is_float(sh(arg1)) && !is_complex(sh(arg1)))
1064
  if (!is_float(sh(arg1)) && !is_complex(sh(arg1))) {
969
    failer(CHSH_FLNEGATE);
1065
    failer(CHSH_FLNEGATE);
-
 
1066
  }
970
#endif
1067
#endif
971
 
1068
 
972
/* PAB changes - 18 October 1994 */
1069
/* PAB changes - 18 October 1994 */
973
#if substitute_complex
1070
#if substitute_complex
974
  if (is_complex(sh(arg1))) {
1071
  if (is_complex(sh(arg1))) {
975
 
-
 
976
      shape complex_shape = sh(arg1);                     /* shape of our complex numbers */
1072
      shape complex_shape = sh(arg1);	/* shape of our complex numbers */
977
      floating_variety real_fv = f_float_of_complex(complex_shape);
1073
      floating_variety real_fv = f_float_of_complex(complex_shape);
978
      shape real_shape = f_floating(real_fv);
1074
      shape real_shape = f_floating(real_fv);
979
      floating_variety complex_fv = f_complex_of_float(real_shape);
1075
      floating_variety complex_fv = f_complex_of_float(real_shape);
980
 
1076
 
981
      exp c1 = me_startid(complex_shape, arg1, 0);
1077
      exp c1 = me_startid(complex_shape, arg1, 0);
982
 
1078
 
983
      exp obtain1_c1 = hold_check(me_obtain(c1));                     /* contents of arg1 */
1079
      exp obtain1_c1 = hold_check(me_obtain(c1));	/* contents of arg1 */
984
      exp obtain2_c1 = hold_check(me_obtain(c1));
1080
      exp obtain2_c1 = hold_check(me_obtain(c1));
985
 
1081
 
986
      exp x1 = f_real_part(obtain1_c1);                              /* re(arg1) */
1082
      exp x1 = f_real_part(obtain1_c1);			/* re(arg1) */
987
      exp y1 = f_imaginary_part(obtain2_c1);                         /* im(arg1) */
1083
      exp y1 = f_imaginary_part(obtain2_c1);		/* im(arg1) */
988
 
1084
 
989
      exp neg_re = f_floating_negate(ov_err, x1);                           /* - re(arg1) */
1085
      exp neg_re = f_floating_negate(ov_err, x1);	/* - re(arg1) */
990
      exp neg_im = f_floating_negate(ov_err, y1);                           /* - im(arg1) */
1086
      exp neg_im = f_floating_negate(ov_err, y1);	/* - im(arg1) */
991
      exp make_comp = f_make_complex(complex_fv, neg_re, neg_im);
1087
      exp make_comp = f_make_complex(complex_fv, neg_re, neg_im);
992
 
1088
 
993
      c1 = me_complete_id(c1, make_comp);
1089
      c1 = me_complete_id(c1, make_comp);
994
 
1090
 
995
      return c1;
1091
      return c1;
996
  };
1092
  }
997
#endif
1093
#endif
998
#if ishppa
1094
#if ishppa
999
  {
1095
  {
1000
    exp r = hold_check(me_u1(ov_err, arg1, fneg_tag));
1096
    exp r = hold_check(me_u1(ov_err, arg1, fneg_tag));
1001
    if (!optop(r) && name(sh(r))==doublehd) {
1097
    if (!optop(r) && name(sh(r)) == doublehd) {
1002
      exp id = me_startid(sh(r),r,0);
1098
      exp id = me_startid(sh(r), r, 0);
1003
      exp tmp = me_complete_id(id,me_obtain(id));
1099
      exp tmp = me_complete_id(id,me_obtain(id));
1004
      return tmp;
1100
      return tmp;
1005
     }
-
 
1006
    else
1101
    } else {
1007
      return r;
1102
      return r;
-
 
1103
    }
1008
  }
1104
  }
1009
#endif
1105
#endif
1010
  return  hold_check(me_u1(ov_err, arg1, fneg_tag));
1106
  return hold_check(me_u1(ov_err, arg1, fneg_tag));
1011
}
1107
}
1012
 
1108
 
1013
 
1109
 
1014
exp f_floating_plus
1110
exp
1015
    PROTO_N ( (ov_err, arg1) )
-
 
1016
    PROTO_T ( error_treatment ov_err X exp_list arg1 )
1111
f_floating_plus(error_treatment ov_err, exp_list arg1)
1017
{
1112
{
1018
  exp first = arg1.start;
1113
  exp first = arg1.start;
1019
  exp r = getexp (sh(first), nilexp, 0, first,
1114
  exp r = getexp(sh(first), nilexp, 0, first, nilexp, 0, 0, fplus_tag);
1020
                  nilexp, 0, 0, fplus_tag);
-
 
1021
  if (name(sh(first)) == bothd || arg1.number == 1)
1115
  if (name(sh(first)) == bothd || arg1.number == 1) {
1022
    return first;
1116
    return first;
-
 
1117
  }
1023
  clear_exp_list(arg1);
1118
  clear_exp_list(arg1);
1024
  seterrhandle(r, ov_err.err_code);
1119
  seterrhandle(r, ov_err.err_code);
1025
  if (isov(r))
1120
  if (isov(r)) {
1026
    setjmp_dest(r, get_lab(ov_err.jmp_dest));
1121
    setjmp_dest(r, get_lab(ov_err.jmp_dest));
-
 
1122
  }
1027
 
1123
 
1028
#if check_shape
1124
#if check_shape
-
 
1125
  {
1029
  {exp t = first;
1126
    exp t = first;
1030
   while (1)
1127
    while (1) {
1031
     {
-
 
1032
       if (! ((is_float(sh(t)) || is_complex(sh(t))) && eq_shape(sh(t), sh(first))) )
1128
      if (!((is_float(sh(t)) || is_complex(sh(t))) &&
-
 
1129
	    eq_shape(sh(t), sh(first)))) {
1033
         failer(CHSH_FLPLUS);
1130
         failer(CHSH_FLPLUS);
-
 
1131
      }
1034
       if (t == arg1.end)
1132
      if (t == arg1.end) {
1035
         break;
1133
         break;
-
 
1134
      }
1036
       t = bro(t);
1135
      t = bro(t);
1037
       if (name(sh(t)) == bothd)
1136
      if (name(sh(t)) == bothd) {
1038
         return t;
1137
	return t;
1039
     };
1138
      }
-
 
1139
    }
1040
  };
1140
  }
1041
#endif
1141
#endif
1042
 
1142
 
1043
/* PAB changes - 18 October 1994 */
1143
/* PAB changes - 18 October 1994 */
1044
#if substitute_complex
1144
#if substitute_complex
1045
  if (is_complex(sh(arg1.start))) {
1145
  if (is_complex(sh(arg1.start))) {
1046
 
-
 
1047
      exp z1, z2, x1, y1, x2, y2, make_comp, t;
1146
      exp z1, z2, x1, y1, x2, y2, make_comp, t;
1048
 
1147
 
1049
      shape complex_shape = sh(arg1.start);               /* shape of our complex numbers */
1148
      shape complex_shape = sh(arg1.start); /* shape of our complex numbers */
1050
      floating_variety real_fv = f_float_of_complex(complex_shape);
1149
      floating_variety real_fv = f_float_of_complex(complex_shape);
1051
      shape real_shape = f_floating(real_fv);
1150
      shape real_shape = f_floating(real_fv);
1052
      floating_variety complex_fv = f_complex_of_float(real_shape);
1151
      floating_variety complex_fv = f_complex_of_float(real_shape);
1053
 
1152
 
1054
#if 0
1153
#if 0
1055
      arg1 = reorder_list(arg1, 1);              /* reorder so constants are at the front */
1154
      arg1 = reorder_list(arg1, 1); /* reorder so constants are at the front */
1056
#endif
1155
#endif
1057
 
1156
 
1058
      z1 = me_startid(complex_shape, arg1.start, 0);
1157
      z1 = me_startid(complex_shape, arg1.start, 0);
1059
 
1158
 
1060
      x1 = f_real_part     (me_obtain(z1));                    /* re(arg1.first) */
1159
      x1 = f_real_part(me_obtain(z1));		/* re(arg1.first) */
1061
      y1 = f_imaginary_part(me_obtain(z1));                    /* im(arg1.first) */
1160
      y1 = f_imaginary_part(me_obtain(z1));	/* im(arg1.first) */
1062
 
1161
 
1063
      t=arg1.start;
1162
      t=arg1.start;
1064
      z2 = z1;                                                   /* start chain of idents */
1163
      z2 = z1;					/* start chain of idents */
1065
 
1164
 
1066
      while (t != arg1.end) {
1165
      while (t != arg1.end) {
1067
 
-
 
1068
	  t = bro(t);
1166
	  t = bro(t);
1069
	  z2 = push(z2, me_startid(complex_shape, t, 0));
1167
	  z2 = push(z2, me_startid(complex_shape, t, 0));
1070
 
1168
 
1071
	  x2 = f_real_part     (me_obtain(z2));              /* contents of next */
1169
	  x2 = f_real_part(me_obtain(z2));	/* contents of next */
1072
	  y2 = f_imaginary_part(me_obtain(z2));              /*   list element   */
1170
	  y2 = f_imaginary_part(me_obtain(z2));	/*   list element   */
1073
 
1171
 
1074
	  x1 = f_bin_floating_plus(ov_err, x1, x2);                    /* pass it this on */
1172
	  x1 = f_bin_floating_plus(ov_err, x1, x2);	/* pass it this on */
1075
	  y1 = f_bin_floating_plus(ov_err, y1, y2);                    /*  as new result  */
1173
	  y1 = f_bin_floating_plus(ov_err, y1, y2);	/*  as new result  */
1076
      }
1174
      }
1077
 
1175
 
1078
      make_comp = f_make_complex(complex_fv, x1, y1);
1176
      make_comp = f_make_complex(complex_fv, x1, y1);
1079
 
1177
 
1080
      return me_complete_chain(z2, arg1.start, make_comp);
1178
      return me_complete_chain(z2, arg1.start, make_comp);
1081
  }
1179
  }
1082
#endif
1180
#endif
1083
  setfather (r, arg1.end);
1181
  setfather(r, arg1.end);
1084
#if ishppa
1182
#if ishppa
1085
  if (!optop(r) && name(sh(r))==doublehd) {
1183
  if (!optop(r) && name(sh(r)) == doublehd) {
1086
    exp id = me_startid(sh(r),r,0);
1184
    exp id = me_startid(sh(r), r, 0);
1087
    exp tmp = me_complete_id(id,me_obtain(id));
1185
    exp tmp = me_complete_id(id, me_obtain(id));
1088
    return tmp;
1186
    return tmp;
1089
   }
-
 
1090
  else
1187
   } else
1091
#endif
1188
#endif
1092
  return r;
1189
  return r;
1093
}
1190
}
1094
 
1191
 
1095
 
1192
 
1096
exp f_floating_test
1193
exp
1097
    PROTO_N ( (prob, flpt_err, nt, dest, arg1, arg2) )
1194
f_floating_test(nat_option prob, error_treatment flpt_err, ntest nt,
1098
    PROTO_T ( nat_option prob X error_treatment flpt_err X ntest nt X label dest X exp arg1 X exp arg2 )
1195
		label dest, exp arg1, exp arg2)
1099
{
1196
{
1100
  if (name(sh(arg1)) == bothd)
1197
  if (name(sh(arg1)) == bothd) {
1101
    { kill_exp(arg2,arg2); return arg1; }
1198
    kill_exp(arg2, arg2);
-
 
1199
    return arg1;
-
 
1200
  }
1102
  if (name(sh(arg2)) == bothd)
1201
  if (name(sh(arg2)) == bothd) {
1103
    { kill_exp(arg1,arg1); return arg2; }
1202
    kill_exp(arg1,arg1);
-
 
1203
    return arg2;
-
 
1204
  }
1104
 
1205
 
1105
#if check_shape
1206
#if check_shape
1106
  if (! ((is_float(sh(arg1)) || is_complex(sh(arg1))) && eq_shape(sh(arg1), sh(arg2))) )
1207
  if (!((is_float(sh(arg1)) || is_complex(sh(arg1))) &&
-
 
1208
	eq_shape(sh(arg1), sh(arg2)))) {
1107
    failer(CHSH_FLTEST);
1209
    failer(CHSH_FLTEST);
-
 
1210
  }
1108
#endif
1211
#endif
1109
 
1212
 
1110
/* PAB changes - 18 October 1994 */
1213
/* PAB changes - 18 October 1994 */
1111
#if substitute_complex
1214
#if substitute_complex
1112
  if (is_complex(sh(arg1))) {                               /* is arg1 a complex number ? */
1215
  if (is_complex(sh(arg1))) {		/* is arg1 a complex number ? */
1113
 
1216
 
1114
      shape complex_shape = sh(arg1);                     /* shape of our complex numbers */
1217
      shape complex_shape = sh(arg1);	/* shape of our complex numbers */
1115
      exp z1 = me_startid(complex_shape, arg1, 0);
1218
      exp z1 = me_startid(complex_shape, arg1, 0);
1116
      exp z2 = me_startid(complex_shape, arg2, 0);
1219
      exp z2 = me_startid(complex_shape, arg2, 0);
1117
 
1220
 
1118
      exp obtain1_z1 = hold_check(me_obtain(z1));                     /* contents of arg1 */
1221
      exp obtain1_z1 = hold_check(me_obtain(z1));	/* contents of arg1 */
1119
      exp obtain2_z1 = hold_check(me_obtain(z1));
1222
      exp obtain2_z1 = hold_check(me_obtain(z1));
1120
      exp obtain1_z2 = hold_check(me_obtain(z2));                     /* contents of arg2 */
1223
      exp obtain1_z2 = hold_check(me_obtain(z2));	/* contents of arg2 */
1121
      exp obtain2_z2 = hold_check(me_obtain(z2));
1224
      exp obtain2_z2 = hold_check(me_obtain(z2));
1122
 
1225
 
1123
      exp x1 = f_real_part     (obtain1_z1);                         /* re(arg1) */
1226
      exp x1 = f_real_part(obtain1_z1);			/* re(arg1) */
1124
      exp x2 = f_real_part     (obtain1_z2);                         /* re(arg2) */
1227
      exp x2 = f_real_part(obtain1_z2);			/* re(arg2) */
1125
      exp y1 = f_imaginary_part(obtain2_z1);                         /* im(arg1) */
1228
      exp y1 = f_imaginary_part(obtain2_z1);		/* im(arg1) */
1126
      exp y2 = f_imaginary_part(obtain2_z2);                         /* im(arg2) */
1229
      exp y2 = f_imaginary_part(obtain2_z2);		/* im(arg2) */
1127
 
1230
 
1128
#if check_shape
1231
#if check_shape
1129
      if ((nt != f_equal) && (nt != f_not_equal))
1232
      if ((nt != f_equal) && (nt != f_not_equal))
1130
	  failer(CHSH_FLTEST);
1233
	  failer(CHSH_FLTEST);
1131
#endif
1234
#endif
1132
 
1235
 
-
 
1236
      if (nt == f_equal) {
1133
      if (nt == f_equal) {                                       /* equality of z1 and z2 */
1237
	  /* equality of z1 and z2 */
1134
 
-
 
1135
	  exp test1 = f_floating_test (prob, flpt_err, f_equal, dest, x1, x2);
1238
	  exp test1 = f_floating_test(prob, flpt_err, f_equal, dest, x1, x2);
1136
	  exp test2 = f_floating_test (prob, flpt_err, f_equal, dest, y1, y2);
1239
	  exp test2 = f_floating_test(prob, flpt_err, f_equal, dest, y1, y2);
1137
 
1240
 
1138
	  exp seq_zero = hold_check(me_u2(test1, 0));
1241
	  exp seq_zero = hold_check(me_u2(test1, 0));
1139
	  exp seq      = hold_check(me_b3(sh(test2), seq_zero, test2, seq_tag));
1242
	  exp seq = hold_check(me_b3(sh(test2), seq_zero, test2, seq_tag));
1140
	  z2           = me_complete_id(z2, seq);
1243
	  z2 = me_complete_id(z2, seq);
1141
 
1244
      } else {
1142
      } else {                                                 /* inequality of z1 and z2 */
1245
	  /* inequality of z1 and z2 */
1143
 
-
 
1144
	  exp seq, conditional;
1246
	  exp seq, conditional;
1145
 
1247
 
1146
	  exp top_cell = me_l1(f_top, top_tag);
1248
	  exp top_cell = me_l1(f_top, top_tag);
1147
	  exp alt_labst = hold_check(me_b3(f_top, me_null(f_top,0,clear_tag),
1249
	  exp alt_labst = hold_check(me_b3(f_top, me_null(f_top, 0, clear_tag),
1148
                                                          top_cell, labst_tag));
-
 
1149
 
-
 
1150
	  exp test1 = f_floating_test (prob, flpt_err, f_equal,
-
 
1151
				       make_label(alt_labst), x1, x2);
-
 
1152
	  exp test2 = f_floating_test (prob, flpt_err, f_not_equal,
-
 
1153
				       dest, y1, y2);
1250
					   top_cell, labst_tag));
1154
      	  exp seq_zero = hold_check(me_b2(test1, test2, 0));
-
 
1155
 
1251
 
-
 
1252
	  exp test1 = f_floating_test(prob, flpt_err, f_equal,
-
 
1253
				      make_label(alt_labst), x1, x2);
1156
	  seq = hold_check(me_b3(f_bottom, seq_zero, f_make_top(), seq_tag));
1254
	  exp test2 = f_floating_test(prob, flpt_err, f_not_equal, dest, y1,
-
 
1255
				      y2);
-
 
1256
      	  exp seq_zero = hold_check(me_b2(test1, test2, 0));
1157
 
1257
 
1158
	  conditional = hold_check(me_b3(f_top,
1258
	  seq = hold_check(me_b3(f_bottom, seq_zero, f_make_top(), seq_tag));
-
 
1259
 
1159
					 seq, alt_labst, cond_tag));
1260
	  conditional = hold_check(me_b3(f_top, seq, alt_labst, cond_tag));
1160
 
1261
 
1161
	  z2 = me_complete_id(z2, conditional);
1262
	  z2 = me_complete_id(z2, conditional);
1162
      }
1263
      }
1163
      z1 = me_complete_id(z1, z2);
1264
      z1 = me_complete_id(z1, z2);
1164
 
1265
 
1165
      return z1;
1266
      return z1;
1166
  }
1267
  }
1167
#endif
1268
#endif
1168
  return me_q2(prob, flpt_err, nt, dest, arg1, arg2, test_tag);
1269
  return me_q2(prob, flpt_err, nt, dest, arg1, arg2, test_tag);
1169
}
1270
}
1170
 
1271
 
1171
 
1272
 
1172
 
1273
 
1173
exp f_imaginary_part
1274
exp
1174
    PROTO_N ( (arg1) )
-
 
1175
    PROTO_T ( exp arg1 )
1275
f_imaginary_part(exp arg1)
1176
{
1276
{
1177
  shape real_shape;
1277
  shape real_shape;
1178
 
1278
 
1179
  if (name(sh(arg1)) == bothd)
1279
  if (name(sh(arg1)) == bothd) {
1180
    return arg1;
1280
    return arg1;
-
 
1281
  }
1181
#if check_shape
1282
#if check_shape
1182
  if (!is_complex(sh(arg1)))
1283
  if (!is_complex(sh(arg1))) {
1183
    failer(CHSH_IMAG);
1284
    failer(CHSH_IMAG);
-
 
1285
  }
1184
#endif
1286
#endif
1185
 
1287
 
1186
/* PAB changes - 25 May 1995 */
1288
/* PAB changes - 25 May 1995 */
1187
  real_shape = f_floating(f_float_of_complex(sh(arg1)));
1289
  real_shape = f_floating(f_float_of_complex(sh(arg1)));
1188
#if substitute_complex
1290
#if substitute_complex
1189
  {
1291
  {
1190
    exp t = me_u3(real_shape, arg1, field_tag);
1292
    exp t = me_u3(real_shape, arg1, field_tag);
1191
    no(t) = shape_size(real_shape);
1293
    no(t) = shape_size(real_shape);
1192
    return hold_check(t);
1294
    return hold_check(t);
1193
  }
1295
  }
1194
#else
1296
#else
1195
  return me_u3(real_shape, arg1, imag_tag);
1297
  return me_u3(real_shape, arg1, imag_tag);
1196
#endif
1298
#endif
1197
}
1299
}
1198
 
1300
 
1199
 
1301
 
1200
exp f_real_part
1302
exp
1201
    PROTO_N ( (arg1) )
-
 
1202
    PROTO_T ( exp arg1 )
1303
f_real_part(exp arg1)
1203
{
1304
{
1204
  shape real_shape;
1305
  shape real_shape;
1205
 
1306
 
1206
  if (name(sh(arg1)) == bothd)
1307
  if (name(sh(arg1)) == bothd) {
1207
    return arg1;
1308
    return arg1;
-
 
1309
  }
1208
#if check_shape
1310
#if check_shape
1209
  if (!is_complex(sh(arg1)))
1311
  if (!is_complex(sh(arg1))) {
1210
    failer(CHSH_REAL);
1312
    failer(CHSH_REAL);
-
 
1313
  }
1211
#endif
1314
#endif
1212
 
1315
 
1213
/* PAB changes - 25 May 1995 */
1316
/* PAB changes - 25 May 1995 */
1214
  real_shape = f_floating(f_float_of_complex(sh(arg1)));
1317
  real_shape = f_floating(f_float_of_complex(sh(arg1)));
1215
#if substitute_complex
1318
#if substitute_complex
Line 1222... Line 1325...
1222
  return me_u3(real_shape, arg1, realpart_tag);
1325
  return me_u3(real_shape, arg1, realpart_tag);
1223
#endif
1326
#endif
1224
}
1327
}
1225
 
1328
 
1226
 
1329
 
1227
 
1330
 
1228
exp f_make_complex
1331
exp
1229
    PROTO_N ( (f, arg1, arg2) )
-
 
1230
    PROTO_T ( floating_variety f X exp arg1 X exp arg2 )
1332
f_make_complex(floating_variety f, exp arg1, exp arg2)
1231
{
1333
{
1232
  if (name(sh(arg1)) == bothd)
1334
  if (name(sh(arg1)) == bothd) {
1233
    { kill_exp(arg2,arg2); return arg1; }
1335
    kill_exp(arg2, arg2);
-
 
1336
    return arg1;
-
 
1337
  }
1234
  if (name(sh(arg2)) == bothd)
1338
  if (name(sh(arg2)) == bothd) {
1235
    { kill_exp(arg1,arg1); return arg2; }
1339
    kill_exp(arg1, arg1);
-
 
1340
    return arg2;
-
 
1341
  }
1236
 
1342
 
1237
#if check_shape
1343
#if check_shape
1238
  if (!is_float(sh(arg1)) || !is_float(sh(arg2)) ||
1344
  if (!is_float(sh(arg1)) || !is_float(sh(arg2)) ||
1239
	!eq_shape(sh(arg1), sh(arg2)) || f != f_complex_of_float(sh(arg1)))
1345
      !eq_shape(sh(arg1), sh(arg2)) || f != f_complex_of_float(sh(arg1))) {
1240
    failer(CHSH_MAKE_COMPLEX);
1346
    failer(CHSH_MAKE_COMPLEX);
-
 
1347
  }
1241
#endif
1348
#endif
1242
 
1349
 
1243
 
1350
 
1244
/* PAB changes - 19 October 1994 */
1351
/* PAB changes - 19 October 1994 */
1245
#if substitute_complex
1352
#if substitute_complex
1246
  switch (f) {
1353
  switch (f) {
Line 1248... Line 1355...
1248
        {
1355
        {
1249
	 shape off_set = f_offset(SHREAL_ALIGN, SHREAL_ALIGN);
1356
	 shape off_set = f_offset(SHREAL_ALIGN, SHREAL_ALIGN);
1250
	 exp val1 = me_shint(off_set, 0);
1357
	 exp val1 = me_shint(off_set, 0);
1251
	 exp val2 = me_shint(off_set, SHREAL_SZ);
1358
	 exp val2 = me_shint(off_set, SHREAL_SZ);
1252
	 exp sz = me_shint(off_set, SHREAL_SZ + SHREAL_SZ);
1359
	 exp sz = me_shint(off_set, SHREAL_SZ + SHREAL_SZ);
1253
	 exp r = getexp(f_compound(sz), nilexp, 0, val1, nilexp, 0, 0, compound_tag);
1360
	 exp r = getexp(f_compound(sz), nilexp, 0, val1, nilexp, 0, 0,
-
 
1361
			compound_tag);
1254
 
1362
 
1255
	 setbro(val1, arg1);
1363
	 setbro(val1, arg1);
1256
	 clearlast(val1);
1364
	 clearlast(val1);
1257
	 setbro(arg1, val2);
1365
	 setbro(arg1, val2);
1258
	 clearlast(arg1);
1366
	 clearlast(arg1);
Line 1265... Line 1373...
1265
       {
1373
       {
1266
	 shape off_set = f_offset(REAL_ALIGN, REAL_ALIGN);
1374
	 shape off_set = f_offset(REAL_ALIGN, REAL_ALIGN);
1267
	 exp val1 = me_shint(off_set, 0);
1375
	 exp val1 = me_shint(off_set, 0);
1268
	 exp val2 = me_shint(off_set, REAL_SZ);
1376
	 exp val2 = me_shint(off_set, REAL_SZ);
1269
	 exp sz = me_shint(off_set, REAL_SZ + REAL_SZ);
1377
	 exp sz = me_shint(off_set, REAL_SZ + REAL_SZ);
1270
	 exp r = getexp(f_compound(sz), nilexp, 0, val1, nilexp, 0, 0, compound_tag);
1378
	 exp r = getexp(f_compound(sz), nilexp, 0, val1, nilexp, 0, 0,
-
 
1379
			compound_tag);
1271
 
1380
 
1272
	 setbro(val1, arg1);
1381
	 setbro(val1, arg1);
1273
	 clearlast(val1);
1382
	 clearlast(val1);
1274
	 setbro(arg1, val2);
1383
	 setbro(arg1, val2);
1275
	 clearlast(arg1);
1384
	 clearlast(arg1);
Line 1282... Line 1391...
1282
       {
1391
       {
1283
	 shape off_set = f_offset(DOUBLE_ALIGN, DOUBLE_ALIGN);
1392
	 shape off_set = f_offset(DOUBLE_ALIGN, DOUBLE_ALIGN);
1284
	 exp val1 = me_shint(off_set, 0);
1393
	 exp val1 = me_shint(off_set, 0);
1285
	 exp val2 = me_shint(off_set, DOUBLE_SZ);
1394
	 exp val2 = me_shint(off_set, DOUBLE_SZ);
1286
	 exp sz = me_shint(off_set, DOUBLE_SZ + DOUBLE_SZ);
1395
	 exp sz = me_shint(off_set, DOUBLE_SZ + DOUBLE_SZ);
1287
	 exp r = getexp(f_compound(sz), nilexp, 0, val1, nilexp, 0, 0, compound_tag);
1396
	 exp r = getexp(f_compound(sz), nilexp, 0, val1, nilexp, 0, 0,
-
 
1397
			compound_tag);
1288
 
1398
 
1289
	 setbro(val1, arg1);
1399
	 setbro(val1, arg1);
1290
	 clearlast(val1);
1400
	 clearlast(val1);
1291
	 setbro(arg1, val2);
1401
	 setbro(arg1, val2);
1292
	 clearlast(arg1);
1402
	 clearlast(arg1);
Line 1299... Line 1409...
1299
       {
1409
       {
1300
	 failer("Illegal floating_variety for make_complex_tag\n");
1410
	 failer("Illegal floating_variety for make_complex_tag\n");
1301
       }
1411
       }
1302
  }
1412
  }
1303
#endif
1413
#endif
1304
  return me_b3(f_floating(f), arg1, arg2,
1414
  return me_b3(f_floating(f), arg1, arg2, make_complex_tag);
1305
		 make_complex_tag);
-
 
1306
}
1415
}
1307
 
1416
 
1308
 
1417
 
1309
#if FBASE == 10
1418
#if FBASE == 10
1310
 
1419
 
1311
exp f_make_floating
1420
exp
1312
    PROTO_N ( (fv, rm, sign, mantissa, base, expo) )
1421
f_make_floating(floating_variety fv, rounding_mode rm, bool sign,
1313
    PROTO_T ( floating_variety fv X rounding_mode rm X bool sign X string mantissa X nat base X signed_nat expo )
1422
		string mantissa, nat base, signed_nat expo)
1314
{
1423
{
1315
  int ignore_zero = 1;
1424
  int ignore_zero = 1;
1316
  int lg = mantissa.number;
1425
  int lg = mantissa.number;
1317
  flpt f = new_flpt ();
1426
  flpt f = new_flpt();
1318
  int  sig_digs = 0;
1427
  int sig_digs = 0;
1319
  int  i;
1428
  int i;
1320
  int point = 0;
1429
  int point = 0;
1321
  char ch;
1430
  char ch;
1322
  int exponent = snatint(expo);
1431
  int exponent = snatint(expo);
1323
 
1432
 
1324
  if (PIC_code)
1433
  if (PIC_code) {
1325
    proc_externs = 1;
1434
    proc_externs = 1;
-
 
1435
  }
1326
 
1436
 
1327
  if (snatneg(expo))
1437
  if (snatneg(expo)) {
1328
    exponent = - exponent;
1438
    exponent = - exponent;
-
 
1439
  }
1329
 
1440
 
1330
  if (natint(base) != 10)
1441
  if (natint(base) != 10) {
1331
    failer (BASE_NOT_10);
1442
    failer(BASE_NOT_10);
-
 
1443
  }
1332
  for (i = 0; i < MANT_SIZE; ++i)
1444
  for (i = 0; i < MANT_SIZE; ++i) {
1333
    (flptnos[f].mant)[i] = 0;
1445
    (flptnos[f].mant)[i] = 0;
-
 
1446
  }
1334
 
1447
 
1335
  for (i = 0; i < lg; ++i) {
1448
  for (i = 0; i < lg; ++i) {
1336
    ch = mantissa.ints.chars[i];
1449
    ch = mantissa.ints.chars[i];
1337
    if (ch == '0' && ignore_zero) {
1450
    if (ch == '0' && ignore_zero) {
1338
      if (point)
1451
      if (point) {
1339
	--exponent;
1452
	--exponent;
1340
    }
1453
      }
1341
    else {
1454
    } else {
1342
      if (ch == '.')
1455
      if (ch == '.') {
1343
	point = 1;
1456
	point = 1;
1344
      else {
1457
      } else {
1345
	ignore_zero = 0;
1458
	ignore_zero = 0;
1346
	if (!point)
1459
	if (!point) {
1347
	  ++exponent;
1460
	  ++exponent;
-
 
1461
	}
1348
	if (sig_digs < MANT_SIZE)
1462
	if (sig_digs < MANT_SIZE) {
1349
	  (flptnos[f].mant)[sig_digs++] = ch - '0';
1463
	 (flptnos[f].mant)[sig_digs++] = ch - '0';
-
 
1464
	}
1350
      };
1465
      }
1351
    };
1466
    }
1352
  };
1467
  }
1353
 
1468
 
1354
  if (ignore_zero) {
1469
  if (ignore_zero) {
1355
    flptnos[f].exp = 0;
1470
    flptnos[f].exp = 0;
1356
    flptnos[f].sign = 0;
1471
    flptnos[f].sign = 0;
1357
  }
-
 
1358
  else {
1472
  } else {
1359
    flptnos[f].exp = exponent - 1;
1473
    flptnos[f].exp = exponent - 1;
1360
    flptnos[f].sign = (sign ? -1 : 1);
1474
    flptnos[f].sign = (sign ? -1 : 1);
1361
  };
1475
  }
1362
 
1476
 
1363
  if (flptnos[f].exp > target_dbl_maxexp)
1477
  if (flptnos[f].exp > target_dbl_maxexp) {
1364
    failer (BIG_FLPT);
1478
    failer(BIG_FLPT);
-
 
1479
  }
1365
 
1480
 
1366
  return (getexp (f_floating(fv), nilexp, 0, nilexp, nilexp,
1481
  return(getexp(f_floating(fv), nilexp, 0, nilexp, nilexp, 0, f, real_tag));
1367
             0, f, real_tag));
-
 
1368
 
1482
 
1369
}
1483
}
1370
 
1484
 
1371
#else
1485
#else
1372
 
1486
 
1373
exp f_make_floating
1487
exp
1374
    PROTO_N ( (fv, rm, sign, mantissa, natbase, expo) )
1488
f_make_floating(floating_variety fv, rounding_mode rm, bool sign,
1375
    PROTO_T ( floating_variety fv X rounding_mode rm X bool sign X string mantissa X nat natbase X signed_nat expo )
1489
		string mantissa, nat natbase, signed_nat expo)
1376
{
1490
{
1377
  int ignore_zero = 1;
1491
  int ignore_zero = 1;
1378
  int lg = mantissa.number;
1492
  int lg = mantissa.number;
1379
  flpt f = new_flpt ();
1493
  flpt f = new_flpt();
1380
  int  has_sig_digs = 0;
1494
  int has_sig_digs = 0;
1381
  int  i;
1495
  int i;
1382
  int point = 0;
1496
  int point = 0;
1383
  int exponent = snatint(expo);
1497
  int exponent = snatint(expo);
1384
  flt fr;
1498
  flt fr;
1385
  int base = natint(natbase);
1499
  int base = natint(natbase);
1386
 
1500
 
1387
 
1501
 
1388
  flt_zero(&fr);
1502
  flt_zero(&fr);
1389
 
1503
 
1390
  if (PIC_code)
1504
  if (PIC_code) {
1391
    proc_externs = 1;
1505
    proc_externs = 1;
-
 
1506
  }
1392
 
1507
 
1393
  if (base != 10 && base != 16 && base !=8 && base != 2 && base != 4)
1508
  if (base != 10 && base != 16 && base !=8 && base != 2 && base != 4) {
1394
    failer (BAD_BASE);
1509
    failer(BAD_BASE);
-
 
1510
  }
1395
 
1511
 
1396
  if (snatneg(expo))
1512
  if (snatneg(expo)) {
1397
    exponent = - exponent;
1513
    exponent =- exponent;
-
 
1514
  }
1398
 
1515
 
1399
  for (i = 0; i < lg; ++i) {
1516
  for (i = 0; i < lg; ++i) {
1400
    char c = mantissa.ints.chars[i];
1517
    char c = mantissa.ints.chars[i];
1401
    if (c != '0' || !ignore_zero) {
1518
    if (c != '0' || !ignore_zero) {
1402
      ignore_zero = 0;
1519
      ignore_zero = 0;
1403
      if (c == '.')
1520
      if (c == '.') {
1404
	point = 1;
1521
	point = 1;
1405
      else {
1522
      } else {
1406
	c = c - '0';
1523
	c = c - '0';
1407
	if (c != 0)
1524
	if (c != 0) {
1408
	  has_sig_digs = 1;
1525
	  has_sig_digs = 1;
-
 
1526
	}
1409
        exponent -= point;
1527
        exponent -= point;
1410
	flpt_newdig((unsigned int)c, &fr, base);
1528
	flpt_newdig((unsigned int)c, &fr, base);
1411
      };
1529
      }
1412
    };
1530
    }
1413
  };
1531
  }
1414
 
1532
 
1415
  if (ignore_zero) {
1533
  if (ignore_zero) {
1416
    fr.exp = 0;
1534
    fr.exp = 0;
1417
    fr.sign = 0;
1535
    fr.sign = 0;
1418
  }
-
 
1419
  else {
1536
  } else {
1420
    if (has_sig_digs)
1537
    if (has_sig_digs) {
1421
      fr.sign = (sign ? -1 : 1);
1538
      fr.sign = (sign ? -1 : 1);
1422
    else
1539
    } else {
1423
      fr.sign = 0;
1540
      fr.sign = 0;
-
 
1541
    }
1424
    flpt_scale(exponent, &fr, base);
1542
    flpt_scale(exponent, &fr, base);
1425
  };
1543
  }
1426
 
-
 
1427
 
1544
 
-
 
1545
 
1428
  flpt_round((int)rm, flpt_bits((floating_variety)fv), &fr);
1546
  flpt_round((int)rm, flpt_bits((floating_variety)fv), &fr);
1429
 
1547
 
1430
  if (flpt_const_overflow_fail) {
1548
  if (flpt_const_overflow_fail) {
1431
    r2l r;
1549
    r2l r;
1432
    r = real2longs_IEEE(&fr, fv);
1550
    r = real2longs_IEEE(&fr, fv);
1433
    UNUSED(r);
1551
    UNUSED(r);
1434
  };
1552
  }
1435
 
1553
 
1436
  flptnos[f] = fr;
1554
  flptnos[f] = fr;
1437
 
1555
 
1438
  return (getexp (f_floating(fv), nilexp, 0, nilexp, nilexp,
1556
  return(getexp(f_floating(fv), nilexp, 0, nilexp, nilexp, 0, f, real_tag));
1439
             0, f, real_tag));
-
 
1440
 
-
 
1441
}
1557
}
1442
 
1558
 
1443
#endif
1559
#endif
1444
 
1560
 
1445
 
1561
 
1446
 
1562
 
1447
exp f_power
1563
exp
1448
    PROTO_N ( (ov_err, arg1, arg2) )
-
 
1449
    PROTO_T ( error_treatment ov_err X exp arg1 X exp arg2 )
1564
f_power(error_treatment ov_err, exp arg1, exp arg2)
1450
{
1565
{
1451
  if (name(sh(arg1)) == bothd)
1566
  if (name(sh(arg1)) == bothd) {
1452
    { kill_exp(arg2,arg2); return arg1; }
1567
    kill_exp(arg2,arg2);
-
 
1568
    return arg1;
-
 
1569
  }
1453
  if (name(sh(arg2)) == bothd)
1570
  if (name(sh(arg2)) == bothd) {
1454
    { kill_exp(arg1,arg1); return arg2; }
1571
    kill_exp(arg1,arg1);
-
 
1572
    return arg2;
-
 
1573
  }
1455
#if check_shape
1574
#if check_shape
1456
  if (!is_integer(sh(arg1)) || !is_integer(sh(arg2)))
1575
  if (!is_integer(sh(arg1)) || !is_integer(sh(arg2))) {
1457
    failer(CHSH_POWER);
1576
    failer(CHSH_POWER);
-
 
1577
  }
1458
#endif
1578
#endif
1459
 
1579
 
1460
  return  real_power(ov_err, arg1, arg2);
1580
  return real_power(ov_err, arg1, arg2);
1461
}
1581
}
1462
 
1582
 
1463
 
1583
 
1464
exp f_round_with_mode
1584
exp
1465
    PROTO_N ( (flpt_err, mode, r, arg1) )
-
 
1466
    PROTO_T ( error_treatment flpt_err X rounding_mode mode X variety r X exp arg1 )
1585
f_round_with_mode(error_treatment flpt_err, rounding_mode mode, variety r,
-
 
1586
		  exp arg1)
1467
{
1587
{
1468
  exp res;
1588
  exp res;
1469
  if (name(sh(arg1)) == bothd)
1589
  if (name(sh(arg1)) == bothd) {
1470
    return arg1;
1590
    return arg1;
-
 
1591
  }
1471
  if (is_complex(sh(arg1))) {
1592
  if (is_complex(sh(arg1))) {
1472
	arg1 = f_real_part(arg1);
1593
	arg1 = f_real_part(arg1);
1473
  }
1594
  }
1474
#if check_shape
1595
#if check_shape
1475
  if (!is_float(sh(arg1)))
1596
  if (!is_float(sh(arg1))) {
1476
    failer(CHSH_ROUND);
1597
    failer(CHSH_ROUND);
-
 
1598
  }
1477
#endif
1599
#endif
1478
#if !has64bits
1600
#if !has64bits
-
 
1601
	if (shape_size(r) >32 &&
1479
	if ( shape_size(r)>32 && (name(arg1) != real_tag || flpt_err.err_code>=4)   ) {
1602
	    (name(arg1) != real_tag || flpt_err.err_code >= 4)) {
1480
		int s = is_signed(r);
1603
		int s = is_signed(r);
1481
		char * fn;
1604
		char *fn;
1482
		exp e;
1605
		exp e;
1483
#if use_long_double
1606
#if use_long_double
1484
	        arg1 = hold_check(
1607
	        arg1 = hold_check(f_change_floating_variety(f_impossible, 2,
1485
		  f_change_floating_variety(f_impossible, 2, arg1));
1608
							    arg1));
1486
#else
1609
#else
1487
	        arg1 = hold_check(
1610
	        arg1 = hold_check(f_change_floating_variety(f_impossible, 1,
1488
		  f_change_floating_variety(f_impossible, 1, arg1));
1611
							    arg1));
1489
#endif
1612
#endif
1490
		switch(mode) {
1613
		switch (mode) {
-
 
1614
		case R2NEAR:
1491
		case R2NEAR: fn = (s)?"__TDFUs_R2NEAR":"__TDFUu_R2NEAR"; break;
1615
			fn = (s) ? "__TDFUs_R2NEAR" : "__TDFUu_R2NEAR";
-
 
1616
			break;
-
 
1617
		case R2PINF:
1492
		case R2PINF: fn = (s)?"__TDFUs_R2PINF":"__TDFUu_R2PINF"; break;
1618
			fn = (s) ? "__TDFUs_R2PINF" : "__TDFUu_R2PINF";
-
 
1619
			break;
-
 
1620
		case R2NINF:
1493
		case R2NINF: fn = (s)?"__TDFUs_R2NINF":"__TDFUu_R2NINF"; break;
1621
			fn = (s) ? "__TDFUs_R2NINF" : "__TDFUu_R2NINF";
-
 
1622
			break;
-
 
1623
		case R2ZERO:
1494
		case R2ZERO: fn = (s)?"__TDFUs_R2ZERO":"__TDFUu_R2ZERO"; break;
1624
			fn = (s) ? "__TDFUs_R2ZERO" : "__TDFUu_R2ZERO";
-
 
1625
			break;
-
 
1626
		default:
1495
		default: fn = (s)?"__TDFUs_ASSTATE":"__TDFUu_R2ASSTATE";
1627
			fn = (s) ? "__TDFUs_ASSTATE" : "__TDFUu_R2ASSTATE";
1496
		}
1628
		}
1497
		e = TDFcallaux(flpt_err, arg1, fn, r);
1629
		e = TDFcallaux(flpt_err, arg1, fn, r);
1498
		return (hold_check(e));
1630
		return(hold_check(e));
1499
	}
1631
	}
1500
#endif
1632
#endif
1501
#if ismips
1633
#if ismips
1502
	/* mips does not seem to get float->unsigned long right -
1634
	/* mips does not seem to get float->unsigned long right -
1503
		so convert to signed long and adjust if too big*/
1635
	   so convert to signed long and adjust if too big*/
1504
	else
-
 
1505
	if (name(arg1)!=real_tag && shape_size(r)==32 && !is_signed(r) ) {
1636
	else if (name(arg1) != real_tag && shape_size(r) == 32 &&
-
 
1637
		 !is_signed(r)) {
1506
		floating_variety fa = (shape_size(sh(arg1))==32)?0:1;
1638
		floating_variety fa = (shape_size(sh(arg1)) == 32) ? 0 : 1;
1507
		exp_list st;
1639
		exp_list st;
1508
		exp z;
1640
		exp z;
1509
		exp d1 = me_startid(r, arg1, 0);
1641
		exp d1 = me_startid(r, arg1, 0);
1510
		exp hldr = getexp(f_top, nilexp, 0, nilexp, nilexp, 0, 0, 0);
1642
		exp hldr = getexp(f_top, nilexp, 0, nilexp, nilexp, 0, 0, 0);
1511
		exp lb = getexp(f_top, nilexp, 0, hldr, nilexp, 0, 0, labst_tag);
1643
		exp lb = getexp(f_top, nilexp, 0, hldr, nilexp, 0, 0,
-
 
1644
				labst_tag);
1512
 
1645
 
1513
		exp fmax = hold_check(f_float_int(f_impossible, fa,
1646
		exp fmax = hold_check(f_float_int(f_impossible, fa,
1514
					me_shint(ulongsh,0x80000000 )));
1647
						  me_shint(ulongsh,
-
 
1648
							   0x80000000)));
1515
		exp d2 = me_startid(r, fmax, 0);
1649
		exp d2 = me_startid(r, fmax, 0);
1516
		exp tst =  f_floating_test(no_nat_option,
1650
		exp tst = f_floating_test(no_nat_option, f_impossible,
1517
				f_impossible, f_less_than, &lb,
1651
					  f_less_than, &lb, me_obtain(d1),
1518
				me_obtain(d1), me_obtain(d2));
1652
					  me_obtain(d2));
1519
		exp nconv = f_round_with_mode(flpt_err, mode, slongsh,
1653
		exp nconv = f_round_with_mode(flpt_err, mode, slongsh,
1520
					me_obtain(d1));
1654
					      me_obtain(d1));
1521
		exp first; exp alt; exp cnd;
1655
		exp first;
-
 
1656
		exp alt;
-
 
1657
		exp cnd;
1522
		st = new_exp_list(1);
1658
		st = new_exp_list(1);
1523
		st = add_exp_list(st, tst, 0);
1659
		st = add_exp_list(st, tst, 0);
1524
		first = f_sequence(st, f_change_variety(flpt_err, r, nconv));
1660
		first = f_sequence(st, f_change_variety(flpt_err, r, nconv));
1525
		z = f_round_with_mode(flpt_err, mode, slongsh,
1661
		z = f_round_with_mode(flpt_err, mode, slongsh,
1526
			f_floating_minus(f_impossible, me_obtain(d1), me_obtain(d2)));
1662
				      f_floating_minus(f_impossible,
-
 
1663
						       me_obtain(d1),
-
 
1664
						       me_obtain(d2)));
1527
		alt = f_plus(f_impossible,
1665
		alt = f_plus(f_impossible, f_change_variety(f_impossible, r, z),
1528
		   f_change_variety(f_impossible, r, z), me_shint(r, 0x80000000));
1666
			     me_shint(r, 0x80000000));
1529
		cnd = f_conditional(&lb, first, alt);
1667
		cnd = f_conditional(&lb, first, alt);
1530
		return me_complete_id(d1, me_complete_id(d2, cnd));
1668
		return me_complete_id(d1, me_complete_id(d2, cnd));
1531
 
1669
 
1532
	}
1670
	}
1533
#endif
1671
#endif
1534
#if ispower
1672
#if ispower
1535
 if (name(arg1)!=real_tag || flpt_err.err_code>2) {
1673
 if (name(arg1) != real_tag || flpt_err.err_code > 2) {
1536
  if (architecture!=POWERPC_CODE)
1674
   if (architecture != POWERPC_CODE) {
1537
  {
-
 
1538
    exp id;
1675
     exp id;
1539
    exp apply1;
1676
     exp apply1;
1540
    exp apply2;
1677
     exp apply2;
1541
    long shp_sze = shape_size(f_integer(r));
1678
     long shp_sze = shape_size(f_integer(r));
1542
    bool sgned = is_signed(f_integer(r));
1679
     bool sgned = is_signed(f_integer(r));
1543
    bool err = (flpt_err.err_code>2);
1680
     bool err = (flpt_err.err_code > 2);
1544
    char *nm ;
1681
     char *nm;
1545
    char *nm_err;
1682
     char *nm_err;
1546
    int power_mode;
1683
     int power_mode;
1547
 
1684
 
1548
    /* Set up ident to hold arg1 */
1685
     /* Set up ident to hold arg1 */
1549
    if (name(sh(arg1))==shrealhd)
1686
     if (name(sh(arg1)) == shrealhd) {
1550
    {
-
 
1551
      arg1 = f_change_floating_variety(f_impossible,realfv,arg1);
1687
       arg1 = f_change_floating_variety(f_impossible, realfv, arg1);
1552
    }
1688
     }
1553
    id = me_startid(f_top,arg1,0);
1689
     id = me_startid(f_top, arg1, 0);
1554
 
1690
 
1555
  /* Set up power_mode */
1691
     /* Set up power_mode */
1556
    switch (mode)
1692
     switch (mode) {
1557
    {
1693
       case R2ZERO:
1558
 
-
 
1559
      case R2ZERO: power_mode = 0;break;
1694
 	      power_mode = 0;
-
 
1695
 	      break;
-
 
1696
       case R2NEAR:
1560
      case R2NEAR: power_mode = 1;break;
1697
 	      power_mode = 1;
-
 
1698
 	      break;
-
 
1699
       case R2PINF:
1561
      case R2PINF: power_mode = 2;break;
1700
 	      power_mode = 2;
-
 
1701
 	      break;
-
 
1702
       case R2NINF:
1562
      case R2NINF: power_mode = 3;break;
1703
 	      power_mode = 3;
-
 
1704
 	      break;
-
 
1705
       default:
1563
      default:power_mode = 1;break;
1706
 	      power_mode = 1;
-
 
1707
 	      break;
1564
    }
1708
     }
1565
 
1709
 
1566
    /* Work out which functions to call */
1710
     /* Work out which functions to call */
1567
    if (sgned)
1711
     if (sgned) {
1568
    {
-
 
1569
      nm = "__TDFrnd_sgned";
1712
       nm = "__TDFrnd_sgned";
1570
      nm_err = "__TDFerr_rnd_sgned";
1713
       nm_err = "__TDFerr_rnd_sgned";
1571
    }
-
 
1572
    else
1714
     } else {
1573
    {
-
 
1574
      nm = "__TDFrnd_unsgned";
1715
       nm = "__TDFrnd_unsgned";
1575
      nm_err = "__TDFerr_rnd_unsgned";
1716
       nm_err = "__TDFerr_rnd_unsgned";
1576
    }
1717
     }
1577
 
1718
 
1578
    {
1719
     {
1579
      exp_list pars2;
1720
       exp_list pars2;
1580
      exp_option no_var ;
1721
       exp_option no_var;
1581
      pars2 = new_exp_list(2);
1722
       pars2 = new_exp_list(2);
1582
      no_var.present = 0;
1723
       no_var.present = 0;
1583
      pars2 = add_exp_list(pars2,me_obtain(id),0);
1724
       pars2 = add_exp_list(pars2, me_obtain(id), 0);
1584
      pars2 = add_exp_list(pars2,me_shint(uwordsh,power_mode),1);
1725
       pars2 = add_exp_list(pars2, me_shint(uwordsh, power_mode), 1);
1585
      apply2 = f_apply_proc(sgned?slongsh:ulongsh,me_obtain(find_named_tg(nm,f_proc)),pars2,no_var);
1726
       apply2 = f_apply_proc(sgned ? slongsh : ulongsh,
-
 
1727
 			    me_obtain(find_named_tg(nm, f_proc)), pars2,
-
 
1728
 			    no_var);
1586
    }
1729
     }
1587
 
1730
 
1588
    if (err)
1731
     if (err) {
1589
    {
-
 
1590
      exp_list st;
1732
       exp_list st;
1591
      exp seq;
1733
       exp seq;
1592
      exp pl;
1734
       exp pl;
1593
      exp_list pars1;
1735
       exp_list pars1;
1594
      exp_option no_var;
1736
       exp_option no_var;
1595
      no_var.present = 0;
1737
       no_var.present = 0;
1596
 
1738
 
1597
      pars1 = new_exp_list(2);
1739
       pars1 = new_exp_list(2);
1598
      pars1 = add_exp_list(pars1,me_obtain(id),0);
1740
       pars1 = add_exp_list(pars1, me_obtain(id), 0);
1599
      pars1 = add_exp_list(pars1,me_shint(uwordsh,power_mode),1);
1741
       pars1 = add_exp_list(pars1, me_shint(uwordsh, power_mode), 1);
1600
      apply1 = f_apply_proc(f_top,me_obtain(find_named_tg(nm_err,f_proc)),pars1,no_var);
1742
       apply1 = f_apply_proc(f_top, me_obtain(find_named_tg(nm_err, f_proc)),
-
 
1743
 			    pars1, no_var);
1601
 
1744
 
-
 
1745
       pl = f_plus(flpt_err, me_shint(slongsh, INT_MAX),
1602
      pl = f_plus(flpt_err,me_shint(slongsh,INT_MAX),me_obtain(find_named_tg("__TDFrnd_error",slongsh)));
1746
 		  me_obtain(find_named_tg("__TDFrnd_error", slongsh)));
1603
      st = new_exp_list(2);
1747
       st = new_exp_list(2);
1604
      st = add_exp_list(st,apply1,0);
1748
       st = add_exp_list(st, apply1, 0);
1605
      st = add_exp_list(st,pl,1);
1749
       st = add_exp_list(st, pl, 1);
1606
      seq = f_sequence(st,apply2);
1750
       seq = f_sequence(st, apply2);
1607
      id = me_complete_id(id,seq);
1751
       id = me_complete_id(id, seq);
1608
    }
-
 
1609
    else
1752
     } else {
1610
    {
-
 
1611
      id = me_complete_id(id,apply2);
1753
       id = me_complete_id(id, apply2);
1612
    }
1754
     }
1613
    if (shp_sze <32)
1755
     if (shp_sze < 32) {
1614
    {
-
 
1615
      id = f_change_variety(flpt_err,f_integer(r),id);
1756
       id = f_change_variety(flpt_err, f_integer(r), id);
1616
    }
1757
     }
1617
    return id;
1758
     return id;
1618
  }/*end ispower */
1759
   }/*end ispower */
1619
 }
1760
 }
1620
  /* FALL THROUGH */
1761
  /* FALL THROUGH */
1621
#endif
1762
#endif
1622
 
1763
 
1623
  res = getexp (f_integer(r), nilexp, 0, arg1, nilexp,
1764
  res = getexp(f_integer(r), nilexp, 0, arg1, nilexp, 0, 0, round_tag);
1624
           0, 0, round_tag);
-
 
1625
  setround_number(res, mode);
1765
  setround_number(res, mode);
1626
  seterrhandle(res, flpt_err.err_code);
1766
  seterrhandle(res, flpt_err.err_code);
1627
  if (flpt_err.err_code ==  4)
1767
  if (flpt_err.err_code == 4) {
1628
    setjmp_dest(res, get_lab(flpt_err.jmp_dest));
1768
    setjmp_dest(res, get_lab(flpt_err.jmp_dest));
-
 
1769
  }
1629
  setfather (res, arg1);
1770
  setfather(res, arg1);
1630
  return res;
1771
  return res;
1631
}
1772
}
1632
 
1773
 
1633
 
1774
 
1634
 
1775
 
1635
floating_variety f_flvar_parms
1776
floating_variety
1636
    PROTO_N ( (base, mantissa_digits, minimum_exponent, maximum_exponent) )
1777
f_flvar_parms(nat base, nat mantissa_digits, nat minimum_exponent,
1637
    PROTO_T ( nat base X nat mantissa_digits X nat minimum_exponent X nat maximum_exponent )
1778
	      nat maximum_exponent)
1638
{
1779
{
1639
  int b = natint(base);
1780
  int b = natint(base);
1640
  int mantdig = natint(mantissa_digits);
1781
  int mantdig = natint(mantissa_digits);
1641
  int neg_minexp = natint(minimum_exponent);
1782
  int neg_minexp = natint(minimum_exponent);
1642
  int maxexp = natint(maximum_exponent);
1783
  int maxexp = natint(maximum_exponent);
Line 1646... Line 1787...
1646
		failer("base in flvar_parms must be a power of 2");
1787
		failer("base in flvar_parms must be a power of 2");
1647
	}
1788
	}
1648
	mantdig+=mantdig;
1789
	mantdig+=mantdig;
1649
	neg_minexp+=neg_minexp;
1790
	neg_minexp+=neg_minexp;
1650
	maxexp+=maxexp;
1791
	maxexp+=maxexp;
1651
	b = (b>>1);
1792
	b = (b >> 1);
1652
  }
1793
  }
1653
 
1794
 
1654
	if (mantdig <= 24 && neg_minexp <= 126 &&
1795
	if (mantdig <= 24 && neg_minexp <= 126 && maxexp <= 127) {
1655
                 maxexp <= 127)
-
 
1656
	  return (0);
1796
	  return(0);
-
 
1797
	}
1657
	if (mantdig <= 53 && neg_minexp <= 1022 &&
1798
	if (mantdig <= 53 && neg_minexp <= 1022 && maxexp <= 1023) {
1658
                 maxexp <= 1023)
-
 
1659
	  return (1);
1799
	  return(1);
-
 
1800
	}
1660
 
1801
 
1661
#if use_long_double
1802
#if use_long_double
1662
	if (mantdig <= 64 && neg_minexp <= 16382 &&
1803
	if (mantdig <= 64 && neg_minexp <= 16382 && maxexp <= 16383) {
1663
                 maxexp <= 16383)
-
 
1664
	  return (2);
1804
	  return(2);
-
 
1805
	}
1665
	return (2);
1806
	return(2);
1666
#else
1807
#else
1667
        return 1;
1808
        return 1;
1668
#endif
1809
#endif
1669
}
-
 
1670
 
-
 
1671
 
-
 
1672
floating_variety f_complex_parms
-
 
1673
    PROTO_N ( (base, mantissa_digits, minimum_exponent, maximum_exponent) )
-
 
1674
    PROTO_T ( nat base X nat mantissa_digits X nat minimum_exponent X nat maximum_exponent )
-
 
1675
{
-
 
1676
  return float_to_complex_var(f_flvar_parms(base, mantissa_digits,
-
 
1677
			 minimum_exponent, maximum_exponent));
-
 
1678
}
1810
}
1679
 
1811
 
1680
 
1812
 
1681
void init_floating_variety
1813
floating_variety
-
 
1814
f_complex_parms(nat base, nat mantissa_digits, nat minimum_exponent,
-
 
1815
		nat maximum_exponent)
-
 
1816
{
-
 
1817
  return float_to_complex_var(f_flvar_parms(base, mantissa_digits,
1682
    PROTO_Z ()
1818
					    minimum_exponent,
-
 
1819
					    maximum_exponent));
-
 
1820
}
-
 
1821
 
-
 
1822
 
-
 
1823
void
-
 
1824
init_floating_variety(void)
1683
{
1825
{
1684
  shrealsh = getshape(0, const_al1, const_al1, SHREAL_ALIGN,
1826
  shrealsh = getshape(0, const_al1, const_al1, SHREAL_ALIGN, SHREAL_SZ,
1685
			 SHREAL_SZ, shrealhd);
1827
		      shrealhd);
1686
  realsh = getshape(0, const_al1, const_al1, REAL_ALIGN, REAL_SZ, realhd);
1828
  realsh = getshape(0, const_al1, const_al1, REAL_ALIGN, REAL_SZ, realhd);
1687
  doublesh = getshape(0, const_al1, const_al1, DOUBLE_ALIGN,
1829
  doublesh = getshape(0, const_al1, const_al1, DOUBLE_ALIGN, DOUBLE_SZ,
1688
			 DOUBLE_SZ, doublehd);
1830
		      doublehd);
1689
#if substitute_complex
1831
#if substitute_complex
1690
  shcomplexsh = getshape(0, const_al1, const_al1, SHREAL_ALIGN,
1832
  shcomplexsh = getshape(0, const_al1, const_al1, SHREAL_ALIGN, 2 * SHREAL_SZ,
1691
			 2*SHREAL_SZ, cpdhd);
1833
			 cpdhd);
1692
  complexsh = getshape(0, const_al1, const_al1, REAL_ALIGN,
1834
  complexsh = getshape(0, const_al1, const_al1, REAL_ALIGN, 2 * REAL_SZ, cpdhd);
1693
			 2*REAL_SZ, cpdhd);
-
 
1694
  complexdoublesh = getshape(0, const_al1, const_al1, DOUBLE_ALIGN,
1835
  complexdoublesh = getshape(0, const_al1, const_al1, DOUBLE_ALIGN,
1695
			 2*DOUBLE_SZ, cpdhd);
1836
			     2 * DOUBLE_SZ, cpdhd);
1696
#else
1837
#else
1697
  shcomplexsh = getshape(0, const_al1, const_al1, SHREAL_ALIGN,
1838
  shcomplexsh = getshape(0, const_al1, const_al1, SHREAL_ALIGN, 2 * SHREAL_SZ,
1698
			 2*SHREAL_SZ, shcomplexhd);
1839
			 shcomplexhd);
1699
  complexsh = getshape(0, const_al1, const_al1, REAL_ALIGN,
1840
  complexsh = getshape(0, const_al1, const_al1, REAL_ALIGN, 2 * REAL_SZ,
1700
			 2*REAL_SZ, complexhd);
1841
		       complexhd);
1701
  complexdoublesh = getshape(0, const_al1, const_al1, DOUBLE_ALIGN,
1842
  complexdoublesh = getshape(0, const_al1, const_al1, DOUBLE_ALIGN,
1702
			 2*DOUBLE_SZ, complexdoublehd);
1843
			     2 * DOUBLE_SZ, complexdoublehd);
1703
#endif
1844
#endif
1704
  return;
1845
  return;
1705
}
1846
}
1706
 
1847
 
1707
 
1848
 
1708
 
1849
 
1709
floating_variety f_dummy_floating_variety;
1850
floating_variety f_dummy_floating_variety;
1710
 
1851
 
1711
floating_variety f_float_of_complex
1852
floating_variety
1712
    PROTO_N ( (sha) )
-
 
1713
    PROTO_T ( shape sha )
1853
f_float_of_complex(shape sha)
1714
{
1854
{
1715
	int s = shape_size(sha)/2;
1855
	int s = shape_size(sha) / 2;
-
 
1856
	if (s == SHREAL_SZ) {
1716
	if (s==SHREAL_SZ) return shrealfv;
1857
	  return shrealfv;
-
 
1858
	}
-
 
1859
	if (s == REAL_SZ) {
1717
	if (s==REAL_SZ) return realfv;
1860
	  return realfv;
-
 
1861
	}
-
 
1862
	if (s == DOUBLE_SZ) {
1718
	if (s==DOUBLE_SZ) return doublefv;
1863
	  return doublefv;
-
 
1864
	}
1719
	failer("Expecting a complex shape");
1865
	failer("Expecting a complex shape");
1720
 
1866
 
1721
	return f_dummy_floating_variety;
1867
	return f_dummy_floating_variety;
1722
}
1868
}
1723
 
1869
 
1724
floating_variety f_complex_of_float
1870
floating_variety
1725
    PROTO_N ( (sha) )
-
 
1726
    PROTO_T ( shape sha )
1871
f_complex_of_float(shape sha)
1727
{
1872
{
1728
	int s = shape_size(sha);
1873
	int s = shape_size(sha);
-
 
1874
	if (s == SHREAL_SZ) {
1729
	if (s==SHREAL_SZ) return shcomplexfv;
1875
	  return shcomplexfv;
-
 
1876
	}
-
 
1877
	if (s == REAL_SZ) {
1730
	if (s==REAL_SZ) return complexfv;
1878
	  return complexfv;
-
 
1879
	}
-
 
1880
	if (s == DOUBLE_SZ) {
1731
	if (s==DOUBLE_SZ) return complexdoublefv;
1881
	  return complexdoublefv;
-
 
1882
	}
1732
	failer("Expecting a floating shape");
1883
	failer("Expecting a floating shape");
1733
	return f_dummy_floating_variety;
1884
	return f_dummy_floating_variety;
1734
}
1885
}
1735
 
1886
 
1736
floating_variety fv_of_shape
1887
floating_variety
1737
    PROTO_N ( (sha) )
-
 
1738
    PROTO_T ( shape sha )
1888
fv_of_shape(shape sha)
1739
{
1889
{
1740
	int s = shape_size(sha);
1890
	int s = shape_size(sha);
-
 
1891
	if (s == SHREAL_SZ) {
1741
	if (s==SHREAL_SZ) return shrealfv;
1892
	  return shrealfv;
-
 
1893
	}
-
 
1894
	if (s == REAL_SZ) {
1742
	if (s==REAL_SZ) return realfv;
1895
	  return realfv;
-
 
1896
	}
-
 
1897
	if (s == DOUBLE_SZ) {
1743
	if (s==DOUBLE_SZ) return doublefv;
1898
	  return doublefv;
-
 
1899
	}
1744
	failer("Expecting a complex shape");
1900
	failer("Expecting a complex shape");
1745
 
1901
 
1746
	return f_dummy_floating_variety;
1902
	return f_dummy_floating_variety;
1747
}
1903
}
1748
 
1904
 
1749
 
1905
 
1750
 
1906
 
1751
static void square_x_iy
1907
static
1752
    PROTO_N ( (ov_err, arg1, arg2, arg3) )
-
 
1753
    PROTO_T ( error_treatment ov_err X exp *arg1 X exp *arg2 X exp arg3 )
1908
void square_x_iy(error_treatment ov_err, exp *arg1, exp *arg2, exp arg3)
1754
{
1909
{
1755
    exp x = *arg1;
1910
    exp x = *arg1;
1756
    exp y = *arg2;
1911
    exp y = *arg2;
1757
 
1912
 
1758
    exp obtain1_x = me_obtain(x);
1913
    exp obtain1_x = me_obtain(x);
Line 1761... Line 1916...
1761
    exp obtain1_y = me_obtain(y);
1916
    exp obtain1_y = me_obtain(y);
1762
    exp obtain2_y = me_obtain(y);
1917
    exp obtain2_y = me_obtain(y);
1763
    exp obtain3_y = me_obtain(y);
1918
    exp obtain3_y = me_obtain(y);
1764
 
1919
 
1765
    exp minus_x_y = f_floating_minus(ov_err, obtain1_x, obtain1_y);
1920
    exp minus_x_y = f_floating_minus(ov_err, obtain1_x, obtain1_y);
1766
    exp  plus_x_y = f_bin_floating_plus(ov_err, obtain2_x, obtain2_y);
1921
    exp plus_x_y = f_bin_floating_plus(ov_err, obtain2_x, obtain2_y);
1767
    exp  mult_x_y = f_bin_floating_mult(ov_err, obtain3_x, obtain3_y);
1922
    exp mult_x_y = f_bin_floating_mult(ov_err, obtain3_x, obtain3_y);
1768
 
1923
 
1769
    exp tmp = push(arg3, me_startid(sh(x), mult_x_y, 0));
1924
    exp tmp = push(arg3, me_startid(sh(x), mult_x_y, 0));
1770
 
1925
 
1771
    exp obtain1_tmp = hold_check(me_obtain(tmp));
1926
    exp obtain1_tmp = hold_check(me_obtain(tmp));
1772
    exp obtain2_tmp = hold_check(me_obtain(tmp));
1927
    exp obtain2_tmp = hold_check(me_obtain(tmp));
1773
 
1928
 
1774
    exp answer_re  = f_bin_floating_mult(ov_err, minus_x_y, plus_x_y);
1929
    exp answer_re = f_bin_floating_mult(ov_err, minus_x_y, plus_x_y);
1775
    exp answer_im  = f_bin_floating_plus(ov_err, obtain1_tmp, obtain2_tmp);
1930
    exp answer_im = f_bin_floating_plus(ov_err, obtain1_tmp, obtain2_tmp);
1776
 
1931
 
1777
    x = push(tmp, me_startid(sh(x), answer_re, 0));
1932
    x = push(tmp, me_startid(sh(x), answer_re, 0));
1778
    y = push(x, me_startid(sh(x), answer_im, 0));
1933
    y = push(x, me_startid(sh(x), answer_im, 0));
1779
 
1934
 
1780
    *arg1 = x;
1935
    *arg1 = x;
Line 1782... Line 1937...
1782
 
1937
 
1783
    return;
1938
    return;
1784
}
1939
}
1785
 
1940
 
1786
 
1941
 
1787
static void mult_w_by_z
1942
static
1788
    PROTO_N ( (ov_err, arg1, arg2, arg3, arg4, arg5) )
1943
void mult_w_by_z(error_treatment ov_err, exp *arg1, exp *arg2, exp arg3,
1789
    PROTO_T ( error_treatment ov_err X exp *arg1 X exp *arg2 X exp arg3 X exp arg4 X exp arg5 )
1944
		 exp arg4, exp arg5)
1790
{
1945
{
1791
    exp u = *arg1;
1946
    exp u = *arg1;
1792
    exp v = *arg2;
1947
    exp v = *arg2;
1793
    exp x =  arg3;
1948
    exp x =  arg3;
1794
    exp y =  arg4;
1949
    exp y =  arg4;
Line 1809... Line 1964...
1809
    exp mult_y_v = f_bin_floating_mult(ov_err, obtain2_y, obtain2_v);
1964
    exp mult_y_v = f_bin_floating_mult(ov_err, obtain2_y, obtain2_v);
1810
 
1965
 
1811
    exp tmp = push(arg5, me_startid(sh(x), mult_y_u, 0));
1966
    exp tmp = push(arg5, me_startid(sh(x), mult_y_u, 0));
1812
    exp obtain_tmp = hold_check(me_obtain(tmp));
1967
    exp obtain_tmp = hold_check(me_obtain(tmp));
1813
 
1968
 
1814
    exp answer_re  = f_floating_minus(ov_err, mult_x_u, mult_y_v);
1969
    exp answer_re = f_floating_minus(ov_err, mult_x_u, mult_y_v);
1815
    exp answer_im  = f_bin_floating_plus(ov_err, mult_x_v, obtain_tmp);
1970
    exp answer_im = f_bin_floating_plus(ov_err, mult_x_v, obtain_tmp);
1816
 
1971
 
1817
    u = push(tmp, me_startid(sh(x), answer_re, 0));
1972
    u = push(tmp, me_startid(sh(x), answer_re, 0));
1818
    v = push(u, me_startid(sh(x), answer_im, 0));
1973
    v = push(u, me_startid(sh(x), answer_im, 0));
1819
 
1974
 
1820
    *arg1 = u;
1975
    *arg1 = u;
Line 1822... Line 1977...
1822
 
1977
 
1823
    return;
1978
    return;
1824
}
1979
}
1825
 
1980
 
1826
 
1981
 
1827
static exp make_comp_1_z
1982
static exp
1828
    PROTO_N ( (complex_fv, ov_err, contents1_u, contents2_u, contents3_u,
-
 
1829
	       contents1_v, contents2_v, contents3_v) )
-
 
1830
    PROTO_T ( floating_variety complex_fv X error_treatment ov_err X
1983
make_comp_1_z(floating_variety complex_fv, error_treatment ov_err,
1831
	      exp contents1_u X exp contents2_u X exp contents3_u X
1984
	      exp contents1_u, exp contents2_u, exp contents3_u,
1832
	      exp contents1_v X exp contents2_v X exp contents3_v )
1985
	      exp contents1_v, exp contents2_v, exp contents3_v)
1833
{
1986
{
1834
    exp mult_u_u    = f_bin_floating_mult(ov_err, contents1_u, contents2_u);
1987
    exp mult_u_u = f_bin_floating_mult(ov_err, contents1_u, contents2_u);
1835
    exp mult_v_v    = f_bin_floating_mult(ov_err, contents1_v, contents2_v);
1988
    exp mult_v_v = f_bin_floating_mult(ov_err, contents1_v, contents2_v);
1836
    exp mod_squared = f_bin_floating_plus(ov_err, mult_u_u, mult_v_v);
1989
    exp mod_squared = f_bin_floating_plus(ov_err, mult_u_u, mult_v_v);
1837
    exp mod_sq      = me_startid(sh(contents1_u), mod_squared, 0);
1990
    exp mod_sq = me_startid(sh(contents1_u), mod_squared, 0);
1838
 
1991
 
1839
    exp obtain1_mod_sq = me_obtain(mod_sq);
1992
    exp obtain1_mod_sq = me_obtain(mod_sq);
1840
    exp obtain2_mod_sq = me_obtain(mod_sq);
1993
    exp obtain2_mod_sq = me_obtain(mod_sq);
1841
 
1994
 
1842
    exp v_div_mod_sq = f_floating_div(ov_err, contents3_v, obtain2_mod_sq);
1995
    exp v_div_mod_sq = f_floating_div(ov_err, contents3_v, obtain2_mod_sq);
1843
 
1996
 
1844
    exp answer_re = f_floating_div(ov_err, contents3_u, obtain1_mod_sq);
1997
    exp answer_re = f_floating_div(ov_err, contents3_u, obtain1_mod_sq);
1845
    exp answer_im = f_floating_negate(ov_err, v_div_mod_sq);
1998
    exp answer_im = f_floating_negate(ov_err, v_div_mod_sq);
1846
 
1999
 
1847
    exp make_comp = f_make_complex(complex_fv, answer_re, answer_im);
2000
    exp make_comp = f_make_complex(complex_fv, answer_re, answer_im);
1848
    return  me_complete_id(mod_sq, make_comp);
2001
    return me_complete_id(mod_sq, make_comp);
1849
}
2002
}
1850
 
2003
 
1851
 
2004
 
1852
#define is_const(X)  (name(X) != ident_tag)
2005
#define is_const(X)	(name(X) != ident_tag)
1853
 
2006
 
1854
exp_list reorder_list
2007
exp_list
1855
    PROTO_N ( (arg1, consts_first) )
-
 
1856
    PROTO_T ( exp_list arg1 X int consts_first )
2008
reorder_list(exp_list arg1, int consts_first)
1857
{
2009
{
1858
    exp type1_start, type1_end, type2_start, type2_end, t;
2010
    exp type1_start, type1_end, type2_start, type2_end, t;
1859
 
2011
 
1860
    type1_start = type1_end = type2_start = type2_end = nilexp;
2012
    type1_start = type1_end = type2_start = type2_end = nilexp;
1861
    setbro(arg1.end, nilexp);
2013
    setbro(arg1.end, nilexp);
1862
    for (t = arg1.start; t != arg1.end; t=bro(t)) {
2014
    for (t = arg1.start; t != arg1.end; t=bro(t)) {
1863
	if ((is_const(t) && consts_first) || !(is_const(t) || consts_first)) {
2015
	if ((is_const(t) && consts_first) || !(is_const(t) || consts_first)) {
1864
	    if (type1_start == nilexp) {
2016
	    if (type1_start == nilexp) {
1865
		type1_start = type1_end = t;                          /* first of type 1 */
2017
		type1_start = type1_end = t;	/* first of type 1 */
1866
	    } else {
2018
	    } else {
1867
		setbro(type1_end, t);                        /* add to existing type 1's */
2019
		setbro(type1_end, t);		/* add to existing type 1's */
1868
		type1_end = t;
2020
		type1_end = t;
1869
	    }
2021
	    }
1870
	} else {
2022
	} else {
1871
	    if (type2_start == nilexp) {
2023
	    if (type2_start == nilexp) {
1872
		type2_start = type2_end = t;                          /* first of type 2 */
2024
		type2_start = type2_end = t;	/* first of type 2 */
1873
	    } else {
2025
	    } else {
1874
		setbro(type2_end, t);                        /* add to existing type 2's */
2026
		setbro(type2_end, t);		/* add to existing type 2's */
1875
		type2_end = t;
2027
		type2_end = t;
1876
	    }
2028
	    }
1877
	}
2029
	}
1878
    }
2030
    }
1879
 
2031
 
1880
    if ((type1_start != nilexp) && (type2_start != nilexp)) {
2032
    if ((type1_start != nilexp) && (type2_start != nilexp)) {
1881
	arg1.start = type1_start;
2033
	arg1.start = type1_start;
1882
        setbro(type1_end, type2_start);                      /* if list is not a mixture */
2034
        setbro(type1_end, type2_start);	/* if list is not a mixture */
1883
	arg1.end = type2_end;                            /* no reordering has to be done */
2035
	arg1.end = type2_end;		/* no reordering has to be done */
1884
    }
2036
    }
1885
 
2037
 
1886
    return arg1;
2038
    return arg1;
1887
}
2039
}
1888
 
2040
 
1889
 
2041
 
1890
exp me_contents
2042
exp
1891
    PROTO_N ( (arg1) )
-
 
1892
    PROTO_T ( exp arg1 )
2043
me_contents(exp arg1)
1893
{
2044
{
1894
  exp r = me_u3(sh(arg1), me_obtain(arg1), cont_tag);
2045
  exp r = me_u3(sh(arg1), me_obtain(arg1), cont_tag);
1895
 
2046
 
1896
  return hold_check(r);
2047
  return hold_check(r);
1897
}
2048
}
Line 1907... Line 2058...
1907
 
2058
 
1908
     arg1 is the new element
2059
     arg1 is the new element
1909
     arg2 is the top element on the stack
2060
     arg2 is the top element on the stack
1910
 */
2061
 */
1911
 
2062
 
1912
static exp push
2063
static exp
1913
    PROTO_N ( (arg1, arg2) )
-
 
1914
    PROTO_T ( exp arg1 X exp arg2 )
2064
push(exp arg1, exp arg2)
1915
{
2065
{
1916
    setbro(arg2, arg1);
2066
    setbro(arg2, arg1);
1917
    return arg2;
2067
    return arg2;
1918
}
2068
}
1919
 
2069
 
Line 1921... Line 2071...
1921
  /* Take the stack full of "ident_tag" declarations and link them
2071
  /* Take the stack full of "ident_tag" declarations and link them
1922
     together with the last element in the list being "last_link"
2072
     together with the last element in the list being "last_link"
1923
     and the body around which the declarations are put be "link_to".
2073
     and the body around which the declarations are put be "link_to".
1924
  */
2074
  */
1925
 
2075
 
1926
static exp me_complete_chain
2076
static exp
1927
    PROTO_N ( (ident_chain, last_link, link_to) )
-
 
1928
    PROTO_T ( exp ident_chain X exp last_link X exp link_to )
2077
me_complete_chain(exp ident_chain, exp last_link, exp link_to)
1929
{
2078
{
1930
    exp remove_link;
2079
    exp remove_link;
1931
 
2080
 
1932
    while (son(ident_chain) != last_link) {
2081
    while (son(ident_chain) != last_link) {
1933
	remove_link = bro(ident_chain);
2082
	remove_link = bro(ident_chain);
1934
	link_to = me_complete_id(ident_chain, link_to);
2083
	link_to = me_complete_id(ident_chain, link_to);
1935
	ident_chain = remove_link;
2084
	ident_chain = remove_link;
1936
    };
2085
    }
1937
 
2086
 
1938
    return me_complete_id(ident_chain, link_to);
2087
    return me_complete_id(ident_chain, link_to);
1939
}
2088
}
1940
 
2089
 
1941
 
2090
 
1942
 
2091
 
1943
/* Binary version of 'f_floating_plus' */
2092
/* Binary version of 'f_floating_plus' */
1944
 
2093
 
1945
static exp f_bin_floating_plus
2094
static exp
1946
    PROTO_N ( (ov_err, arg1, arg2) )
-
 
1947
    PROTO_T ( error_treatment ov_err X exp arg1 X exp arg2 )
2095
f_bin_floating_plus(error_treatment ov_err, exp arg1, exp arg2)
1948
{
2096
{
1949
  exp_list el;
2097
  exp_list el;
1950
  el = new_exp_list(2);
2098
  el = new_exp_list(2);
1951
  el = add_exp_list(el, arg1, 0);
2099
  el = add_exp_list(el, arg1, 0);
1952
  el = add_exp_list(el, arg2, 1);
2100
  el = add_exp_list(el, arg2, 1);
1953
  return f_floating_plus (ov_err,el);
2101
  return f_floating_plus(ov_err, el);
1954
}
2102
}
1955
 
2103
 
1956
 
2104
 
1957
/* Binary version of 'f_floating_mult' */
2105
/* Binary version of 'f_floating_mult' */
1958
 
2106
 
1959
static exp f_bin_floating_mult
2107
static exp
1960
    PROTO_N ( (ov_err, arg1, arg2) )
-
 
1961
    PROTO_T ( error_treatment ov_err X exp arg1 X exp arg2 )
2108
f_bin_floating_mult(error_treatment ov_err, exp arg1, exp arg2)
1962
{
2109
{
1963
  exp_list el;
2110
  exp_list el;
1964
  el = new_exp_list(2);
2111
  el = new_exp_list(2);
1965
  el = add_exp_list(el, arg1, 0);
2112
  el = add_exp_list(el, arg1, 0);
1966
  el = add_exp_list(el, arg2, 1);
2113
  el = add_exp_list(el, arg2, 1);
1967
  return f_floating_mult (ov_err,el);
2114
  return f_floating_mult(ov_err, el);
1968
}
2115
}
1969
 
2116
 
1970
static exp optimise_with_wrap
2117
static exp
1971
    PROTO_N ( (arg, shape1, shape2) )
-
 
1972
    PROTO_T ( exp arg X shape shape1 X shape shape2 )
2118
optimise_with_wrap(exp arg, shape shape1, shape shape2)
1973
{
2119
{
1974
  if (! eq_shape(shape1,shape2))
2120
  if (!eq_shape(shape1, shape2)) {
1975
    return  f_change_variety (f_wrap, shape2, arg);
2121
    return f_change_variety(f_wrap, shape2, arg);
-
 
2122
  }
1976
 
2123
 
1977
  return (arg);
2124
  return(arg);
1978
}
2125
}
1979
 
2126
 
1980
static exp real_power
2127
static exp
1981
    PROTO_N ( (ov_err, arg1, arg2) )
-
 
1982
    PROTO_T ( error_treatment ov_err X exp arg1 X exp arg2 )
2128
real_power(error_treatment ov_err, exp arg1, exp arg2)
1983
{
2129
{
1984
 
2130
 
1985
    /* Gives shorter .s file if n<10 and arg1 is unknown */
2131
    /* Gives shorter .s file if n<10 and arg1 is unknown */
1986
 
2132
 
1987
    exp real1, sn;
2133
    exp real1, sn;
1988
    exp (*f_real_mult) PROTO_S ((error_treatment, exp, exp));
2134
    exp(*f_real_mult)(error_treatment, exp, exp);
1989
    shape real_shape, integer_shape, tmp_shape;
2135
    shape real_shape, integer_shape, tmp_shape;
1990
 
2136
 
1991
 
2137
 
1992
/* With wrap, we may as well work with 'int's and change back after */
2138
/* With wrap, we may as well work with 'int's and change back after */
1993
 
2139
 
1994
    tmp_shape = sh(arg1);
2140
    tmp_shape = sh(arg1);
1995
    if (is_integer(tmp_shape) && !is_signed(tmp_shape) &&
2141
    if (is_integer(tmp_shape) && !is_signed(tmp_shape) &&
1996
	shape_size(sh(arg1)) < 32 &&
2142
	shape_size(sh(arg1)) < 32 && eq_et(ov_err, f_wrap)) {
1997
	eq_et(ov_err, f_wrap))
-
 
1998
    {
-
 
1999
	arg1 = hold_check (f_change_variety (f_impossible, ulongsh, arg1));
2143
	arg1 = hold_check(f_change_variety(f_impossible, ulongsh, arg1));
2000
    }
2144
    }
2001
 
2145
 
2002
 
2146
 
2003
/* Widen to 'int' if necessary - guarantees negate will work */
2147
/* Widen to 'int' if necessary - guarantees negate will work */
2004
 
2148
 
2005
    if (shape_size(sh(arg2)) < 32) {
2149
    if (shape_size(sh(arg2)) < 32) {
2006
	arg2 = hold_check (f_change_variety (f_impossible, slongsh, arg2));
2150
	arg2 = hold_check(f_change_variety(f_impossible, slongsh, arg2));
2007
    }
2151
    }
2008
 
2152
 
2009
    real_shape = sh(arg1);                       /* shape of the result */
2153
    real_shape = sh(arg1);	/* shape of the result */
2010
    integer_shape = sh(arg2);
2154
    integer_shape = sh(arg2);
2011
    sn = me_startid(integer_shape, arg2, 0);
2155
    sn = me_startid(integer_shape, arg2, 0);
2012
 
2156
 
2013
 
2157
 
2014
/* Identify an exp which represents the value 1 (or 1.0) */
2158
/* Identify an exp which represents the value 1 (or 1.0) */
2015
 
2159
 
2016
    if (is_integer(real_shape)) {
2160
    if (is_integer(real_shape)) {
2017
	real1 = me_shint(real_shape,1);
2161
	real1 = me_shint(real_shape,1);
2018
    }
-
 
2019
    else {
2162
    } else {
2020
	real1 = me_shint(integer_shape,1);
2163
	real1 = me_shint(integer_shape,1);
2021
	real1 = f_float_int (f_impossible, fv_of_shape(real_shape), real1);
2164
	real1 = f_float_int(f_impossible, fv_of_shape(real_shape), real1);
2022
	real1 = hold_check (real1);		/* This should be reduced to 1.0 */
2165
	real1 = hold_check (real1);	/* This should be reduced to 1.0 */
2023
    }
2166
    }
2024
    real1 = push (sn, me_startid(real_shape, real1, 0));
2167
    real1 = push(sn, me_startid(real_shape, real1, 0));
2025
 
2168
 
2026
 
2169
 
2027
/* Decide which is the suitable function for multiplying two numbers */
2170
/* Decide which is the suitable function for multiplying two numbers */
2028
 
2171
 
2029
    f_real_mult = (is_integer(real_shape) ? f_mult : f_bin_floating_mult);
2172
    f_real_mult = (is_integer(real_shape)? f_mult : f_bin_floating_mult);
2030
 
2173
 
2031
    if (is_constant_arg(arg2) ||
2174
    if (is_constant_arg(arg2) ||
2032
	((name(arg2) == name_tag) && (name(son(arg2)) == ident_tag)
2175
	((name(arg2) == name_tag) && (name(son(arg2)) == ident_tag) &&
2033
	   && !isvar(son(arg2)) && is_constant_arg(son(son(arg2)))))
2176
	 !isvar(son(arg2)) && is_constant_arg(son(son(arg2))))) {
2034
    {                                                                /* we know the power */
2177
	/* we know the power */
2035
	int exponent;
2178
	int exponent;
2036
	exp x;
2179
	exp x;
2037
 
2180
 
2038
	if (is_constant_arg(arg2)) {
2181
	if (is_constant_arg(arg2)) {
2039
	    exponent = no(arg2);	/* arg2 is a constant */
2182
	    exponent = no(arg2);	/* arg2 is a constant */
2040
	}
-
 
2041
	else {
2183
	} else {
2042
	    exponent = no(son(son(arg2)));
2184
	    exponent = no(son(son(arg2)));
2043
		/* arg2 identifies a constant */
2185
		/* arg2 identifies a constant */
2044
	}
2186
	}
2045
 
2187
 
2046
	if (exponent < 0) {
2188
	if (exponent < 0) {
2047
	    if (is_integer(real_shape)) {
2189
	    if (is_integer(real_shape)) {
2048
		failer("constant value out of range: power: must be non-negative");
2190
		failer("constant value out of range: power: must be non-negative");
2049
	    }
2191
	    } else {
2050
	    else {        	/* take reciprocal */
2192
		/* take reciprocal */
2051
		arg1 = hold_check (f_floating_div (ov_err, me_obtain(real1), arg1));
2193
		arg1 = hold_check(f_floating_div(ov_err, me_obtain(real1),
-
 
2194
						 arg1));
2052
	    }
2195
	    }
2053
	}
2196
	}
2054
	x = push (real1, me_startid(real_shape, arg1, 0));
2197
	x = push(real1, me_startid(real_shape, arg1, 0));
2055
 
2198
 
2056
	if (exponent == 0) {
2199
	if (exponent == 0) {
2057
	    return  me_complete_chain (x, arg2, optimise_with_wrap (
2200
	    return me_complete_chain(x, arg2,
-
 
2201
				     optimise_with_wrap(me_obtain(real1),
2058
			   me_obtain(real1), real_shape, tmp_shape));
2202
							real_shape, tmp_shape));
2059
	}
2203
	}
2060
 
2204
 
2061
	{
2205
	{
2062
	    exp  w, mylast = x;
2206
	    exp w, mylast = x;
2063
	    int n = abs(exponent);
2207
	    int n = abs(exponent);
2064
 
2208
 
2065
	    while ((n % 2) == 0) {
2209
	    while ((n % 2) == 0) {
2066
		exp mult_x_x;
2210
		exp mult_x_x;
2067
		mult_x_x = (*f_real_mult)(ov_err, me_obtain(x), me_obtain(x));
2211
		mult_x_x = (*f_real_mult)(ov_err, me_obtain(x), me_obtain(x));
2068
		mylast = x = push (mylast,
2212
		mylast = x = push(mylast, me_startid(real_shape,
2069
			 me_startid(real_shape, hold_check(mult_x_x), 0));
2213
						     hold_check(mult_x_x), 0));
2070
		n = n / 2;
2214
		n = n / 2;
2071
	    }
2215
	    }
2072
 
2216
 
2073
	    if (n == 1) {
2217
	    if (n == 1) {
-
 
2218
		/* return x  */
2074
		return  me_complete_chain (x, arg2, optimise_with_wrap (
2219
		return me_complete_chain(x, arg2,
2075
				me_obtain(x), real_shape, tmp_shape));        /* return x  */
2220
					 optimise_with_wrap(me_obtain(x),
-
 
2221
							    real_shape,
-
 
2222
							    tmp_shape));
2076
	    }
2223
	    }
-
 
2224
	    else {
2077
	    else {                      	                             /*  w = x  */
2225
		/*  w = x  */
2078
		mylast = w = push (x, me_startid(real_shape, me_obtain(x), 0));
2226
		mylast = w = push(x, me_startid(real_shape, me_obtain(x), 0));
2079
	    }
2227
	    }
2080
 
2228
 
2081
	    while (n != 1) {
2229
	    while (n != 1) {
2082
		exp mult_x_x;
2230
		exp mult_x_x;
2083
		mult_x_x = (*f_real_mult)(ov_err, me_obtain(x), me_obtain(x));
2231
		mult_x_x = (*f_real_mult)(ov_err, me_obtain(x), me_obtain(x));
2084
		mylast = x = push (mylast,
2232
		mylast = x = push(mylast, me_startid(real_shape,
2085
			me_startid(real_shape, hold_check(mult_x_x), 0));
2233
						     hold_check(mult_x_x), 0));
2086
		n = n / 2;
2234
		n = n / 2;
2087
		if ((n % 2) == 1) {
2235
		if ((n % 2) == 1) {
2088
		    exp mult_w_x;
2236
		    exp mult_w_x;
2089
		    mult_w_x = (*f_real_mult)(ov_err, me_obtain(w), me_obtain(x));
2237
		    mult_w_x = (*f_real_mult)(ov_err, me_obtain(w),
-
 
2238
					      me_obtain(x));
2090
		    mylast = w = push (mylast,
2239
		    mylast = w = push(mylast, me_startid(real_shape,
2091
			me_startid(real_shape, hold_check(mult_w_x), 0));
2240
							 hold_check(mult_w_x),
-
 
2241
							 0));
2092
		}
2242
		}
2093
	    }
2243
	    }
2094
 
2244
 
-
 
2245
	    /*  return w  */
2095
	    return  me_complete_chain (w, arg2, optimise_with_wrap (
2246
	    return me_complete_chain(w, arg2, optimise_with_wrap(me_obtain(w),
-
 
2247
								 real_shape,
2096
				me_obtain(w), real_shape, tmp_shape));    /*  return w  */
2248
								 tmp_shape));
2097
	}
2249
	}
2098
 
-
 
2099
    } else {
2250
    } else {
2100
 
-
 
2101
	exp  reinitialise_w, main_loop, make_comp;              /* main building blocks */
2251
	exp reinitialise_w, main_loop, make_comp; /* main building blocks */
2102
	exp  square_x, mult_x_w, half_n, update_w, repeat_body;
2252
	exp square_x, mult_x_w, half_n, update_w, repeat_body;
2103
	exp  seq, w, x, n;
2253
	exp seq, w, x, n;
2104
 
2254
 
2105
	n = me_obtain(sn);
2255
	n = me_obtain(sn);
2106
	if (!is_integer(real_shape)) {	/* Must be positive for integer powers */
2256
	if (!is_integer(real_shape)) { /* Must be positive for integer powers */
2107
	    n = f_abs (f_impossible, n);
2257
	    n = f_abs(f_impossible, n);
2108
	}
2258
	}
2109
 
2259
 
2110
	n = push (real1, me_startid (integer_shape, n, 1));
2260
	n = push(real1, me_startid(integer_shape, n, 1));
2111
	w = push (n, me_startid(real_shape, me_obtain(real1), 1));
2261
	w = push(n, me_startid(real_shape, me_obtain(real1), 1));
2112
	x = push (w, me_startid(real_shape, arg1, 1));
2262
	x = push(w, me_startid(real_shape, arg1, 1));
2113
 
-
 
2114
 
2263
 
2115
	/*  change value of w to z if n is odd  */
2264
	/*  change value of w to z if n is odd  */
2116
 
-
 
2117
	{
2265
	{
2118
	    exp rem_n_2 = f_and (me_contents(n), me_shint(integer_shape, 1));
2266
	    exp rem_n_2 = f_and(me_contents(n), me_shint(integer_shape, 1));
2119
	    exp assign_w = f_assign (me_obtain(w), me_contents(x));
2267
	    exp assign_w = f_assign(me_obtain(w), me_contents(x));
2120
	    exp alt_labst = hold_check(me_b3(f_top, f_make_value(f_top),
2268
	    exp alt_labst = hold_check(me_b3(f_top, f_make_value(f_top),
2121
					       f_make_top(), labst_tag));
2269
					     f_make_top(), labst_tag));
2122
	    exp is_n_odd = f_integer_test (no_nat_option, f_equal, make_label(alt_labst),
2270
	    exp is_n_odd = f_integer_test(no_nat_option, f_equal,
-
 
2271
					  make_label(alt_labst), rem_n_2,
2123
				rem_n_2, me_shint(integer_shape, 1));
2272
					  me_shint(integer_shape, 1));
2124
	    exp seq = f_sequence (add_exp_list(new_exp_list(1), is_n_odd, 0), assign_w);
2273
	    exp seq = f_sequence(add_exp_list(new_exp_list(1), is_n_odd, 0),
-
 
2274
				 assign_w);
2125
	    reinitialise_w = hold_check(me_b3(lub_shape(sh(seq),sh(alt_labst)),
2275
	    reinitialise_w = hold_check(me_b3(lub_shape(sh(seq),sh(alt_labst)),
2126
					      seq, alt_labst, cond_tag));
2276
					      seq, alt_labst, cond_tag));
2127
	}
2277
	}
2128
 
2278
 
2129
	/*  x=x*x  */
2279
	/*  x=x*x  */
2130
	{
2280
	{
2131
	    exp mult_x_x;
2281
	    exp mult_x_x;
2132
	    mult_x_x = (*f_real_mult) (ov_err, me_contents(x), me_contents(x));
2282
	    mult_x_x = (*f_real_mult)(ov_err, me_contents(x), me_contents(x));
2133
	    square_x = f_assign (me_obtain(x), mult_x_x);
2283
	    square_x = f_assign(me_obtain(x), mult_x_x);
2134
	}
2284
	}
2135
 
2285
 
2136
	/*  w=x*w  */
2286
	/*  w=x*w  */
2137
	{
2287
	{
2138
	    exp answer;
2288
	    exp answer;
2139
	    answer = (*f_real_mult)(ov_err, me_contents(x), me_contents(w));
2289
	    answer = (*f_real_mult)(ov_err, me_contents(x), me_contents(w));
2140
	    mult_x_w = f_assign (me_obtain(w), answer);
2290
	    mult_x_w = f_assign(me_obtain(w), answer);
2141
	}
2291
	}
2142
 
2292
 
2143
	/*  n=n/2  */
2293
	/*  n = n / 2  */
2144
	{
2294
	{
2145
	    exp answer = f_shift_right (me_contents(n), me_shint(integer_shape, 1));
2295
	    exp answer = f_shift_right(me_contents(n),
-
 
2296
				       me_shint(integer_shape, 1));
2146
	    half_n = f_assign (me_obtain(n), answer);
2297
	    half_n = f_assign(me_obtain(n), answer);
2147
	}
2298
	}
2148
 
2299
 
2149
	/*  if n is odd then w = z*w  */
2300
	/*  if n is odd then w = z * w  */
2150
	{
2301
	{
2151
	    exp rem_n_2 = f_and (me_contents(n), me_shint(integer_shape, 1));
2302
	    exp rem_n_2 = f_and(me_contents(n), me_shint(integer_shape, 1));
2152
	    exp alt_labst = hold_check(me_b3(f_top, f_make_value(f_top),
2303
	    exp alt_labst = hold_check(me_b3(f_top, f_make_value(f_top),
2153
					     f_make_top(), labst_tag));
2304
					     f_make_top(), labst_tag));
2154
	    exp is_n_odd = f_integer_test (no_nat_option, f_equal, make_label(alt_labst),
2305
	    exp is_n_odd = f_integer_test(no_nat_option, f_equal,
-
 
2306
					  make_label(alt_labst),
2155
					   rem_n_2, me_shint(integer_shape, 1));
2307
					  rem_n_2, me_shint(integer_shape, 1));
2156
	    exp seq = f_sequence (add_exp_list(new_exp_list(1),
2308
	    exp seq = f_sequence(add_exp_list(new_exp_list(1),
2157
					is_n_odd, 0), mult_x_w);
2309
					      is_n_odd, 0), mult_x_w);
2158
	    update_w = hold_check(me_b3(lub_shape(sh(seq),sh(alt_labst)),
2310
	    update_w = hold_check(me_b3(lub_shape(sh(seq),sh(alt_labst)),
2159
					seq, alt_labst, cond_tag));
2311
					seq, alt_labst, cond_tag));
2160
	}
2312
	}
2161
 
2313
 
2162
	/*  repeat + body  */
2314
	/*  repeat + body  */
2163
	{
2315
	{
2164
	    exp body_labst, if_n_equals_1;
2316
	    exp body_labst, if_n_equals_1;
2165
	    exp_list st;
2317
	    exp_list st;
2166
 
2318
 
2167
	    body_labst = hold_check(me_b3(f_top, f_make_value(f_top), f_make_top(), labst_tag));
2319
	    body_labst = hold_check(me_b3(f_top, f_make_value(f_top),
-
 
2320
					  f_make_top(), labst_tag));
2168
 
2321
 
2169
	    if_n_equals_1 = f_integer_test (no_nat_option, f_equal, make_label(body_labst),
2322
	    if_n_equals_1 = f_integer_test(no_nat_option, f_equal,
-
 
2323
					   make_label(body_labst),
-
 
2324
					   me_contents(n),
2170
					    me_contents(n), me_shint(integer_shape, 1));
2325
					   me_shint(integer_shape, 1));
2171
 
2326
 
2172
	    st = new_exp_list(1);
2327
	    st = new_exp_list(1);
2173
	    st = add_exp_list(st, square_x, 0);
2328
	    st = add_exp_list(st, square_x, 0);
2174
	    st = add_exp_list(st, half_n, 1);
2329
	    st = add_exp_list(st, half_n, 1);
2175
	    st = add_exp_list(st, update_w, 2);
2330
	    st = add_exp_list(st, update_w, 2);
2176
	    seq = f_sequence (st, if_n_equals_1);
2331
	    seq = f_sequence(st, if_n_equals_1);
2177
 
2332
 
2178
	    setbro (son(body_labst), seq);
2333
	    setbro(son(body_labst), seq);
2179
	    setsh (body_labst, sh (seq));                    /*  put seq into the body  */
2334
	    setsh (body_labst, sh (seq));	/*  put seq into the body  */
2180
	    clearlast (son(body_labst));                     /*  of the labst           */
2335
	    clearlast (son(body_labst));	/*  of the labst           */
2181
	    setfather (body_labst, seq);
2336
	    setfather(body_labst, seq);
2182
 
2337
 
2183
	    repeat_body = hold_check(me_b3(sh(body_labst), f_make_top(), body_labst, rep_tag));
2338
	    repeat_body = hold_check(me_b3(sh(body_labst), f_make_top(),
-
 
2339
					   body_labst, rep_tag));
2184
	    note_repeat(repeat_body);
2340
	    note_repeat(repeat_body);
2185
	}
2341
	}
2186
 
2342
 
2187
	/*  make loop - only done if  mod(n) > 1  */
2343
	/*  make loop - only done if  mod(n) > 1  */
2188
	{
2344
	{
2189
	    exp alt_labst = hold_check(me_b3(f_top, f_make_value(f_top),
2345
	    exp alt_labst = hold_check(me_b3(f_top, f_make_value(f_top),
2190
					   f_make_top(), labst_tag));
2346
					     f_make_top(), labst_tag));
2191
	    exp is_n_gt_1 = f_integer_test (no_nat_option, f_greater_than, make_label(alt_labst),
2347
	    exp is_n_gt_1 = f_integer_test(no_nat_option, f_greater_than,
-
 
2348
					   make_label(alt_labst),
-
 
2349
					   me_contents(n),
2192
					    me_contents(n), me_shint(integer_shape, 1));
2350
					   me_shint(integer_shape, 1));
2193
	    exp seq = f_sequence (add_exp_list(new_exp_list(1),
2351
	    exp seq = f_sequence(add_exp_list(new_exp_list(1),
2194
					 is_n_gt_1, 0), repeat_body);
2352
					      is_n_gt_1, 0), repeat_body);
2195
	    main_loop = hold_check(me_b3(lub_shape(sh(seq),sh(alt_labst)),
2353
	    main_loop = hold_check(me_b3(lub_shape(sh(seq),sh(alt_labst)),
2196
					 seq, alt_labst, cond_tag));
2354
					 seq, alt_labst, cond_tag));
2197
	}
2355
	}
2198
 
2356
 
2199
	if (is_integer(real_shape)) {
2357
	if (is_integer(real_shape)) {
2200
	    make_comp = me_contents(w);
2358
	    make_comp = me_contents(w);
2201
	}
-
 
2202
	else {
2359
	} else {
2203
	    exp make_comp2 = f_floating_div(ov_err, me_obtain(real1), me_contents(w));
2360
	    exp make_comp2 = f_floating_div(ov_err, me_obtain(real1),
-
 
2361
					    me_contents(w));
2204
	    exp alt_labst = hold_check(me_b3(real_shape, f_make_value(f_top),
2362
	    exp alt_labst = hold_check(me_b3(real_shape, f_make_value(f_top),
2205
					     make_comp2, labst_tag));
2363
					     make_comp2, labst_tag));
2206
	    exp is_arg2_positive = f_integer_test (no_nat_option, f_greater_than_or_equal,
2364
	    exp is_arg2_positive = f_integer_test(no_nat_option,
-
 
2365
						  f_greater_than_or_equal,
2207
					       make_label(alt_labst), me_obtain(sn),
2366
						  make_label(alt_labst),
-
 
2367
						  me_obtain(sn),
2208
					       me_shint(integer_shape, 0));
2368
						  me_shint(integer_shape, 0));
2209
	    exp seq = f_sequence (add_exp_list(new_exp_list(1),
2369
	    exp seq = f_sequence(add_exp_list(new_exp_list(1),
2210
			       	is_arg2_positive, 0), me_contents(w));
2370
					      is_arg2_positive, 0),
-
 
2371
				 me_contents(w));
2211
 
2372
 
2212
	    make_comp = hold_check(me_b3(lub_shape(sh(seq),sh(alt_labst)),
2373
	    make_comp = hold_check(me_b3(lub_shape(sh(seq),sh(alt_labst)), seq,
2213
					 seq, alt_labst, cond_tag));
2374
					 alt_labst, cond_tag));
2214
	}
2375
	}
2215
 
2376
 
2216
	seq = f_sequence (add_exp_list (add_exp_list(new_exp_list(1),
2377
	seq = f_sequence(add_exp_list(add_exp_list(new_exp_list(1),
-
 
2378
						   reinitialise_w, 0),
2217
				reinitialise_w, 0), main_loop, 1), make_comp);
2379
				      main_loop, 1), make_comp);
2218
	seq = optimise_with_wrap (seq, real_shape, tmp_shape);
2380
	seq = optimise_with_wrap(seq, real_shape, tmp_shape);
2219
	return  me_complete_chain(x, arg2, seq);
2381
	return  me_complete_chain(x, arg2, seq);
2220
    }
2382
    }
2221
}
2383
}