-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtriple-double.h
1380 lines (1067 loc) · 57.5 KB
/
triple-double.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* triple_double.h
*
* This file contains useful tools and data for triple double data representation.
*
*/
#ifndef TRIPLE_DOUBLE_H
#define TRIPLE_DOUBLE_H 1
#include "scs_lib/scs.h"
#include "scs_lib/scs_private.h"
/* undef all the variables that might have been defined in
scs_lib/scs_private.h */
#undef VERSION
#undef PACKAGE
#undef HAVE_GMP_H
#undef HAVE_MPFR_H
#undef HAVE_MATHLIB_H
/* then include the proper definitions */
#include "crlibm_config.h"
#ifdef HAVE_INTTYPES_H
#include <inttypes.h>
#endif
/* Set to O for larger but faster functions.
As it only impacts the second step, smaller is preferred */
#define TRIPLEDOUBLE_AS_FUNCTIONS 0
#define Renormalize3(resh, resm, resl, ah, am, al) DoRenormalize3(resh, resm, resl, ah, am, al)
/*extern void Renormalize3(double* resh, double* resm, double* resl, double ah, double am, double al) ;*/
#if TRIPLEDOUBLE_AS_FUNCTIONS
extern void Mul23(double* resh, double* resm, double* resl, double ah, double al, double bh, double bl);
extern void Mul233(double* resh, double* resm, double* resl, double ah, double al, double bh, double bm, double bl);
extern void Mul33(double* resh, double* resm, double* resl, double ah, double am, double al, double bh, double bm, double bl);
extern void Mul133(double* resh, double* resm, double* resl, double a, double bh, double bm, double bl);
extern void Mul123(double* resh, double* resm, double* resl, double a, double bh, double bl);
extern void Sqrt13(double* resh, double* resm, double* resl, double x);
extern void Recpr33(double* resh, double* resm, double* resl, double dh, double dm, double dl);
#else
#define Mul23(resh, resm, resl, ah, al, bh, bl) DoMul23(resh, resm, resl, ah, al, bh, bl)
#define Mul233(resh, resm, resl, ah, al, bh, bm, bl) DoMul233(resh, resm, resl, ah, al, bh, bm, bl)
#define Mul33(resh, resm, resl, ah, am, al, bh, bm, bl) DoMul33(resh, resm, resl, ah, am, al, bh, bm, bl)
#define Mul133(resh, resm, resl, a, bh, bm, bl) DoMul133(resh, resm, resl, a, bh, bm, bl)
#define Mul123(resh, resm, resl, a, bh, bl) DoMul123(resh, resm, resl, a, bh, bl)
#define Sqrt13(resh, resm, resl , x) DoSqrt13(resh, resm, resl , x)
#define Recpr33(resh, resm, resl, dh, dm, dl) DoRecpr33(resh, resm, resl, dh, dm, dl)
#endif
/* Renormalize3
Procedure for renormalizing a triple double number, i.e.
computing exactly an equivalent sum of three non-overlapping
double numbers
Arguments: a triple double number ah, am, al
Results: a triple double number resh, resm, resl
Preconditions: abs(ah) > abs(am) > abs(al)
ah and am are overlapping not more than 51 bits
am and al are overlapping not more than 51 bits
Guarantees: abs(resh) > abs(resm) > abs(resl)
resh and resm are non-overlapping
resm and resl are non-overlapping
resm = round-to-nearest(resm + resl)
Details: resh, resm and resl are considered to be pointers
*/
#define DoRenormalize3(resh, resm, resl, ah, am, al) \
{ \
double _t1h, _t1l, _t2l; \
\
Add12(_t1h, _t1l, (am), (al)); \
Add12((*(resh)), _t2l, (ah), (_t1h)); \
Add12((*(resm)), (*(resl)), _t2l, _t1l); \
}
/* Mul23
Procedure for multiplying two double double numbers resulting
in a triple double number
Arguments: two double double numbers:
ah, al and
bh, bl
Results: a triple double number resh, resm, resl
Preconditions: abs(ah) > abs(al)
ah and al do not overlap
ah = round-to-nearest(ah + al)
abs(bh) > abs(bl)
bh and bl do not overlap
bh = round-to-nearest(bh + bl)
Guarantees: resm and resl are non-overlapping
resm = round-to-nearest(resm + resl)
abs(resm) <= 2^(-49) * abs(resh)
resh+resm+resl = (ah+al) * (bh+bl) * (1 + eps)
where
abs(eps) <= 2^(-149)
Details: resh, resm and resl are considered to be pointers
*/
#define DoMul23(resh, resm, resl, ah, al, bh, bl) \
{ \
double _t1, _t2, _t3, _t4, _t5, _t6, _t7, _t8, _t9, _t10; \
\
Mul12((resh),&_t1,(ah),(bh)); \
Mul12(&_t2,&_t3,(ah),(bl)); \
Mul12(&_t4,&_t5,(al),(bh)); \
_t6 = (al) * (bl); \
Add22Cond(&_t7,&_t8,_t2,_t3,_t4,_t5); \
Add12(_t9,_t10,_t1,_t6); \
Add22Cond((resm),(resl),_t7,_t8,_t9,_t10); \
}
/* Mul233
Procedure for multiplying a double double number by
a triple double number resulting in a triple double number
Arguments: a double double number ah, al
a triple double number bh, bm, bl
Results: a triple double number resh, resm, resl
Preconditions: abs(ah) > abs(al)
ah and al do not overlap
ah = round-to-nearest(ah + al)
abs(bm) <= 2^(-b_o) * abs(bh)
abs(bl) <= 2^(-b_u) * abs(bm)
where
b_o >= 2
b_u >= 1
Guarantees: resm and resl are non-overlapping
resm = round-to-nearest(resm + resl)
abs(resm) <= 2^(\gamma) * abs(resh)
where
\gamma >= min(48,b_o-4,b_o+b_u-4)
resh+resm+resl=(ah+al) * (bh+bm+bl) * (1+eps)
where
abs(eps) <=
(2^(-99-b_o) + 2^(-99-b_o-b_u) + 2^(-152)) /
(1 - 2^(-53) - 2^(-b_o+1) - 2^(-b_o-b_u+1))
Details: resh, resm and resl are considered to be pointers
*/
#define DoMul233(resh, resm, resl, ah, al, bh, bm, bl) \
{ \
double _t1, _t2, _t3, _t4, _t5, _t6, _t7, _t8, _t9, _t10; \
double _t11, _t12, _t13, _t14, _t15, _t16, _t17, _t18; \
\
Mul12((resh),&_t1,(ah),(bh)); \
Mul12(&_t2,&_t3,(ah),(bm)); \
Mul12(&_t4,&_t5,(ah),(bl)); \
Mul12(&_t6,&_t7,(al),(bh)); \
Mul12(&_t8,&_t9,(al),(bm)); \
_t10 = (al) * (bl); \
Add22Cond(&_t11,&_t12,_t2,_t3,_t4,_t5); \
Add22Cond(&_t13,&_t14,_t6,_t7,_t8,_t9); \
Add22Cond(&_t15,&_t16,_t11,_t12,_t13,_t14); \
Add12Cond(_t17,_t18,_t1,_t10); \
Add22Cond((resm),(resl),_t17,_t18,_t15,_t16); \
}
/* Add33
Procedure for adding two triple double numbers resulting
in a triple double number
Arguments: two triple double numbers:
ah, am, al and
bh, bm, bl
Results: a triple double number resh, resm, resl
Preconditions: abs(bh) <= 0.75 * abs(ah) OR ( sign(bh) = sign(ah) AND abs(bh) <= abs(ah)) (i)
abs(am) <= 2^(-a_o) * abs(ah)
abs(al) <= 2^(-a_u) * abs(am)
abs(bm) <= 2^(-b_o) * abs(bh)
abs(bl) <= 2^(-b_u) * abs(bm)
where
b_o >= a_o >= 4
b_u >= a_u >= 4
Condition (i) may not be respected if
one can assume in this case that ah=am=al=0
Guarantees: resm and resl are non-overlapping
resm = round-to-nearest(resm + resl)
abs(resm) <= 2^(-min(a_o,b_o) + 5) * abs(resh)
resh+resm+resl = (ah+am+al + bh+bm+bl) * (1+eps)
where
abs(eps) <= 2^(-min(a_o+a_u,b_o+b_u)-47) + 2^(-min(a_o,a_u)-98)
Details: resh, resm and resl are considered to be pointers
*/
#define Add33(resh, resm, resl, ah, am, al, bh, bm, bl) \
{ \
double _t1, _t2, _t3, _t4, _t5, _t6, _t7, _t8; \
\
Add12((*(resh)),_t1,(ah),(bh)); \
Add12Cond(_t2,_t3,(am),(bm)); \
_t6 = (al) + (bl); \
Add12Cond(_t7,_t4,_t1,_t2); \
_t5 = _t3 + _t4; \
_t8 = _t5 + _t6; \
Add12Cond((*(resm)),(*(resl)),_t7,_t8); \
}
/* Add33Cond
Procedure for adding two triple double numbers resulting
in a triple double number
Arguments: two triple double numbers:
ah, am, al and
bh, bm, bl
Results: a triple double number resh, resm, resl
Preconditions: abs(am) <= 2^(-a_o) * abs(ah)
abs(al) <= 2^(-a_u) * abs(am)
abs(bm) <= 2^(-b_o) * abs(bh)
abs(bl) <= 2^(-b_u) * abs(bm)
where
b_o >= a_o >= 4
b_u >= a_u >= 4
Condition (i) may not be respected if
one can assume in this case that ah=am=al=0
Guarantees: TODO
Details: resh, resm and resl are considered to be pointers
*/
#define Add33Cond(resh, resm, resl, ah, am, al, bh, bm, bl) \
{ \
double _t1, _t2, _t3, _t4, _t5, _t6, _t7, _t8; \
\
Add12Cond((*(resh)),_t1,(ah),(bh)); \
Add12Cond(_t2,_t3,(am),(bm)); \
_t6 = (al) + (bl); \
Add12Cond(_t7,_t4,_t1,_t2); \
_t5 = _t3 + _t4; \
_t8 = _t5 + _t6; \
Add12Cond((*(resm)),(*(resl)),_t7,_t8); \
}
/* Add233
Procedure for adding a double double number to a triple
double number resulting in a triple double number
Arguments: a double double number ah, al
a triple double number bh, bm, bl
Results: a triple double number resh, resm, resl
Preconditions: abs(ah) > abs(al)
ah and al do not overlap
ah = round-to-nearest(ah + al)
abs(bh) <= 2^(-2) * abs(ah)
abs(bm) <= 2^(-b_o) * abs(bh)
abs(bl) <= 2^(-b_u) * abs(bm)
where
b_o >= 2
b_u >= 1
Guarantees: resm and resl are non-overlapping
resm = round-to-nearest(resm + resl)
abs(resm) <= 2^(\gamma) * abs(resh)
where
\gamma >= min(45,b_o-4,b_o+b_u-2)
resh+resm+resl=((ah+al) + (bh+bm+bl)) * (1+eps)
where
abs(eps) <=
<= 2^(-b_o-b_u-52) + 2^(-b_o-104) + 2^(-153)
Details: resh, resm and resl are considered to be pointers
*/
#define Add233(resh, resm, resl, ah, al, bh, bm, bl) \
{ \
double _t1, _t2, _t3, _t4, _t5, _t6, _t7; \
\
Add12((*(resh)),_t1,(ah),(bh)); \
Add12Cond(_t2,_t3,(al),(bm)); \
Add12Cond(_t4,_t5,_t1,_t2); \
_t6 = _t3 + (bl); \
_t7 = _t6 + _t5; \
Add12Cond((*(resm)),(*(resl)),_t4,_t7); \
}
/* Add123
Procedure for adding a double number to a double
double number resulting in a triple double number
Arguments: a double number a
a double double number bh, bl
Results: a triple double number resh, resm, resl
Preconditions: abs(bh) <= 2^(-2) * abs(a)
abs(bl) <= 2^(-53) * abs(bh)
Guarantees: resm and resl are non-overlapping
resm = round-to-nearest(resm + resl)
abs(resm) <= 2^(-\gamma) * abs(resh)
where
\gamma >= 52
resh+resm+resl=(a + (bh+bm+bl)) exactly
Details: resh, resm and resl are considered to be pointers
*/
#define Add123(resh, resm, resl, a, bh, bl) \
{ \
double _t1; \
\
Add12((*(resh)),_t1,(a),(bh)); \
Add12((*(resm)),(*(resl)),_t1,(bl)); \
}
/* Add213
Procedure for adding a double double number to a double
number resulting in a triple double number
Arguments: a double double number ah, al
a double number b
Results: a triple double number resh, resm, resl
Preconditions: abs(b) <= 2^(-2) * abs(ah)
abs(al) <= 2^(-53) * abs(ah)
Guarantees: resm and resl are non-overlapping
resm = round-to-nearest(resm + resl)
abs(resm) <= 2^(-\gamma) * abs(resh)
where
\gamma >= 52
resh+resm+resl=(a + (bh+bm+bl)) exactly
Details: resh, resm and resl are considered to be pointers
*/
#define Add213(resh, resm, resl, ah, al, b) \
{ \
double _t1; \
\
Add12((*(resh)),_t1,(ah),(b)); \
Add12Cond((*(resm)),(*(resl)),(al),(b)); \
}
/* Add23
Procedure for adding a double-double number to a double-double
number resulting in a triple double number
Arguments: a double double number ah, al
a double double number bh, bl
Results: a triple double number resh, resm, resl
Preconditions: abs(bh) <= 2^(-2) * abs(ah)
abs(al) <= 2^(-53) * abs(ah)
abs(bl) <= 2^(-53) * abs(bh)
Guarantees: TO DO
Details: resh, resm and resl are considered to be pointers
*/
#define Add23(resh, resm, resl, ah, al, bh, bl) \
{ \
double _t1, _t2, _t3, _t4, _t5, _t6; \
\
Add12((*(resh)),_t1,(ah),(bh)); \
Add12Cond(_t2,_t3,(al),(bl)); \
Add12Cond(_t4,_t5,_t1,_t2); \
_t6 = _t3 + _t5; \
Add12Cond((*(resm)),(*(resl)),_t4,_t6); \
}
/* Add133
Procedure for adding a double number to a triple
double number resulting in a triple double number
Arguments: a double number a
a triple double number bh, bm, bl
Results: a triple double number resh, resm, resl
Preconditions: abs(bh) <= 2^(-2) * abs(a)
abs(bm) <= 2^(-b_o) * abs(bh)
abs(bl) <= 2^(-b_u) * abs(bm)
where
b_o >= 2
b_u >= 1
Guarantees: resm and resl are non-overlapping
resm = round-to-nearest(resm + resl)
abs(resm) <= 2^(\gamma) * abs(resh)
where
\gamma >= min(47,2-b_o,1-b_o-b_u)
resh+resm+resl=(a + (bh+bm+bl)) * (1+eps)
where
abs(eps) <=
<= 2^(-52-b_o-b_u) + 2^(-154)
Details: resh, resm and resl are considered to be pointers
*/
#define Add133(resh, resm, resl, a, bh, bm, bl) \
{ \
double _t1, _t2, _t3, _t4; \
\
Add12((*(resh)),_t1,(a),(bh)); \
Add12Cond(_t2,_t3,_t1,(bm)); \
_t4 = _t3 + (bl); \
Add12Cond((*(resm)),(*(resl)),_t2,_t4); \
}
/* Add133Cond
Procedure for adding a double number to a triple
double number resulting in a triple double number
Arguments: a double number a
a triple double number bh, bm, bl
Results: a triple double number resh, resm, resl
Preconditions: abs(bm) <= 2^(-b_o) * abs(bh)
abs(bl) <= 2^(-b_u) * abs(bm)
where
b_o >= 2
b_u >= 1
Guarantees: resm and resl are non-overlapping
resm = round-to-nearest(resm + resl)
abs(resm) <= 2^(\gamma) * abs(resh)
where
TODO
resh+resm+resl=(a + (bh+bm+bl)) * (1+eps)
where
abs(eps) <=
TODO
Details: resh, resm and resl are considered to be pointers
*/
#define Add133Cond(resh, resm, resl, a, bh, bm, bl) \
{ \
double _t1, _t2, _t3, _t4; \
\
Add12Cond((*(resh)),_t1,(a),(bh)); \
Add12Cond(_t2,_t3,_t1,(bm)); \
_t4 = _t3 + (bl); \
Add12Cond((*(resm)),(*(resl)),_t2,_t4); \
}
/* Add233Cond
Procedure for adding a double double number to a triple
double number resulting in a triple double number
Arguments: a double double number ah, al
a triple double number bh, bm, bl
Results: a triple double number resh, resm, resl
Preconditions: abs(ah) > abs(al)
ah and al do not overlap
ah = round-to-nearest(ah + al)
abs(bm) <= 2^(-b_o) * abs(bh)
abs(bl) <= 2^(-b_u) * abs(bm)
where
b_o >= 2
b_u >= 1
Guarantees: resm and resl are non-overlapping
resm = round-to-nearest(resm + resl)
abs(resm) <= 2^(\gamma) * abs(resh)
where
\gamma >= ????
resh+resm+resl=((ah+al) + (bh+bm+bl)) * (1+eps)
where
abs(eps) <=
<= ????
Details: resh, resm and resl are considered to be pointers
*/
#define Add233Cond(resh, resm, resl, ah, al, bh, bm, bl) \
{ \
double _t1, _t2, _t3, _t4, _t5, _t6, _t7; \
\
Add12Cond((*(resh)),_t1,(ah),(bh)); \
Add12Cond(_t2,_t3,(al),(bm)); \
Add12Cond(_t4,_t5,_t1,_t2); \
_t6 = _t3 + (bl); \
_t7 = _t6 + _t5; \
Add12Cond((*(resm)),(*(resl)),_t4,_t7); \
}
/* Mul33
Procedure for multiplying two triple double numbers resulting
in a triple double number
Arguments: two triple double numbers:
ah, am, al and
bh, bm, bl
Results: a triple double number resh, resm, resl
Preconditions: abs(am) <= 2^(-a_o) * abs(ah)
abs(al) <= 2^(-a_u) * abs(am)
abs(bm) <= 2^(-b_o) * abs(bh)
abs(bl) <= 2^(-b_u) * abs(bm)
where
b_o, a_o >= 5
b_u, a_u >= 5
Guarantees: resm and resl are non-overlapping
resm = round-to-nearest(resm + resl)
abs(resm) <= 2^(-g_o) * abs(resh)
with
g_o > min(48,-4+a_o,-4+b_o,-4+a_o-b_o)
resh+resm+resl = (ah+am+al) * (bh+bm+bl) * (1+eps)
where
abs(eps) <= 2^-151 + 2^-99-a_o + 2^-99-b_o +
+ 2^-49-a_o-a_u + 2^-49-b_o-b_u + 2^50-a_o-b_o-b_u +
+ 2^50-a_o-b_o-b_u + 2^-101-a_o-b_o + 2^-52-a_o-a_u-b_o-b_u
Details: resh, resm and resl are considered to be pointers
*/
#define DoMul33(resh, resm, resl, ah, am, al, bh, bm, bl) \
{ \
double _t1, _t2, _t3, _t4, _t5, _t6, _t7, _t8, _t9; \
double _t10, _t11, _t12, _t13, _t14, _t15, _t16, _t17; \
double _t18, _t19, _t20, _t21, _t22; \
\
Mul12((resh),&_t1,(ah),(bh)); \
Mul12(&_t2,&_t3,(ah),(bm)); \
Mul12(&_t4,&_t5,(am),(bh)); \
Mul12(&_t6,&_t7,(am),(bm)); \
_t8 = (ah) * (bl); \
_t9 = (al) * (bh); \
_t10 = (am) * (bl); \
_t11 = (al) * (bm); \
_t12 = _t8 + _t9; \
_t13 = _t10 + _t11; \
Add12Cond(_t14,_t15,_t1,_t6); \
_t16 = _t7 + _t15; \
_t17 = _t12 + _t13; \
_t18 = _t16 + _t17; \
Add12Cond(_t19,_t20,_t14,_t18); \
Add22Cond(&_t21,&_t22,_t2,_t3,_t4,_t5); \
Add22Cond((resm),(resl),_t21,_t22,_t19,_t20); \
}
/* Mul133
Procedure for multiplying double by a triple double number resulting
in a triple double number
Arguments: a double a
a triple double bh, bm, bl
Results: a triple double number resh, resm, resl
Preconditions: abs(bm) <= 2^(-b_o) * abs(bh)
abs(bl) <= 2^(-b_u) * abs(bm)
where
b_o >= 2
b_u >= 2
Guarantees: resm and resl are non-overlapping
resm = round-to-nearest(resm + resl)
abs(resm) <= 2^(-g_o) * abs(resh)
with
g_o > min(47,-5-b_o,-5+b_o+b_u)
resh+resm+resl = a * (bh+bm+bl) * (1+eps)
where
abs(eps) <= 2^-49-b_o-b_u + 2^-101-b_o + 2^-156
Details: resh, resm and resl are considered to be pointers
*/
#define DoMul133(resh, resm, resl, a, bh, bm, bl) \
{ \
double _t2, _t3, _t4, _t5, _t7, _t8, _t9, _t10; \
\
Mul12((resh),&_t2,(a),(bh)); \
Mul12(&_t3,&_t4,(a),(bm)); \
_t5 = (a) * (bl); \
Add12Cond(_t9,_t7,_t2,_t3); \
_t8 = _t4 + _t5; \
_t10 = _t7 + _t8; \
Add12Cond((*(resm)),(*(resl)),_t9,_t10); \
}
/* Mul123
Procedure for multiplying double by a double double number resulting
in a triple double number
Arguments: a double a
a double double bh, bl
Results: a triple double number resh, resm, resl
Guarantees: resm and resl are non-overlapping
resm = round-to-nearest(resm + resl)
abs(resm) <= 2^(-g_o) * abs(resh)
with
g_o > 47
resh+resm+resl = a * (bh+bm) * (1+eps)
where
abs(eps) <= 2^-154
Details: resh, resm and resl are considered to be pointers
*/
#define DoMul123(resh, resm, resl, a, bh, bl) \
{ \
double _t1, _t2, _t3, _t4, _t5, _t6; \
\
Mul12((resh),&_t1,(a),(bh)); \
Mul12(&_t2,&_t3,(a),(bl)); \
Add12Cond(_t5,_t4,_t1,_t2); \
_t6 = _t3 + _t4; \
Add12Cond((*(resm)),(*(resl)),_t5,_t6); \
}
/* ReturnRoundToNearest3
Procedure for rounding a triple to a double number
in round-to-nearest-ties-to-even mode.
Arguments: a triple double number xh, xm, xl
Results: a double number xprime
returned by a return-statement
Preconditions: xh, xm and xl are non-overlapping
xm = RN(xm +math xl)
xh != 0, xm != 0
xl = 0 iff xm != +/- 0.5 * ulp(xh) (0.25 if xh = 2^e)
Guarantees: xprime = RN(xh + xm + xl)
Sideeffects: returns, i.e. leaves the function
*/
#define ReturnRoundToNearest3(xh,xm,xl) \
{ \
double _t1, _t2, _t3, _t4, _t5, _t6; \
db_number _xp, _xn; \
\
_xp.d = (xh); \
_xn.i[HI] = _xp.i[HI]; \
_xn.i[LO] = _xp.i[LO]; \
_xn.l--; \
_t1 = _xn.d; \
_xp.l++; \
_t4 = _xp.d; \
_t2 = (xh) - _t1; \
_t3 = _t2 * -0.5; \
_t5 = _t4 - (xh); \
_t6 = _t5 * 0.5; \
if (((xm) != _t3) && ((xm) != _t6)) return ((xh) + (xm)); \
if ((xm) * (xl) > 0.0) { \
if ((xh) * (xl) > 0.0) \
return _t4; \
else \
return _t1; \
} else return (xh); \
}
/* ReturnRoundToNearest3Other
ATTENTION: THIS CURRENTLY UNPROVEN CODE !!!
Procedure for rounding a triple to a double number
in round-to-nearest-ties-to-even mode.
Arguments: a triple double number xh, xm, xl
Results: a double number xprime
returned by a return-statement
Preconditions: |xm + xl| <= 2^(-5) * |xh|
Guarantees: xprime = RN(xh + xm + xl)
Sideeffects: returns, i.e. leaves the function
*/
#define ReturnRoundToNearest3Other(xh,xm,xl) \
{ \
double _t3, _t4; \
db_number _t3db; \
\
Add12(_t3,_t4,(xm),(xl)); \
if (_t4 != 0.0) { \
_t3db.d = _t3; \
if (!(_t3db.i[LO] & 0x00000001)) { \
if ((_t4 > 0.0) ^ ((_t3db.i[HI] & 0x80000000) != 0)) \
_t3db.l++; \
else \
_t3db.l--; \
_t3 = _t3db.d; \
} \
} \
return (xh) + _t3; \
}
/* ReturnRoundUpwards3
Procedure for rounding a triple to a double number
in round-upwards mode.
Arguments: a triple double number xh, xm, xl
Results: a double number xprime
returned by a return-statement
Preconditions: xh, xm and xl are non-overlapping
xm = RN(xm +math xl)
xh != 0, xm != 0
Exact algebraic images have already
been filtered out.
Guarantees: xprime = RU(xh + xm + xl)
Sideeffects: returns, i.e. leaves the function
*/
#define ReturnRoundUpwards3(xh,xm,xl) \
{ \
double _t1, _t2, _t3; \
db_number _tdb; \
\
Add12(_t1,_t2,(xh),(xm)); \
_t3 = _t2 + (xl); \
if (_t3 > 0.0) { \
if (_t1 > 0.0) { \
_tdb.d = _t1; \
_tdb.l++; \
return _tdb.d; \
} else { \
_tdb.d = _t1; \
_tdb.l--; \
return _tdb.d; \
} \
} else return _t1; \
}
/* ReturnRoundDownwards3
Procedure for rounding a triple to a double number
in round-downwards mode.
Arguments: a triple double number xh, xm, xl
Results: a double number xprime
returned by a return-statement
Preconditions: xh, xm and xl are non-overlapping
xm = RN(xm +math xl)
xh != 0, xm != 0
Exact algebraic images have already
been filtered out.
Guarantees: xprime = RD(xh + xm + xl)
Sideeffects: returns, i.e. leaves the function
*/
#define ReturnRoundDownwards3(xh,xm,xl) \
{ \
double _t1, _t2, _t3; \
db_number _tdb; \
\
Add12(_t1,_t2,(xh),(xm)); \
_t3 = _t2 + (xl); \
if (_t3 < 0.0) { \
if (_t1 > 0.0) { \
_tdb.d = _t1; \
_tdb.l--; \
return _tdb.d; \
} else { \
_tdb.d = _t1; \
_tdb.l++; \
return _tdb.d; \
} \
} else return _t1; \
}
/* ReturnRoundTowardsZero3
Procedure for rounding a triple to a double number
in round-towards-zero mode.
Arguments: a triple double number xh, xm, xl
Results: a double number xprime
returned by a return-statement
Preconditions: xh, xm and xl are non-overlapping
xm = RN(xm +math xl)
xh != 0, xm != 0
Exact algebraic images have already
been filtered out.
Guarantees: xprime = RZ(xh + xm + xl)
Sideeffects: returns, i.e. leaves the function
*/
#define ReturnRoundTowardsZero3(xh,xm,xl) \
{ \
double _t1, _t2, _t3; \
db_number _tdb; \
\
Add12(_t1,_t2,(xh),(xm)); \
_t3 = _t2 + (xl); \
if (_t1 > 0.0) { \
if (_t3 < 0.0) { \
_tdb.d = _t1; \
_tdb.l--; \
return _tdb.d; \
} else return _t1; \
} else { \
if (_t3 > 0.0) { \
_tdb.d = _t1; \
_tdb.l--; \
return _tdb.d; \
} else return _t1; \
} \
}
/* ReturnRoundUpwards3Unfiltered
Procedure for rounding a triple to a double number
in round-upwards mode.
Arguments: a triple double number xh, xm, xl
a double constant wca representing 2^k
where 2^-k is Lefevre's worst case accuracy
Results: a double number xprime
returned by a return-statement
Preconditions: xh, xm and xl are non-overlapping
xm = RN(xm +math xl)
xh != 0, xm != 0
Guarantees: xprime = RU(xh + xm + xl)
Sideeffects: returns, i.e. leaves the function
*/
#define ReturnRoundUpwards3Unfiltered(xh,xm,xl,wca) \
{ \
double _t1, _t2, _t3; \
db_number _tdb, _tdb2; \
\
Add12(_t1,_t2,(xh),(xm)); \
_t3 = _t2 + (xl); \
if (_t3 > 0.0) { \
_tdb2.d = wca * _t3; \
_tdb.d = _t1; \
if ((_tdb2.i[HI] & 0x7ff00000) < (_tdb.i[HI] & 0x7ff00000)) \
return _t1; \
if (_t1 > 0.0) { \
_tdb.l++; \
return _tdb.d; \
} else { \
_tdb.l--; \
return _tdb.d; \
} \
} else return _t1; \
}
/* ReturnRoundDownwards3Unfiltered
Procedure for rounding a triple to a double number
in round-downwards mode.
Arguments: a triple double number xh, xm, xl
a double constant wca representing 2^k
where 2^-k is Lefevre's worst case accuracy
Results: a double number xprime
returned by a return-statement
Preconditions: xh, xm and xl are non-overlapping
xm = RN(xm +math xl)
xh != 0, xm != 0
Guarantees: xprime = RD(xh + xm + xl)
Sideeffects: returns, i.e. leaves the function
*/
#define ReturnRoundDownwards3Unfiltered(xh,xm,xl,wca) \
{ \
double _t1, _t2, _t3; \
db_number _tdb, _tdb2; \
\
Add12(_t1,_t2,(xh),(xm)); \
_t3 = _t2 + (xl); \
if (_t3 < 0.0) { \
_tdb2.d = wca * _t3; \
_tdb.d = _t1; \
if ((_tdb2.i[HI] & 0x7ff00000) < (_tdb.i[HI] & 0x7ff00000)) \
return _t1; \
if (_t1 > 0.0) { \
_tdb.l--; \
return _tdb.d; \
} else { \
_tdb.l++; \