CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

| Download

GAP 4.8.9 installation with standard packages -- copy to your CoCalc project to get it

Path: gap4r8 / src / ariths.c
Views: 418346
1
/****************************************************************************
2
**
3
*W ariths.c GAP source Frank Celler
4
*W & Martin Schönert
5
**
6
**
7
*Y Copyright (C) 1996, Lehrstuhl D für Mathematik, RWTH Aachen, Germany
8
*Y (C) 1998 School Math and Comp. Sci., University of St Andrews, Scotland
9
*Y Copyright (C) 2002 The GAP Group
10
**
11
** This file contains the functions of the arithmetic operations package.
12
*/
13
#include "system.h" /* system dependent part */
14
15
16
#include "gasman.h" /* garbage collector */
17
#include "objects.h" /* objects */
18
#include "scanner.h" /* scanner */
19
20
#include "gap.h" /* error handling, initialisation */
21
22
#include "gvars.h" /* global variables */
23
#include "calls.h" /* generic call mechanism */
24
#include "opers.h" /* generic operations */
25
26
#include "ariths.h" /* basic arithmetic */
27
28
#include "bool.h" /* booleans */
29
30
#include "records.h" /* generic records */
31
#include "precord.h" /* plain records */
32
33
#include "lists.h" /* generic lists */
34
#include "string.h" /* strings */
35
36
#include "code.h" /* coder */
37
#include "thread.h" /* threads */
38
#include "tls.h" /* thread-local storage */
39
40
41
42
/****************************************************************************
43
**
44
45
*F * * * * * * * * * * * unary arithmetic operations * * * * * * * * * * * *
46
*/
47
48
/****************************************************************************
49
**
50
*V ZeroFuncs[ <type> ] . . . . . . . . . . . . . . . . table of zero methods
51
*/
52
ArithMethod1 ZeroFuncs [LAST_VIRTUAL_TNUM+1];
53
54
55
/****************************************************************************
56
**
57
*F ZeroObject( <obj> ) . . . . . . . . . . . . . . . . . . . . call methsel
58
*/
59
Obj ZEROOp;
60
61
Obj ZeroObject (
62
Obj obj )
63
64
{
65
Obj val;
66
val = DoOperation1Args( ZEROOp, obj );
67
while (val == 0)
68
val = ErrorReturnObj("ZEROOp: method should have returned a value", 0L, 0L,
69
"you can supply one by 'return <value>;'");
70
return val;
71
}
72
73
74
/****************************************************************************
75
**
76
*F VerboseZeroObject( <obj> ) . . . . . . . . . . . . call verbose methsel
77
*/
78
Obj VerboseZeroObject (
79
Obj obj )
80
81
{
82
Obj val;
83
val = DoVerboseOperation1Args( ZEROOp, obj );
84
while (val == 0)
85
val = ErrorReturnObj("ZEROOp: method should have returned a value", 0L, 0L,
86
"you can supply one by 'return <value>;'");
87
return val;
88
}
89
90
91
/****************************************************************************
92
**
93
*F InstallZeroObject( <verb> ) . . . . . . . . . . . . install zero methods
94
*/
95
void InstallZeroObject ( Int verb )
96
{
97
UInt t1; /* type of left operand */
98
ArithMethod1 func; /* zero function */
99
100
func = ( verb ? VerboseZeroObject : ZeroObject );
101
for ( t1 = FIRST_EXTERNAL_TNUM; t1 <= LAST_EXTERNAL_TNUM; t1++ ) {
102
ZeroFuncs[t1] = func;
103
}
104
ZeroFuncs[ T_PREC ] = func;
105
ZeroFuncs[ T_PREC +IMMUTABLE ] = func;
106
}
107
108
109
/****************************************************************************
110
**
111
*F FuncZERO( <self>, <obj> ) . . . . . . . . . . . . . . . . . . call 'ZERO'
112
*/
113
Obj FuncZERO (
114
Obj self,
115
Obj obj )
116
{
117
return ZERO(obj);
118
}
119
120
/****************************************************************************
121
**
122
*V ZeroMutFuncs[ <type> ] . . . . . . . . . . . . . . . . table of zero methods
123
*/
124
ArithMethod1 ZeroMutFuncs [LAST_VIRTUAL_TNUM+1];
125
126
127
/****************************************************************************
128
**
129
*F ZeroMutObject( <obj> ) . . . . . . . . . . . . . . . . . . . . call methsel
130
*/
131
Obj ZeroOp;
132
133
Obj ZeroMutObject (
134
Obj obj )
135
136
{
137
Obj val;
138
val = DoOperation1Args( ZeroOp, obj );
139
while (val == 0)
140
val = ErrorReturnObj("ZeroOp: method should have returned a value", 0L, 0L,
141
"you can supply one by 'return <value>;'");
142
return val;
143
}
144
145
146
/****************************************************************************
147
**
148
*F VerboseZeroMutObject( <obj> ) . . . . . . . . . . . . call verbose methsel
149
*/
150
Obj VerboseZeroMutObject (
151
Obj obj )
152
153
{
154
Obj val;
155
val = DoVerboseOperation1Args( ZeroOp, obj );
156
while (val == 0)
157
val = ErrorReturnObj("ZeroOp: method should have returned a value", 0L, 0L,
158
"you can supply one by 'return <value>;'");
159
return val;
160
}
161
162
163
/****************************************************************************
164
**
165
*F InstallZeroMutObject( <verb> ) . . . . . . . . . . . . install zero methods
166
*/
167
void InstallZeroMutObject ( Int verb )
168
{
169
UInt t1; /* type of left operand */
170
ArithMethod1 func; /* zero function */
171
172
func = ( verb ? VerboseZeroMutObject : ZeroMutObject );
173
for ( t1 = FIRST_EXTERNAL_TNUM; t1 <= LAST_EXTERNAL_TNUM; t1++ ) {
174
ZeroMutFuncs[t1] = func;
175
}
176
ZeroMutFuncs[ T_PREC ] = func;
177
ZeroMutFuncs[ T_PREC +IMMUTABLE ] = func;
178
}
179
180
181
/****************************************************************************
182
**
183
*F FuncZERO_MUT( <self>, <obj> ) . . . . . . . . . . . . . . call 'ZERO_MUT'
184
*/
185
Obj FuncZERO_MUT (
186
Obj self,
187
Obj obj )
188
{
189
return ZERO_MUT(obj);
190
}
191
192
193
/****************************************************************************
194
**
195
*V AInvFuncs[ <type> ] . . . . . . . . . . table of additive inverse methods
196
*V AInvMutFuncs[ <type> ] . . . . . . . . table of additive inverse methods
197
** which return mutable results
198
*/
199
ArithMethod1 AInvFuncs [LAST_VIRTUAL_TNUM+1];
200
ArithMethod1 AInvMutFuncs[ LAST_VIRTUAL_TNUM + 1];
201
202
203
/****************************************************************************
204
**
205
*F AInvObj( <obj> ) . . . . . . . . . . . . . . . . . . . . . call methsel
206
*/
207
Obj AInvOp;
208
209
Obj AInvObject (
210
Obj obj )
211
{
212
Obj val;
213
val = DoOperation1Args( AInvOp, obj );
214
while (val == 0)
215
val = ErrorReturnObj("AInvOp: method should have returned a value", 0L, 0L,
216
"you can supply one by 'return <value>;'");
217
return val;
218
}
219
220
221
/****************************************************************************
222
**
223
*F VerboseAInvObject( <obj> ) . . . . . . . . . . . . call verbose methsel
224
*/
225
Obj VerboseAInvObject (
226
Obj obj )
227
{
228
Obj val;
229
val = DoVerboseOperation1Args( AInvOp, obj );
230
while (val == 0)
231
val = ErrorReturnObj("AInvOp: method should have returned a value", 0L, 0L,
232
"you can supply one by 'return <value>;'");
233
return val;
234
}
235
236
237
/****************************************************************************
238
**
239
*F InstallAinvObject( <verb> ) . . . . . . install additive inverse methods
240
*/
241
void InstallAinvObject ( Int verb )
242
{
243
UInt t1; /* type of left operand */
244
ArithMethod1 func; /* ainv function */
245
246
func = ( verb ? VerboseAInvObject : AInvObject );
247
for ( t1 = FIRST_EXTERNAL_TNUM; t1 <= LAST_EXTERNAL_TNUM; t1++ ) {
248
AInvFuncs[t1] = func;
249
}
250
AInvFuncs[ T_PREC ] = func;
251
AInvFuncs[ T_PREC +IMMUTABLE ] = func;
252
}
253
254
255
/****************************************************************************
256
**
257
*F FuncAINV( <self>, <obj> ) . . . . . . . . . . . . . . . . . . call 'AINV'
258
*/
259
Obj FuncAINV (
260
Obj self,
261
Obj obj )
262
{
263
return AINV(obj);
264
}
265
266
/****************************************************************************
267
**
268
*F AInvMutObject( <obj> ) . .. . . . . . . . . . . . . . . . . call methsel
269
*/
270
Obj AdditiveInverseOp;
271
272
Obj AInvMutObject (
273
Obj obj )
274
{
275
Obj val;
276
val = DoOperation1Args( AdditiveInverseOp, obj );
277
while (val == 0)
278
val = ErrorReturnObj("AdditiveInverseOp: method should have returned a value", 0L, 0L,
279
"you can supply one by 'return <value>;'");
280
return val;
281
}
282
283
284
/****************************************************************************
285
**
286
*F VerboseAInvMutObject( <obj> ) . . . . . . . . . . . . call verbose methsel
287
*/
288
Obj VerboseAInvMutObject (
289
Obj obj )
290
{
291
Obj val;
292
val = DoVerboseOperation1Args( AdditiveInverseOp, obj );
293
while (val == 0)
294
val = ErrorReturnObj("AdditiveInverseOp: method should have returned a value", 0L, 0L,
295
"you can supply one by 'return <value>;'");
296
return val;
297
}
298
299
300
/****************************************************************************
301
**
302
*F InstallAinvMutObject( <verb> ) . . . . . . install additive inverse methods
303
*/
304
void InstallAinvMutObject ( Int verb )
305
{
306
UInt t1; /* type of left operand */
307
ArithMethod1 func; /* ainv function */
308
309
func = ( verb ? VerboseAInvMutObject : AInvMutObject );
310
for ( t1 = FIRST_EXTERNAL_TNUM; t1 <= LAST_EXTERNAL_TNUM; t1++ ) {
311
AInvMutFuncs[t1] = func;
312
}
313
AInvMutFuncs[ T_PREC ] = func;
314
AInvMutFuncs[ T_PREC +IMMUTABLE ] = func;
315
}
316
317
318
/****************************************************************************
319
**
320
*F FuncAINV_MUT( <self>, <obj> ) . . . . . . . . . . . . . . . . . . call 'AINV'
321
*/
322
Obj FuncAINV_MUT (
323
Obj self,
324
Obj obj )
325
{
326
return AINV_MUT(obj);
327
}
328
329
330
/****************************************************************************
331
**
332
333
*V OneFuncs[ <type> ] . . . . . . . . . . . . . . . . table of one methods
334
*/
335
ArithMethod1 OneFuncs [LAST_VIRTUAL_TNUM+1];
336
337
338
/****************************************************************************
339
**
340
*F OneObject( <obj> ) . . . . . . . . . . . . . . . . . . . . call methsel
341
*/
342
Obj OneOp;
343
344
Obj OneObject (
345
Obj obj )
346
{
347
Obj val;
348
val = DoOperation1Args( OneOp, obj );
349
while (val == 0)
350
val = ErrorReturnObj("OneOp: method should have returned a value", 0L, 0L,
351
"you can supply one by 'return <value>;'");
352
return val;
353
}
354
355
356
/****************************************************************************
357
**
358
*F VerboseOneObject( <obj> ) . . . . . . . . . . . . . . . . . call methsel
359
*/
360
Obj VerboseOneObject (
361
Obj obj )
362
{
363
Obj val;
364
val = DoVerboseOperation1Args( OneOp, obj );
365
while (val == 0)
366
val = ErrorReturnObj("OneOp: method should have returned a value", 0L, 0L,
367
"you can supply one by 'return <value>;'");
368
return val;
369
}
370
371
372
/****************************************************************************
373
**
374
*F InstallOneObject( <verb> ) . . . . . . . . . . . . . install one methods
375
*/
376
void InstallOneObject ( Int verb )
377
{
378
UInt t1; /* type of left operand */
379
ArithMethod1 func; /* one function */
380
381
func = ( verb ? VerboseOneObject : OneObject );
382
for ( t1 = FIRST_EXTERNAL_TNUM; t1 <= LAST_EXTERNAL_TNUM; t1++ ) {
383
OneFuncs[t1] = func;
384
}
385
OneFuncs[ T_PREC ] = func;
386
OneFuncs[ T_PREC +IMMUTABLE ] = func;
387
}
388
389
390
/****************************************************************************
391
**
392
*F FuncONE( <self>, <obj> ) . . . . . . . . . . . . . . . . . call 'ONE'
393
*/
394
Obj FuncONE (
395
Obj self,
396
Obj obj )
397
{
398
return ONE(obj);
399
}
400
401
/****************************************************************************
402
**
403
404
*V OneMutFuncs[ <type> ] . . . . .table of mutability retaining one methods
405
*/
406
ArithMethod1 OneMutFuncs [LAST_VIRTUAL_TNUM+1];
407
408
409
/****************************************************************************
410
**
411
*F OneMutObject( <obj> ) . . . . . . . . . . . . . . . . . . . . call methsel
412
*/
413
Obj OneMutOp;
414
415
Obj OneMutObject (
416
Obj obj )
417
{
418
Obj val;
419
val = DoOperation1Args( OneMutOp, obj );
420
while (val == 0)
421
val = ErrorReturnObj("ONEOp: method should have returned a value", 0L, 0L,
422
"you can supply one by 'return <value>;'");
423
return val;
424
}
425
426
427
/****************************************************************************
428
**
429
*F VerboseOneMutObject( <obj> ) . . . . . . . . . . . . . . . call methsel
430
*/
431
Obj VerboseOneMutObject (
432
Obj obj )
433
{
434
Obj val;
435
val = DoVerboseOperation1Args( OneMutOp, obj );
436
while (val == 0)
437
val = ErrorReturnObj("ONEOp: method should have returned a value", 0L, 0L,
438
"you can supply one by 'return <value>;'");
439
return val;
440
}
441
442
443
/****************************************************************************
444
**
445
*F InstallOneMutObject( <verb> ) . . . . . . . . . . . . . install one methods
446
*/
447
void InstallOneMutObject ( Int verb )
448
{
449
UInt t1; /* type of left operand */
450
ArithMethod1 func; /* one function */
451
452
func = ( verb ? VerboseOneMutObject : OneMutObject );
453
for ( t1 = FIRST_EXTERNAL_TNUM; t1 <= LAST_EXTERNAL_TNUM; t1++ ) {
454
OneMutFuncs[t1] = func;
455
}
456
OneMutFuncs[ T_PREC ] = func;
457
OneMutFuncs[ T_PREC +IMMUTABLE ] = func;
458
}
459
460
461
/****************************************************************************
462
**
463
*F FuncONE_MUT( <self>, <obj> ) . . . . . . . . . . . . . . . .call 'ONE_MUT'
464
*/
465
Obj FuncONE_MUT (
466
Obj self,
467
Obj obj )
468
{
469
return ONE_MUT(obj);
470
}
471
472
473
/****************************************************************************
474
**
475
476
*V InvFuncs[ <type> ] . . . . . . . . . . . . . table of inverse functions
477
*/
478
ArithMethod1 InvFuncs [LAST_VIRTUAL_TNUM+1];
479
480
481
/****************************************************************************
482
**
483
*F InvObject( <obj> ) . . . . . . . . . . . . . . . . . . . . call methsel
484
*/
485
Obj InvOp;
486
487
Obj InvObject (
488
Obj obj )
489
{
490
Obj val;
491
val = DoOperation1Args( InvOp, obj );
492
while (val == 0)
493
val = ErrorReturnObj("InvOp: method should have returned a value", 0L, 0L,
494
"you can supply one by 'return <value>;'");
495
return val;
496
}
497
498
499
/****************************************************************************
500
**
501
*F VerboseInvObject( <obj> ) . . . . . . . . . . . . . . . . . call methsel
502
*/
503
Obj VerboseInvObject (
504
Obj obj )
505
{
506
Obj val;
507
val = DoVerboseOperation1Args( InvOp, obj );
508
while (val == 0)
509
val = ErrorReturnObj("InvOp: method should have returned a value", 0L, 0L,
510
"you can supply one by 'return <value>;'");
511
return val;
512
}
513
514
515
/****************************************************************************
516
**
517
*F InstallInvObject( <verb> ) . . . . . . . . . . . install inverse methods
518
*/
519
void InstallInvObject ( Int verb )
520
{
521
UInt t1; /* type of left operand */
522
ArithMethod1 func; /* inv function */
523
524
func = ( verb ? VerboseInvObject : InvObject );
525
for ( t1 = FIRST_EXTERNAL_TNUM; t1 <= LAST_EXTERNAL_TNUM; t1++ ) {
526
InvFuncs[t1] = func;
527
}
528
InvFuncs[ T_PREC ] = func;
529
InvFuncs[ T_PREC +IMMUTABLE ] = func;
530
}
531
532
533
/****************************************************************************
534
**
535
*F FuncINV( <self>, <obj> ) . . . . . . . . . . . . . . . . . . call 'INV'
536
*/
537
Obj FuncINV (
538
Obj self,
539
Obj obj )
540
{
541
return INV( obj );
542
}
543
544
545
/****************************************************************************
546
**
547
*V InvMutFuncs[ <type> ] . table of mutability-preserving inverse functions
548
*/
549
ArithMethod1 InvMutFuncs [LAST_VIRTUAL_TNUM+1];
550
551
552
/****************************************************************************
553
**
554
*F InvMutObject( <obj> ) . . . . . . . . . . . . . . .. . . . . call methsel
555
*/
556
Obj InvMutOp;
557
558
Obj InvMutObject (
559
Obj obj )
560
{
561
Obj val;
562
val = DoOperation1Args( InvMutOp, obj );
563
while (val == 0)
564
val = ErrorReturnObj("INVOp: method should have returned a value", 0L, 0L,
565
"you can supply one by 'return <value>;'");
566
return val;
567
}
568
569
570
/****************************************************************************
571
**
572
*F VerboseInvMutObject( <obj> ) . . . . . . . . . . . . . . . call methsel
573
*/
574
Obj VerboseInvMutObject (
575
Obj obj )
576
{
577
Obj val;
578
val = DoVerboseOperation1Args( InvMutOp, obj );
579
while (val == 0)
580
val = ErrorReturnObj("INVOp: method should have returned a value", 0L, 0L,
581
"you can supply one by 'return <value>;'");
582
return val;
583
}
584
585
586
/****************************************************************************
587
**
588
*F InstallInvMutObject( <verb> ) install mutability preserving inverse methods
589
*/
590
void InstallInvMutObject ( Int verb )
591
{
592
UInt t1; /* type of left operand */
593
ArithMethod1 func; /* inv function */
594
595
func = ( verb ? VerboseInvMutObject : InvMutObject );
596
for ( t1 = FIRST_EXTERNAL_TNUM; t1 <= LAST_EXTERNAL_TNUM; t1++ ) {
597
InvMutFuncs[t1] = func;
598
}
599
InvMutFuncs[ T_PREC ] = func;
600
InvMutFuncs[ T_PREC +IMMUTABLE ] = func;
601
}
602
603
604
/****************************************************************************
605
**
606
*F FuncINV_MUT( <self>, <obj> ) . . . . . . . . . . . . . call 'INV_MUT'
607
*/
608
Obj FuncINV_MUT (
609
Obj self,
610
Obj obj )
611
{
612
return INV_MUT( obj );
613
}
614
615
616
/****************************************************************************
617
**
618
619
*F * * * * * * * * * * * * * comparison operations * * * * * * * * * * * * *
620
*/
621
622
/****************************************************************************
623
**
624
625
*V EqFuncs[ <typeL> ][ <typeR> ] . . . . . . . . table of comparison methods
626
*/
627
CompaMethod EqFuncs [LAST_VIRTUAL_TNUM+1][LAST_VIRTUAL_TNUM+1];
628
629
630
/****************************************************************************
631
**
632
*F EqNot( <opL>, <opR> ) . . . . . . . . . . . . . . . . . . . . . not equal
633
*/
634
Int EqNot (
635
Obj opL,
636
Obj opR )
637
{
638
return 0L;
639
}
640
641
642
/****************************************************************************
643
**
644
*F EqObject( <opL>, <opR> ) . . . . . . . . . . . . . . . . . call methsel
645
*/
646
Obj EqOper;
647
648
Int EqObject (
649
Obj opL,
650
Obj opR )
651
{
652
return (DoOperation2Args( EqOper, opL, opR ) == True);
653
}
654
655
656
/****************************************************************************
657
**
658
*F VerboseEqObject( <opL>, <opR> ) . . . . . . . . . . . . . . call methsel
659
*/
660
Int VerboseEqObject (
661
Obj opL,
662
Obj opR )
663
{
664
return (DoVerboseOperation2Args( EqOper, opL, opR ) == True);
665
}
666
667
668
/****************************************************************************
669
**
670
*F InstallEqObject( <verb> ) . . . . . . . . . . install comparison methods
671
*/
672
void InstallEqObject ( Int verb )
673
{
674
UInt t1; /* type of left operand */
675
UInt t2; /* type of right operand */
676
CompaMethod func; /* equal function */
677
678
func = ( verb ? VerboseEqObject : EqObject );
679
for ( t1 = FIRST_EXTERNAL_TNUM; t1 <= LAST_EXTERNAL_TNUM; t1++ ) {
680
for ( t2 = FIRST_REAL_TNUM; t2 <= LAST_VIRTUAL_TNUM; t2++ ) {
681
EqFuncs[t1][t2] = func;
682
EqFuncs[t2][t1] = func;
683
}
684
}
685
for ( t2 = FIRST_REAL_TNUM; t2 <= LAST_VIRTUAL_TNUM; t2++ ) {
686
687
EqFuncs[ t2 ][ T_PREC ] = func;
688
EqFuncs[ t2 ][ T_PREC +IMMUTABLE ] = func;
689
EqFuncs[ T_PREC ][ t2 ] = func;
690
EqFuncs[ T_PREC +IMMUTABLE ][ t2 ] = func;
691
}
692
}
693
694
695
/****************************************************************************
696
**
697
*F FuncEQ( <self>, <opL>, <opR> ) . . . . . . . . . . . . . . . . call 'EQ'
698
*/
699
Obj FuncEQ (
700
Obj self,
701
Obj opL,
702
Obj opR )
703
{
704
/* if both operands are T_MACFLOAT, we use the comparison method in all cases,
705
even if the objects are identical. In this manner, we can have 0./0. != 0./0. as
706
the IEEE754 standard requires.
707
if (TNUM_OBJ(opL) == T_MACFLOAT && TNUM_OBJ(opR) == T_MACFLOAT)
708
return (*EqFuncs[T_MACFLOAT][T_MACFLOAT])(opL,opR) ? True : False;
709
*/
710
711
return (EQ( opL, opR ) ? True : False);
712
}
713
714
715
/****************************************************************************
716
**
717
718
*V LtFuncs[ <typeL> ][ <typeR> ] . . . . . . . . table of comparison methods
719
*/
720
CompaMethod LtFuncs [LAST_VIRTUAL_TNUM+1][LAST_VIRTUAL_TNUM+1];
721
722
723
/****************************************************************************
724
**
725
*F LtObject( <opL>, <opR> ) . . . . . . . . . . . . . . . . . call methsel
726
*/
727
Obj LtOper;
728
729
Int LtObject (
730
Obj opL,
731
Obj opR )
732
{
733
return (DoOperation2Args( LtOper, opL, opR ) == True);
734
}
735
736
737
/****************************************************************************
738
**
739
*F VerboseLtObject( <opL>, <opR> ) . . . . . . . . . . . . . . call methsel
740
*/
741
Int VerboseLtObject (
742
Obj opL,
743
Obj opR )
744
{
745
return (DoVerboseOperation2Args( LtOper, opL, opR ) == True);
746
}
747
748
749
/****************************************************************************
750
**
751
*F InstallLtObject( <verb> ) . . . . . . . . . . . install less than methods
752
*/
753
void InstallLtObject ( Int verb )
754
{
755
UInt t1; /* type of left operand */
756
UInt t2; /* type of right operand */
757
CompaMethod func; /* less than function */
758
759
func = ( verb ? VerboseLtObject : LtObject );
760
for ( t1 = FIRST_EXTERNAL_TNUM; t1 <= LAST_EXTERNAL_TNUM; t1++ ) {
761
for ( t2 = FIRST_REAL_TNUM; t2 <= LAST_VIRTUAL_TNUM; t2++ ) {
762
LtFuncs[t1][t2] = func;
763
LtFuncs[t2][t1] = func;
764
}
765
}
766
for ( t2 = FIRST_REAL_TNUM; t2 <= LAST_VIRTUAL_TNUM; t2++ ) {
767
768
LtFuncs[ t2 ][ T_PREC ] = func;
769
LtFuncs[ t2 ][ T_PREC +IMMUTABLE ] = func;
770
LtFuncs[ T_PREC ][ t2 ] = func;
771
LtFuncs[ T_PREC +IMMUTABLE ][ t2 ] = func;
772
}
773
}
774
775
776
/****************************************************************************
777
**
778
*F FuncLT( <self>, <opL>, <opR> ) . . . . . . . . . . . . . . . . call 'LT'
779
*/
780
Obj FuncLT (
781
Obj self,
782
Obj opL,
783
Obj opR )
784
{
785
return (LT( opL, opR ) ? True : False);
786
}
787
788
789
/****************************************************************************
790
**
791
792
*V InFuncs[ <typeL> ][ <typeR> ] . . . . . . . . table of membership methods
793
*/
794
CompaMethod InFuncs [LAST_VIRTUAL_TNUM+1][LAST_VIRTUAL_TNUM+1];
795
796
797
/****************************************************************************
798
**
799
*F InUndefined( <self>, <opL>, <opR> ) . . . . . . . . . . . . . cannot 'in'
800
*/
801
Int InUndefined (
802
Obj opL,
803
Obj opR )
804
{
805
return (ErrorReturnObj(
806
"operations: IN of %s and %s is not defined",
807
(Int)TNAM_OBJ(opL),
808
(Int)TNAM_OBJ(opR),
809
"you can 'return <boolean>;' to give a value for the result" ) == True);
810
}
811
812
813
/****************************************************************************
814
**
815
*F InObject( <opL>, <opR> ) . . . . . . . . . . . . . . . . . call methsel
816
*/
817
Obj InOper;
818
819
Int InObject (
820
Obj opL,
821
Obj opR )
822
{
823
return (DoOperation2Args( InOper, opL, opR ) == True);
824
}
825
826
827
/****************************************************************************
828
**
829
*F VerboseInObject( <opL>, <opR> ) . . . . . . . . . . . . . . call methsel
830
*/
831
Int VerboseInObject (
832
Obj opL,
833
Obj opR )
834
{
835
return (DoVerboseOperation2Args( InOper, opL, opR ) == True);
836
}
837
838
839
/****************************************************************************
840
**
841
*F InstallInObject( <verb> ) . . . . . . . . . . . . . . install in methods
842
*/
843
void InstallInObject ( Int verb )
844
{
845
UInt t1; /* type of left operand */
846
UInt t2; /* type of right operand */
847
CompaMethod func; /* in function */
848
849
func = ( verb ? VerboseInObject : InObject );
850
for ( t1 = FIRST_EXTERNAL_TNUM; t1 <= LAST_EXTERNAL_TNUM; t1++ ) {
851
for ( t2 = FIRST_REAL_TNUM; t2 <= LAST_VIRTUAL_TNUM; t2++ ) {
852
InFuncs[t1][t2] = func;
853
InFuncs[t2][t1] = func;
854
}
855
}
856
for ( t2 = FIRST_REAL_TNUM; t2 <= LAST_VIRTUAL_TNUM; t2++ ) {
857
858
InFuncs[ t2 ][ T_PREC ] = func;
859
InFuncs[ t2 ][ T_PREC +IMMUTABLE ] = func;
860
}
861
}
862
863
864
/****************************************************************************
865
**
866
*F FuncIN( <self>, <opL>, <opR> ) . . . . . . . . . . . . . . . . call 'IN'
867
*/
868
Obj FuncIN (
869
Obj self,
870
Obj opL,
871
Obj opR )
872
{
873
return (IN( opL, opR ) ? True : False);
874
}
875
876
877
/****************************************************************************
878
**
879
880
*F * * * * * * * * * * * binary arithmetic operations * * * * * * * * * * * *
881
*/
882
883
/****************************************************************************
884
**
885
886
*V SumFuncs[ <typeL> ][ <typeR> ] . . . . . . . . . . table of sum methods
887
*/
888
ArithMethod2 SumFuncs [LAST_VIRTUAL_TNUM+1][LAST_VIRTUAL_TNUM+1];
889
890
891
/****************************************************************************
892
**
893
*F SumObject( <opL>, <opR> ) . . . . . . . . . . . . . . . . . call methsel
894
*/
895
Obj SumOper;
896
897
Obj SumObject (
898
Obj opL,
899
Obj opR )
900
{
901
Obj val;
902
val = DoOperation2Args( SumOper, opL, opR );
903
while (val == 0)
904
val = ErrorReturnObj("SUM: method should have returned a value", 0L, 0L,
905
"you can supply one by 'return <value>;'");
906
return val;
907
}
908
909
910
/****************************************************************************
911
**
912
*F VerboseSumObject( <opL>, <opR> ) . . . . . . . . . . . . . call methsel
913
*/
914
Obj VerboseSumObject (
915
Obj opL,
916
Obj opR )
917
{
918
Obj val;
919
val = DoVerboseOperation2Args( SumOper, opL, opR );
920
while (val == 0)
921
val = ErrorReturnObj("SUM: method should have returned a value", 0L, 0L,
922
"you can supply one by 'return <value>;'");
923
return val;
924
}
925
926
927
/****************************************************************************
928
**
929
*F InstallSumObject( <verb> ) . . . . . . . . . . . . . install sum methods
930
*/
931
void InstallSumObject ( Int verb )
932
{
933
UInt t1; /* type of left operand */
934
UInt t2; /* type of right operand */
935
ArithMethod2 func; /* sum function */
936
937
func = ( verb ? VerboseSumObject : SumObject );
938
for ( t1 = FIRST_EXTERNAL_TNUM; t1 <= LAST_EXTERNAL_TNUM; t1++ ) {
939
for ( t2 = FIRST_REAL_TNUM; t2 <= LAST_VIRTUAL_TNUM; t2++ ) {
940
SumFuncs[t1][t2] = func;
941
SumFuncs[t2][t1] = func;
942
}
943
}
944
for ( t2 = FIRST_REAL_TNUM; t2 <= LAST_VIRTUAL_TNUM; t2++ ) {
945
946
SumFuncs[ t2 ][ T_PREC ] = func;
947
SumFuncs[ t2 ][ T_PREC +IMMUTABLE ] = func;
948
SumFuncs[ T_PREC ][ t2 ] = func;
949
SumFuncs[ T_PREC +IMMUTABLE ][ t2 ] = func;
950
}
951
}
952
953
954
/****************************************************************************
955
**
956
*F FuncSUM( <self>, <opL>, <opR> ) . . . . . . . . . . . . . . . call 'SUM'
957
*/
958
Obj FuncSUM (
959
Obj self,
960
Obj opL,
961
Obj opR )
962
{
963
return SUM( opL, opR );
964
}
965
966
967
/****************************************************************************
968
**
969
970
*V DiffFuncs[ <typeL> ][ <typeR> ] . . . . . . . table of difference methods
971
*/
972
ArithMethod2 DiffFuncs [LAST_VIRTUAL_TNUM+1][LAST_VIRTUAL_TNUM+1];
973
974
975
/****************************************************************************
976
**
977
*F DiffDefault( <opL>, <opR> ) . . . . . . . . . . . . call 'SUM' and 'AINV'
978
*/
979
Obj DiffDefault (
980
Obj opL,
981
Obj opR )
982
{
983
Obj tmp;
984
985
tmp = AINV( opR );
986
return SUM( opL, tmp );
987
}
988
989
990
/****************************************************************************
991
**
992
*F DiffObject( <opL>, <opR> ) . . . . . . . . . . . . . . . . call methsel
993
*/
994
Obj DiffOper;
995
996
Obj DiffObject (
997
Obj opL,
998
Obj opR )
999
{
1000
Obj val;
1001
val = DoOperation2Args( DiffOper, opL, opR );
1002
while (val == 0)
1003
val = ErrorReturnObj("DIFF: method should have returned a value", 0L, 0L,
1004
"you can supply one by 'return <value>;'");
1005
return val;
1006
}
1007
1008
1009
/****************************************************************************
1010
**
1011
*F VerboseDiffObject( <opL>, <opR> ) . . . . . . . . . . . . . call methsel
1012
*/
1013
Obj VerboseDiffObject (
1014
Obj opL,
1015
Obj opR )
1016
{
1017
Obj val;
1018
val = DoVerboseOperation2Args( DiffOper, opL, opR );
1019
while (val == 0)
1020
val = ErrorReturnObj("DIFF: method should have returned a value", 0L, 0L,
1021
"you can supply one by 'return <value>;'");
1022
return val;
1023
}
1024
1025
1026
/****************************************************************************
1027
**
1028
*F InstallDiffObject( <verb> ) . . . . . . . . . install difference methods
1029
*/
1030
void InstallDiffObject ( Int verb )
1031
{
1032
UInt t1; /* type of left operand */
1033
UInt t2; /* type of right operand */
1034
ArithMethod2 func; /* difference function */
1035
1036
func = ( verb ? VerboseDiffObject : DiffObject );
1037
for ( t1 = FIRST_EXTERNAL_TNUM; t1 <= LAST_EXTERNAL_TNUM; t1++ ) {
1038
for ( t2 = FIRST_REAL_TNUM; t2 <= LAST_VIRTUAL_TNUM; t2++ ) {
1039
DiffFuncs[t1][t2] = func;
1040
DiffFuncs[t2][t1] = func;
1041
}
1042
}
1043
for ( t2 = FIRST_REAL_TNUM; t2 <= LAST_VIRTUAL_TNUM; t2++ ) {
1044
1045
DiffFuncs[ t2 ][ T_PREC ] = func;
1046
DiffFuncs[ t2 ][ T_PREC +IMMUTABLE ] = func;
1047
DiffFuncs[ T_PREC ][ t2 ] = func;
1048
DiffFuncs[ T_PREC +IMMUTABLE ][ t2 ] = func;
1049
}
1050
}
1051
1052
1053
/****************************************************************************
1054
**
1055
*F FuncDIFF_DEFAULT( <self>, <opL>, <opR> ) . . . . . . call 'DiffDefault'
1056
*/
1057
Obj DiffDefaultFunc;
1058
1059
Obj FuncDIFF_DEFAULT (
1060
Obj self,
1061
Obj opL,
1062
Obj opR )
1063
{
1064
return DiffDefault( opL, opR );
1065
}
1066
1067
1068
/****************************************************************************
1069
**
1070
*F FuncDIFF( <self>, <opL>, <opR> ) . . . . . . . . . . . . . . call 'DIFF'
1071
*/
1072
Obj FuncDIFF (
1073
Obj self,
1074
Obj opL,
1075
Obj opR )
1076
{
1077
return DIFF( opL, opR );
1078
}
1079
1080
1081
/****************************************************************************
1082
**
1083
1084
*V ProdFuncs[ <typeL> ][ <typeR> ] . . . . . . . . table of product methods
1085
*/
1086
ArithMethod2 ProdFuncs [LAST_VIRTUAL_TNUM+1][LAST_VIRTUAL_TNUM+1];
1087
1088
1089
/****************************************************************************
1090
**
1091
*F ProdObject( <opL>, <opR> ) . . . . . . . . . . . . . . . . call methsel
1092
*/
1093
Obj ProdOper;
1094
1095
Obj ProdObject (
1096
Obj opL,
1097
Obj opR )
1098
{
1099
Obj val;
1100
val = DoOperation2Args( ProdOper, opL, opR );
1101
while (val == 0)
1102
val = ErrorReturnObj("PROD: method should have returned a value", 0L, 0L,
1103
"you can supply one by 'return <value>;'");
1104
return val;
1105
}
1106
1107
1108
/****************************************************************************
1109
**
1110
*F VerboseProdObject( <opL>, <opR> ) . . . . . . . . . . . . . call methsel
1111
*/
1112
Obj VerboseProdObject (
1113
Obj opL,
1114
Obj opR )
1115
{
1116
Obj val;
1117
val = DoVerboseOperation2Args( ProdOper, opL, opR );
1118
while (val == 0)
1119
val = ErrorReturnObj("PROD: method should have returned a value", 0L, 0L,
1120
"you can supply one by 'return <value>;'");
1121
return val;
1122
}
1123
1124
1125
/****************************************************************************
1126
**
1127
*F InstallProdObject( <verb> ) . . . . . . . . . . . install product methods
1128
*/
1129
void InstallProdObject ( Int verb )
1130
{
1131
UInt t1; /* type of left operand */
1132
UInt t2; /* type of right operand */
1133
ArithMethod2 func; /* product function */
1134
1135
func = ( verb ? VerboseProdObject : ProdObject );
1136
for ( t1 = FIRST_EXTERNAL_TNUM; t1 <= LAST_EXTERNAL_TNUM; t1++ ) {
1137
for ( t2 = FIRST_REAL_TNUM; t2 <= LAST_VIRTUAL_TNUM; t2++ ) {
1138
ProdFuncs[t1][t2] = func;
1139
ProdFuncs[t2][t1] = func;
1140
}
1141
}
1142
for ( t2 = FIRST_REAL_TNUM; t2 <= LAST_VIRTUAL_TNUM; t2++ ) {
1143
1144
ProdFuncs[ t2 ][ T_PREC ] = func;
1145
ProdFuncs[ t2 ][ T_PREC +IMMUTABLE ] = func;
1146
ProdFuncs[ T_PREC ][ t2 ] = func;
1147
ProdFuncs[ T_PREC +IMMUTABLE ][ t2 ] = func;
1148
}
1149
}
1150
1151
1152
/****************************************************************************
1153
**
1154
*F FuncPROD( <self>, <opL>, <opR> ) . . . . . . . . . . . . . . call 'PROD'
1155
*/
1156
Obj FuncPROD (
1157
Obj self,
1158
Obj opL,
1159
Obj opR )
1160
{
1161
return PROD( opL, opR );
1162
}
1163
1164
1165
/****************************************************************************
1166
**
1167
1168
*V QuoFuncs[ <typeL> ][ <typeR> ] . . . . . . . . table of quotient methods
1169
*/
1170
ArithMethod2 QuoFuncs [LAST_VIRTUAL_TNUM+1][LAST_VIRTUAL_TNUM+1];
1171
1172
1173
/****************************************************************************
1174
**
1175
*F QuoDefault( <opL>, <opR> ) . . . . . . . . . . . . call 'INV' and 'PROD'
1176
*/
1177
Obj QuoDefault (
1178
Obj opL,
1179
Obj opR )
1180
{
1181
Obj tmp;
1182
tmp = INV_MUT( opR );
1183
return PROD( opL, tmp );
1184
}
1185
1186
1187
/****************************************************************************
1188
**
1189
*F QuoObject( <opL>, <opR> ) . . . . . . . . . . . . . . . . . call methsel
1190
*/
1191
Obj QuoOper;
1192
1193
Obj QuoObject (
1194
Obj opL,
1195
Obj opR )
1196
{
1197
Obj val;
1198
val = DoOperation2Args( QuoOper, opL, opR );
1199
while (val == 0)
1200
val = ErrorReturnObj("QUO: method should have returned a value", 0L, 0L,
1201
"you can supply one by 'return <value>;'");
1202
return val;
1203
}
1204
1205
1206
/****************************************************************************
1207
**
1208
*F VerboseQuoObject( <opL>, <opR> ) . . . . . . . . . . . . . call methsel
1209
*/
1210
Obj VerboseQuoObject (
1211
Obj opL,
1212
Obj opR )
1213
{
1214
Obj val;
1215
val = DoVerboseOperation2Args( QuoOper, opL, opR );
1216
while (val == 0)
1217
val = ErrorReturnObj("QUO: method should have returned a value", 0L, 0L,
1218
"you can supply one by 'return <value>;'");
1219
return val;
1220
}
1221
1222
1223
/****************************************************************************
1224
**
1225
*F InstallQuoObject( <verb> ) . . . . . . . . . . install quotient methods
1226
*/
1227
void InstallQuoObject ( Int verb )
1228
{
1229
UInt t1; /* type of left operand */
1230
UInt t2; /* type of right operand */
1231
ArithMethod2 func; /* quotient function */
1232
1233
func = ( verb ? VerboseQuoObject : QuoObject );
1234
for ( t1 = FIRST_EXTERNAL_TNUM; t1 <= LAST_EXTERNAL_TNUM; t1++ ) {
1235
for ( t2 = FIRST_REAL_TNUM; t2 <= LAST_VIRTUAL_TNUM; t2++ ) {
1236
QuoFuncs[t1][t2] = func;
1237
QuoFuncs[t2][t1] = func;
1238
}
1239
}
1240
for ( t2 = FIRST_REAL_TNUM; t2 <= LAST_VIRTUAL_TNUM; t2++ ) {
1241
1242
QuoFuncs[ t2 ][ T_PREC ] = func;
1243
QuoFuncs[ t2 ][ T_PREC +IMMUTABLE ] = func;
1244
QuoFuncs[ T_PREC ][ t2 ] = func;
1245
QuoFuncs[ T_PREC +IMMUTABLE ][ t2 ] = func;
1246
}
1247
}
1248
1249
1250
/****************************************************************************
1251
**
1252
*F FuncQUO_DEFAULT( <self>, <opL>, <opR> ) . . . . . . . . call 'QuoDefault'
1253
*/
1254
Obj QuoDefaultFunc;
1255
1256
Obj FuncQUO_DEFAULT (
1257
Obj self,
1258
Obj opL,
1259
Obj opR )
1260
{
1261
return QuoDefault( opL, opR );
1262
}
1263
1264
1265
/****************************************************************************
1266
**
1267
*F FuncQUO( <self>, <opL>, <opR> ) . . . . . . . . . . . . . . . call 'QUO'
1268
*/
1269
Obj FuncQUO (
1270
Obj self,
1271
Obj opL,
1272
Obj opR )
1273
{
1274
return QUO( opL, opR );
1275
}
1276
1277
1278
/****************************************************************************
1279
**
1280
1281
*V LQuoFuncs[ <typeL> ][ <typeR> ] . . . . . table of left quotient methods
1282
*/
1283
ArithMethod2 LQuoFuncs [LAST_VIRTUAL_TNUM+1][LAST_VIRTUAL_TNUM+1];
1284
1285
1286
/****************************************************************************
1287
**
1288
*F LQuoDefault( <opL>, <opR> ) . . . . . . . . . . . . call 'INV' and 'PROD'
1289
*/
1290
Obj LQuoDefault (
1291
Obj opL,
1292
Obj opR )
1293
{
1294
Obj tmp;
1295
tmp = INV_MUT( opL );
1296
return PROD( tmp, opR );
1297
}
1298
1299
1300
/****************************************************************************
1301
**
1302
*F LQuoObject( <opL>, <opR> ) . . . . . . . . . . . . . . . . call methsel
1303
*/
1304
Obj LQuoOper;
1305
1306
Obj LQuoObject (
1307
Obj opL,
1308
Obj opR )
1309
{
1310
Obj val;
1311
val = DoOperation2Args( LQuoOper, opL, opR );
1312
while (val == 0)
1313
val = ErrorReturnObj("LeftQuotient: method should have returned a value", 0L, 0L,
1314
"you can supply one by 'return <value>;'");
1315
return val;
1316
}
1317
1318
1319
/****************************************************************************
1320
**
1321
*F VerboseLQuoObject( <opL>, <opR> ) . . . . . . . . . . . . . call methsel
1322
*/
1323
Obj VerboseLQuoObject (
1324
Obj opL,
1325
Obj opR )
1326
{
1327
Obj val;
1328
val = DoOperation2Args( LQuoOper, opL, opR );
1329
while (val == 0)
1330
val = ErrorReturnObj("LeftQuotient: method should have returned a value", 0L, 0L,
1331
"you can supply one by 'return <value>;'");
1332
return val;
1333
}
1334
1335
1336
/****************************************************************************
1337
**
1338
*F InstallLQuoObject( <verb> ) . . . . . . . . install left quotient methods
1339
*/
1340
void InstallLQuoObject ( Int verb )
1341
{
1342
UInt t1; /* type of left operand */
1343
UInt t2; /* type of right operand */
1344
ArithMethod2 func; /* left quotient function */
1345
1346
func = ( verb ? VerboseLQuoObject : LQuoObject );
1347
for ( t1 = FIRST_EXTERNAL_TNUM; t1 <= LAST_EXTERNAL_TNUM; t1++ ) {
1348
for ( t2 = FIRST_REAL_TNUM; t2 <= LAST_VIRTUAL_TNUM; t2++ ) {
1349
LQuoFuncs[t1][t2] = func;
1350
LQuoFuncs[t2][t1] = func;
1351
}
1352
}
1353
for ( t2 = FIRST_REAL_TNUM; t2 <= LAST_VIRTUAL_TNUM; t2++ ) {
1354
LQuoFuncs[ t2 ][ T_PREC ] = func;
1355
LQuoFuncs[ t2 ][ T_PREC +IMMUTABLE ] = func;
1356
LQuoFuncs[ T_PREC ][ t2 ] = func;
1357
LQuoFuncs[ T_PREC +IMMUTABLE ][ t2 ] = func;
1358
}
1359
}
1360
1361
1362
/****************************************************************************
1363
**
1364
*F FuncLQUO_DEFAULT( <self>, <opL>, <opR> ) . . . . . . call 'LQuoDefault'
1365
*/
1366
Obj LQuoDefaultFunc;
1367
1368
Obj FuncLQUO_DEFAULT (
1369
Obj self,
1370
Obj opL,
1371
Obj opR )
1372
{
1373
return LQuoDefault( opL, opR );
1374
}
1375
1376
1377
/****************************************************************************
1378
**
1379
*F FuncLQUO( <self>, <opL>, <opR> ) . . . . . . . . . . . . . . call 'LQUO'
1380
*/
1381
Obj FuncLQUO (
1382
Obj self,
1383
Obj opL,
1384
Obj opR )
1385
{
1386
return LQUO( opL, opR );
1387
}
1388
1389
1390
/****************************************************************************
1391
**
1392
1393
*V PowFuncs[ <typeL> ][ <typeR> ] . . . . . . . . . table of power methods
1394
*/
1395
ArithMethod2 PowFuncs [LAST_VIRTUAL_TNUM+1][LAST_VIRTUAL_TNUM+1];
1396
1397
1398
/****************************************************************************
1399
**
1400
*F PowDefault( <opL>, <opR> ) . . . . . . . . . . . call 'LQUO' and 'PROD'
1401
*/
1402
Obj PowDefault (
1403
Obj opL,
1404
Obj opR )
1405
{
1406
Obj tmp;
1407
tmp = LQUO( opR, opL );
1408
return PROD( tmp, opR );
1409
}
1410
1411
1412
/****************************************************************************
1413
**
1414
*F PowObject( <opL>, <opR> ) . . . . . . . . . . . . . . . . . call methsel
1415
*/
1416
Obj PowOper;
1417
1418
Obj PowObject (
1419
Obj opL,
1420
Obj opR )
1421
{
1422
Obj val;
1423
val = DoOperation2Args( PowOper, opL, opR );
1424
while (val == 0)
1425
val = ErrorReturnObj("POW: method should have returned a value", 0L, 0L,
1426
"you can supply one by 'return <value>;'");
1427
return val;
1428
}
1429
1430
1431
/****************************************************************************
1432
**
1433
*F VerbosePowObject( <opL>, <opR> ) . . . . . . . . . . . . . call methsel
1434
*/
1435
Obj VerbosePowObject (
1436
Obj opL,
1437
Obj opR )
1438
{
1439
1440
Obj val;
1441
val = DoVerboseOperation2Args( PowOper, opL, opR );
1442
while (val == 0)
1443
val = ErrorReturnObj("POW: method should have returned a value", 0L, 0L,
1444
"you can supply one by 'return <value>;'");
1445
return val;
1446
}
1447
1448
1449
/****************************************************************************
1450
**
1451
*F InstallPowObject( <verb> ) . . . . . . . . . . install the power methods
1452
*/
1453
void InstallPowObject ( Int verb )
1454
{
1455
UInt t1; /* type of left operand */
1456
UInt t2; /* type of right operand */
1457
ArithMethod2 func; /* power function */
1458
1459
func = ( verb ? VerbosePowObject : PowObject );
1460
for ( t1 = FIRST_EXTERNAL_TNUM; t1 <= LAST_EXTERNAL_TNUM; t1++ ) {
1461
for ( t2 = FIRST_REAL_TNUM; t2 <= LAST_VIRTUAL_TNUM; t2++ ) {
1462
PowFuncs[t1][t2] = func;
1463
PowFuncs[t2][t1] = func;
1464
}
1465
}
1466
for ( t2 = FIRST_REAL_TNUM; t2 <= LAST_VIRTUAL_TNUM; t2++ ) {
1467
1468
PowFuncs[ t2 ][ T_PREC ] = func;
1469
PowFuncs[ t2 ][ T_PREC +IMMUTABLE ] = func;
1470
PowFuncs[ T_PREC ][ t2 ] = func;
1471
PowFuncs[ T_PREC +IMMUTABLE ][ t2 ] = func;
1472
}
1473
}
1474
1475
1476
/****************************************************************************
1477
**
1478
*F FuncPOW_DEFAULT( <self>, <opL>, <opR> ) . . . . . . . . call 'PowDefault'
1479
*/
1480
Obj PowDefaultFunc;
1481
1482
Obj FuncPOW_DEFAULT (
1483
Obj self,
1484
Obj opL,
1485
Obj opR )
1486
{
1487
return PowDefault( opL, opR );
1488
}
1489
1490
1491
/****************************************************************************
1492
**
1493
*F FuncPOW( <self>, <opL>, <opR> ) . . . . . . . . . . . . . . . call 'POW'
1494
*/
1495
Obj FuncPOW (
1496
Obj self,
1497
Obj opL,
1498
Obj opR )
1499
{
1500
return POW( opL, opR );
1501
}
1502
1503
1504
/****************************************************************************
1505
**
1506
1507
*V CommFuncs[ <typeL> ][ <typeR> ] . . . . . . . table of commutator methods
1508
*/
1509
ArithMethod2 CommFuncs [LAST_VIRTUAL_TNUM+1][LAST_VIRTUAL_TNUM+1];
1510
1511
1512
/****************************************************************************
1513
**
1514
*F CommDefault( <opL>, <opR> ) . . . . . . . . . . . call 'LQUO' and 'PROD'
1515
*/
1516
Obj CommDefault (
1517
Obj opL,
1518
Obj opR )
1519
{
1520
Obj tmp1;
1521
Obj tmp2;
1522
tmp1 = PROD( opR, opL );
1523
tmp2 = PROD( opL, opR );
1524
return LQUO( tmp1, tmp2 );
1525
}
1526
1527
1528
/****************************************************************************
1529
**
1530
*F CommObject( <opL>, <opR> ) . . . . . . . . . . . . . . . . call methsel
1531
*/
1532
Obj CommOper;
1533
1534
Obj CommObject (
1535
Obj opL,
1536
Obj opR )
1537
{
1538
Obj val;
1539
val = DoOperation2Args( CommOper, opL, opR );
1540
while (val == 0)
1541
val = ErrorReturnObj("Comm: method should have returned a value", 0L, 0L,
1542
"you can supply one by 'return <value>;'");
1543
return val;
1544
}
1545
1546
1547
/****************************************************************************
1548
**
1549
*F VerboseCommObject( <opL>, <opR> ) . . . . . . . . . . . . . call methsel
1550
*/
1551
Obj VerboseCommObject (
1552
Obj opL,
1553
Obj opR )
1554
{
1555
Obj val;
1556
val = DoVerboseOperation2Args( CommOper, opL, opR );
1557
while (val == 0)
1558
val = ErrorReturnObj("Comm: method should have returned a value", 0L, 0L,
1559
"you can supply one by 'return <value>;'");
1560
return val;
1561
}
1562
1563
1564
/****************************************************************************
1565
**
1566
*F InstallCommObject( <verb> ) . . . . . . . . . install commutator methods
1567
*/
1568
void InstallCommObject ( Int verb )
1569
{
1570
UInt t1; /* type of left operand */
1571
UInt t2; /* type of right operand */
1572
ArithMethod2 func; /* commutator function */
1573
1574
func = ( verb ? VerboseCommObject : CommObject );
1575
for ( t1 = FIRST_EXTERNAL_TNUM; t1 <= LAST_EXTERNAL_TNUM; t1++ ) {
1576
for ( t2 = FIRST_REAL_TNUM; t2 <= LAST_VIRTUAL_TNUM; t2++ ) {
1577
CommFuncs[t1][t2] = func;
1578
CommFuncs[t2][t1] = func;
1579
}
1580
}
1581
for ( t2 = FIRST_REAL_TNUM; t2 <= LAST_VIRTUAL_TNUM; t2++ ) {
1582
1583
CommFuncs[ t2 ][ T_PREC ] = func;
1584
CommFuncs[ t2 ][ T_PREC +IMMUTABLE ] = func;
1585
CommFuncs[ T_PREC ][ t2 ] = func;
1586
CommFuncs[ T_PREC +IMMUTABLE ][ t2 ] = func;
1587
}
1588
}
1589
1590
1591
/****************************************************************************
1592
**
1593
*F FuncCOMM_DEFAULT( <self>, <opL>, <opR> ) . . . . . . call 'CommDefault'
1594
*/
1595
Obj CommDefaultFunc;
1596
1597
Obj FuncCOMM_DEFAULT (
1598
Obj self,
1599
Obj opL,
1600
Obj opR )
1601
{
1602
return CommDefault( opL, opR );
1603
}
1604
1605
1606
/****************************************************************************
1607
**
1608
*F FuncCOMM( <self>, <opL>, <opR> ) . . . . . . . . . . . . . . call 'COMM'
1609
*/
1610
Obj FuncCOMM (
1611
Obj self,
1612
Obj opL,
1613
Obj opR )
1614
{
1615
return COMM( opL, opR );
1616
}
1617
1618
1619
/****************************************************************************
1620
**
1621
1622
*V ModFuncs[ <typeL> ][ <typeR> ] . . . . . . . table of remainder methods
1623
*/
1624
ArithMethod2 ModFuncs [LAST_VIRTUAL_TNUM+1][LAST_VIRTUAL_TNUM+1];
1625
1626
1627
1628
/****************************************************************************
1629
**
1630
*F ModObject( <opL>, <opR> ) . . . . . . . . . . . . . . . . . call methsel
1631
*/
1632
Obj ModOper;
1633
1634
Obj ModObject (
1635
Obj opL,
1636
Obj opR )
1637
{
1638
Obj val;
1639
val = DoOperation2Args( ModOper, opL, opR );
1640
while (val == 0)
1641
val = ErrorReturnObj("mod: method should have returned a value", 0L, 0L,
1642
"you can supply one by 'return <value>;'");
1643
return val;
1644
}
1645
1646
1647
/****************************************************************************
1648
**
1649
*F VerboseModObject( <opL>, <opR> ) . . . . . . . . . . . . . call methsel
1650
*/
1651
Obj VerboseModObject (
1652
Obj opL,
1653
Obj opR )
1654
{
1655
Obj val;
1656
val = DoVerboseOperation2Args( ModOper, opL, opR );
1657
while (val == 0)
1658
val = ErrorReturnObj("mod: method should have returned a value", 0L, 0L,
1659
"you can supply one by 'return <value>;'");
1660
return val;
1661
}
1662
1663
1664
/****************************************************************************
1665
**
1666
*F InstallModObject( <verb> ) . . . . . . . . . . . install the mod methods
1667
*/
1668
void InstallModObject ( Int verb )
1669
{
1670
UInt t1; /* type of left operand */
1671
UInt t2; /* type of right operand */
1672
ArithMethod2 func; /* mod function */
1673
1674
func = ( verb ? VerboseModObject : ModObject );
1675
for ( t1 = FIRST_EXTERNAL_TNUM; t1 <= LAST_EXTERNAL_TNUM; t1++ ) {
1676
for ( t2 = FIRST_REAL_TNUM; t2 <= LAST_VIRTUAL_TNUM; t2++ ) {
1677
ModFuncs[t1][t2] = func;
1678
ModFuncs[t2][t1] = func;
1679
}
1680
}
1681
for ( t2 = FIRST_REAL_TNUM; t2 <= LAST_VIRTUAL_TNUM; t2++ ) {
1682
1683
ModFuncs[ t2 ][ T_PREC ] = func;
1684
ModFuncs[ t2 ][ T_PREC +IMMUTABLE ] = func;
1685
ModFuncs[ T_PREC ][ t2 ] = func;
1686
ModFuncs[ T_PREC +IMMUTABLE ][ t2 ] = func;
1687
}
1688
}
1689
1690
1691
/****************************************************************************
1692
**
1693
*F FuncMOD( <self>, <opL>, <opR> ) . . . . . . . . . . . . . . . call 'MOD'
1694
*/
1695
Obj FuncMOD (
1696
Obj self,
1697
Obj opL,
1698
Obj opR )
1699
{
1700
return MOD( opL, opR );
1701
}
1702
1703
1704
/****************************************************************************
1705
**
1706
1707
*F * * * * * * * * * * * * * initialize package * * * * * * * * * * * * * * *
1708
*/
1709
1710
/****************************************************************************
1711
**
1712
1713
*V GVarAttrs . . . . . . . . . . . . . . . . . list of attributes to export
1714
*/
1715
static StructGVarAttr GVarAttrs [] = {
1716
1717
1718
{ 0 }
1719
1720
};
1721
1722
1723
/****************************************************************************
1724
**
1725
*V GVarOpers . . . . . . . . . . . . . . . . . list of operations to export
1726
*/
1727
static StructGVarOper GVarOpers [] = {
1728
1729
{ "EQ", 2, "opL, opR", &EqOper,
1730
FuncEQ, "src/ariths.c:EQ" },
1731
1732
{ "LT", 2, "opL, opR", &LtOper,
1733
FuncLT, "src/ariths.c:LT" },
1734
1735
{ "IN", 2, "opL, opR", &InOper,
1736
FuncIN, "src/ariths.c:IN" },
1737
1738
{ "SUM", 2, "opL, opR", &SumOper,
1739
FuncSUM, "src/ariths.c:SUM" },
1740
1741
{ "DIFF", 2, "opL, opR", &DiffOper,
1742
FuncDIFF, "src/ariths.c:DIFF" },
1743
1744
{ "PROD", 2, "opL, opR", &ProdOper,
1745
FuncPROD, "src/ariths.c:PROD" },
1746
1747
{ "QUO", 2, "opL, opR", &QuoOper,
1748
FuncQUO, "src/ariths.c:QUO" },
1749
1750
{ "LQUO", 2, "opL, opR", &LQuoOper,
1751
FuncLQUO, "src/ariths.c:LQUO" },
1752
1753
{ "POW", 2, "opL, opR", &PowOper,
1754
FuncPOW, "src/ariths.c:POW" },
1755
1756
{ "COMM", 2, "opL, opR", &CommOper,
1757
FuncCOMM, "src/ariths.c:COMM" },
1758
1759
{ "MOD", 2, "opL, opR", &ModOper,
1760
FuncMOD, "src/ariths.c:MOD" },
1761
1762
{ "ZERO", 1, "op", &ZEROOp,
1763
FuncZERO, "src/ariths.c:ZERO" },
1764
1765
{ "ZERO_MUT", 1, "op", &ZeroOp,
1766
FuncZERO_MUT, "src/ariths.c:ZERO_MUT" },
1767
1768
{ "AINV", 1, "op", &AInvOp,
1769
FuncAINV, "src/ariths.c:AINV" },
1770
1771
{ "AINV_MUT", 1, "op", &AdditiveInverseOp,
1772
FuncAINV_MUT, "src/ariths.c:AINV_MUT" },
1773
1774
{ "ONE", 1, "op", &OneOp,
1775
FuncONE, "src/ariths.c:ONE" },
1776
1777
{ "ONE_MUT", 1, "op", &OneMutOp,
1778
FuncONE_MUT, "src/ariths.c:ONE_MUT" },
1779
1780
{ "INV", 1, "op", &InvOp,
1781
FuncINV, "src/ariths.c:INV" },
1782
1783
{ "INV_MUT", 1, "op", &InvMutOp,
1784
FuncINV_MUT, "src/ariths.c:INV_MUT" },
1785
1786
{ 0 }
1787
1788
};
1789
1790
1791
/****************************************************************************
1792
**
1793
*V GVarFuncs . . . . . . . . . . . . . . . . . . list of functions to export
1794
*/
1795
static StructGVarFunc GVarFuncs [] = {
1796
1797
{ "COMM_DEFAULT", 2, "opL, opR",
1798
FuncCOMM_DEFAULT, "src/ariths.c:COMM_DEFAULT" },
1799
1800
{ "POW_DEFAULT", 2, "opL, opR",
1801
FuncPOW_DEFAULT, "src/ariths.c:POW_DEFAULT" },
1802
1803
{ "LQUO_DEFAULT", 2, "opL, opR",
1804
FuncLQUO_DEFAULT, "src/ariths.c:LQUO_DEFAULT" },
1805
1806
{ "QUO_DEFAULT", 2, "opL, opR",
1807
FuncQUO_DEFAULT, "src/ariths.c:QUO_DEFAULT" },
1808
1809
{ "DIFF_DEFAULT", 2, "opL, opR",
1810
FuncDIFF_DEFAULT, "src/ariths.c:DIFF_DEFAULT" },
1811
1812
1813
{ 0 }
1814
1815
};
1816
1817
1818
/****************************************************************************
1819
**
1820
1821
*F InitKernel( <module> ) . . . . . . . . initialise kernel data structures
1822
*/
1823
static Int InitKernel (
1824
StructInitInfo * module )
1825
{
1826
UInt t1; /* type of left operand */
1827
UInt t2; /* type of right operand */
1828
1829
/* init filters and functions */
1830
InitHdlrAttrsFromTable( GVarAttrs );
1831
InitHdlrOpersFromTable( GVarOpers );
1832
InitHdlrFuncsFromTable( GVarFuncs );
1833
1834
/* make and install the 'ZERO' arithmetic operation */
1835
for ( t1 = FIRST_REAL_TNUM; t1 <= LAST_VIRTUAL_TNUM; t1++ ) {
1836
ZeroFuncs[t1] = ZeroObject;
1837
}
1838
InstallZeroObject(0);
1839
1840
/* make and install the 'ZERO_MUT' arithmetic operation */
1841
for ( t1 = FIRST_REAL_TNUM; t1 <= LAST_VIRTUAL_TNUM; t1++ ) {
1842
ZeroMutFuncs[t1] = ZeroMutObject;
1843
}
1844
InstallZeroObject(0);
1845
1846
/* make and install the 'AINV' arithmetic operation */
1847
for ( t1 = FIRST_REAL_TNUM; t1 <= LAST_VIRTUAL_TNUM; t1++ ) {
1848
AInvFuncs[t1] = AInvObject;
1849
}
1850
1851
InstallAinvMutObject(0);
1852
/* make and install the 'AINV_MUT' arithmetic operation */
1853
for ( t1 = FIRST_REAL_TNUM; t1 <= LAST_VIRTUAL_TNUM; t1++ ) {
1854
AInvMutFuncs[t1] = AInvMutObject;
1855
}
1856
InstallAinvObject(0);
1857
1858
/* make and install the 'ONE' arithmetic operation */
1859
for ( t1 = FIRST_REAL_TNUM; t1 <= LAST_VIRTUAL_TNUM; t1++ ) {
1860
OneFuncs[t1] = OneObject;
1861
}
1862
InstallOneObject(0);
1863
1864
/* make and install the 'ONE' arithmetic operation */
1865
for ( t1 = FIRST_REAL_TNUM; t1 <= LAST_VIRTUAL_TNUM; t1++ ) {
1866
OneMutFuncs[t1] = OneMutObject;
1867
}
1868
InstallOneMutObject(0);
1869
1870
/* make and install the 'INV' arithmetic operation */
1871
for ( t1 = FIRST_REAL_TNUM; t1 <= LAST_VIRTUAL_TNUM; t1++ ) {
1872
InvFuncs[t1] = InvObject;
1873
}
1874
InstallInvObject(0);
1875
1876
/* make and install the 'INV' arithmetic operation */
1877
for ( t1 = FIRST_REAL_TNUM; t1 <= LAST_VIRTUAL_TNUM; t1++ ) {
1878
InvMutFuncs[t1] = InvMutObject;
1879
}
1880
InstallInvMutObject(0);
1881
1882
/* make and install the 'EQ' comparison operation */
1883
for ( t1 = FIRST_REAL_TNUM; t1 <= LAST_VIRTUAL_TNUM; t1++ ) {
1884
for ( t2 = FIRST_REAL_TNUM; t2 <= LAST_VIRTUAL_TNUM; t2++ ) {
1885
EqFuncs[t1][t2] = EqNot;
1886
}
1887
}
1888
InstallEqObject(0);
1889
1890
/* make and install the 'LT' comparison operation */
1891
for ( t1 = FIRST_REAL_TNUM; t1 <= LAST_VIRTUAL_TNUM; t1++ ) {
1892
for ( t2 = FIRST_REAL_TNUM; t2 <= LAST_VIRTUAL_TNUM; t2++ ) {
1893
LtFuncs[t1][t2] = LtObject;
1894
}
1895
}
1896
InstallLtObject(0);
1897
1898
/* make and install the 'IN' comparison operation */
1899
for ( t1 = FIRST_REAL_TNUM; t1 <= LAST_VIRTUAL_TNUM; t1++ ) {
1900
for ( t2 = FIRST_REAL_TNUM; t2 <= LAST_VIRTUAL_TNUM; t2++ ) {
1901
InFuncs[t1][t2] = InUndefined;
1902
}
1903
}
1904
InstallInObject(0);
1905
1906
/* make and install the 'SUM' arithmetic operation */
1907
for ( t1 = FIRST_REAL_TNUM; t1 <= LAST_VIRTUAL_TNUM; t1++ ) {
1908
for ( t2 = FIRST_REAL_TNUM; t2 <= LAST_VIRTUAL_TNUM; t2++ ) {
1909
SumFuncs[t1][t2] = SumObject;
1910
}
1911
}
1912
InstallSumObject(0);
1913
1914
/* make and install the 'DIFF' arithmetic operation */
1915
for ( t1 = FIRST_REAL_TNUM; t1 <= LAST_VIRTUAL_TNUM; t1++ ) {
1916
for ( t2 = FIRST_REAL_TNUM; t2 <= LAST_VIRTUAL_TNUM; t2++ ) {
1917
DiffFuncs[t1][t2] = DiffDefault;
1918
}
1919
}
1920
InstallDiffObject(0);
1921
1922
/* make and install the 'PROD' arithmetic operation */
1923
for ( t1 = FIRST_REAL_TNUM; t1 <= LAST_VIRTUAL_TNUM; t1++ ) {
1924
for ( t2 = FIRST_REAL_TNUM; t2 <= LAST_VIRTUAL_TNUM; t2++ ) {
1925
ProdFuncs[t1][t2] = ProdObject;
1926
}
1927
}
1928
InstallProdObject(0);
1929
1930
/* make and install the 'QUO' arithmetic operation */
1931
for ( t1 = FIRST_REAL_TNUM; t1 <= LAST_VIRTUAL_TNUM; t1++ ) {
1932
for ( t2 = FIRST_REAL_TNUM; t2 <= LAST_VIRTUAL_TNUM; t2++ ) {
1933
QuoFuncs[t1][t2] = QuoDefault;
1934
}
1935
}
1936
InstallQuoObject(0);
1937
1938
/* make and install the 'LQUO' arithmetic operation */
1939
for ( t1 = FIRST_REAL_TNUM; t1 <= LAST_VIRTUAL_TNUM; t1++ ) {
1940
for ( t2 = FIRST_REAL_TNUM; t2 <= LAST_VIRTUAL_TNUM; t2++ ) {
1941
LQuoFuncs[t1][t2] = LQuoDefault;
1942
}
1943
}
1944
InstallLQuoObject(0);
1945
1946
/* make and install the 'POW' arithmetic operation */
1947
for ( t1 = FIRST_REAL_TNUM; t1 <= LAST_VIRTUAL_TNUM; t1++ ) {
1948
for ( t2 = FIRST_REAL_TNUM; t2 <= LAST_VIRTUAL_TNUM; t2++ ) {
1949
PowFuncs[t1][t2] = PowObject;
1950
}
1951
}
1952
InstallPowObject(0);
1953
1954
/* make and install the 'COMM' arithmetic operation */
1955
for ( t1 = FIRST_REAL_TNUM; t1 <= LAST_VIRTUAL_TNUM; t1++ ) {
1956
for ( t2 = FIRST_REAL_TNUM; t2 <= LAST_VIRTUAL_TNUM; t2++ ) {
1957
CommFuncs[t1][t2] = CommDefault;
1958
}
1959
}
1960
InstallCommObject(0);
1961
1962
/* make and install the 'MOD' arithmetic operation */
1963
for ( t1 = FIRST_REAL_TNUM; t1 <= LAST_VIRTUAL_TNUM; t1++ ) {
1964
for ( t2 = FIRST_REAL_TNUM; t2 <= LAST_VIRTUAL_TNUM; t2++ ) {
1965
ModFuncs[t1][t2] = ModObject;
1966
}
1967
}
1968
InstallModObject(0);
1969
1970
1971
/* return success */
1972
return 0;
1973
}
1974
1975
1976
/****************************************************************************
1977
**
1978
*F InitLibrary( <module> ) . . . . . . . initialise library data structures
1979
*/
1980
static Int InitLibrary (
1981
StructInitInfo * module )
1982
{
1983
/* init filters and functions */
1984
InitGVarAttrsFromTable( GVarAttrs );
1985
InitGVarOpersFromTable( GVarOpers );
1986
InitGVarFuncsFromTable( GVarFuncs );
1987
1988
/* return success */
1989
return 0;
1990
}
1991
1992
1993
/****************************************************************************
1994
**
1995
*F InitInfoAriths() . . . . . . . . . . . . . . . . table of init functions
1996
*/
1997
static StructInitInfo module = {
1998
MODULE_BUILTIN, /* type */
1999
"ariths", /* name */
2000
0, /* revision entry of c file */
2001
0, /* revision entry of h file */
2002
0, /* version */
2003
0, /* crc */
2004
InitKernel, /* initKernel */
2005
InitLibrary, /* initLibrary */
2006
0, /* checkInit */
2007
0, /* preSave */
2008
0, /* postSave */
2009
0 /* postRestore */
2010
};
2011
2012
StructInitInfo * InitInfoAriths ( void )
2013
{
2014
return &module;
2015
}
2016
2017
2018
/****************************************************************************
2019
**
2020
2021
*E ariths.c . . . . . . . . . . . . . . . . . . . . . . . . . . . ends here
2022
*/
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034