-
-
Notifications
You must be signed in to change notification settings - Fork 90
/
dlamch.cs
1489 lines (1393 loc) · 53.6 KB
/
dlamch.cs
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
#region Translated by Jose Antonio De Santiago-Castillo.
//Translated by Jose Antonio De Santiago-Castillo.
//E-mail:JAntonioDeSantiago@gmail.com
//Website: www.DotNumerics.com
//
//Fortran to C# Translation.
//Translated by:
//F2CSharp Version 0.72 (Dicember 7, 2009)
//Code Optimizations: , assignment operator, for-loop: array indexes
//
#endregion
using System;
using DotNumerics.FortranLibrary;
namespace DotNumerics.LinearAlgebra.CSLapack
{
#region The Class: DLAMCH
/// <summary>
/// -- LAPACK auxiliary routine (version 3.1) --
/// Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
/// November 2006
/// Purpose
/// =======
///
/// DLAMCH determines double precision machine parameters.
///
///</summary>
public class DLAMCH
{
#region Dependencies
LSAME _lsame; DLAMC2 _dlamc2;
#endregion
#region Variables
const double ONE = 1.0E+0; const double ZERO = 0.0E+0; bool FIRST = false; double BASE = 0; double EMAX = 0;
double EMIN = 0;double EPS = 0; double PREC = 0; double RMAX = 0; double RMIN = 0; double RND = 0; double SFMIN = 0;
double T = 0;
#endregion
public DLAMCH(LSAME lsame, DLAMC2 dlamc2)
{
#region Set Dependencies
this._lsame = lsame; this._dlamc2 = dlamc2;
#endregion
#region Data Initialization
//FIRST/.TRUE.
FIRST = true;
#endregion
}
public DLAMCH()
{
#region Dependencies (Initialization)
LSAME lsame = new LSAME();
DLAMC3 dlamc3 = new DLAMC3();
DLAMC1 dlamc1 = new DLAMC1(dlamc3);
DLAMC4 dlamc4 = new DLAMC4(dlamc3);
DLAMC5 dlamc5 = new DLAMC5(dlamc3);
DLAMC2 dlamc2 = new DLAMC2(dlamc3, dlamc1, dlamc4, dlamc5);
#endregion
#region Set Dependencies
this._lsame = lsame; this._dlamc2 = dlamc2;
#endregion
#region Data Initialization
//FIRST/.TRUE.
FIRST = true;
#endregion
}
/// <summary>
/// Purpose
/// =======
///
/// DLAMCH determines double precision machine parameters.
///
///</summary>
/// <param name="CMACH">
/// (input) CHARACTER*1
/// Specifies the value to be returned by DLAMCH:
/// = 'E' or 'e', DLAMCH := eps
/// = 'S' or 's , DLAMCH := sfmin
/// = 'B' or 'b', DLAMCH := base
/// = 'P' or 'p', DLAMCH := eps*base
/// = 'N' or 'n', DLAMCH := t
/// = 'R' or 'r', DLAMCH := rnd
/// = 'M' or 'm', DLAMCH := emin
/// = 'U' or 'u', DLAMCH := rmin
/// = 'L' or 'l', DLAMCH := emax
/// = 'O' or 'o', DLAMCH := rmax
///
/// where
///
/// eps = relative machine precision
/// sfmin = safe minimum, such that 1/sfmin does not overflow
/// base = base of the machine
/// prec = eps*base
/// t = number of (base) digits in the mantissa
/// rnd = 1.0 when rounding occurs in addition, 0.0 otherwise
/// emin = minimum exponent before (gradual) underflow
/// rmin = underflow threshold - base**(emin-1)
/// emax = largest exponent before overflow
/// rmax = overflow threshold - (base**emax)*(1-eps)
///</param>
public double Run(string CMACH)
{
double dlamch = 0;
#region Variables
bool LRND = false; int BETA = 0; int IMAX = 0; int IMIN = 0; int IT = 0; double RMACH = 0; double SMALL = 0;
#endregion
#region Strings
CMACH = CMACH.Substring(0, 1);
#endregion
#region Prolog
// *
// * -- LAPACK auxiliary routine (version 3.1) --
// * Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
// * November 2006
// *
// * .. Scalar Arguments ..
// * ..
// *
// * Purpose
// * =======
// *
// * DLAMCH determines double precision machine parameters.
// *
// * Arguments
// * =========
// *
// * CMACH (input) CHARACTER*1
// * Specifies the value to be returned by DLAMCH:
// * = 'E' or 'e', DLAMCH := eps
// * = 'S' or 's , DLAMCH := sfmin
// * = 'B' or 'b', DLAMCH := base
// * = 'P' or 'p', DLAMCH := eps*base
// * = 'N' or 'n', DLAMCH := t
// * = 'R' or 'r', DLAMCH := rnd
// * = 'M' or 'm', DLAMCH := emin
// * = 'U' or 'u', DLAMCH := rmin
// * = 'L' or 'l', DLAMCH := emax
// * = 'O' or 'o', DLAMCH := rmax
// *
// * where
// *
// * eps = relative machine precision
// * sfmin = safe minimum, such that 1/sfmin does not overflow
// * base = base of the machine
// * prec = eps*base
// * t = number of (base) digits in the mantissa
// * rnd = 1.0 when rounding occurs in addition, 0.0 otherwise
// * emin = minimum exponent before (gradual) underflow
// * rmin = underflow threshold - base**(emin-1)
// * emax = largest exponent before overflow
// * rmax = overflow threshold - (base**emax)*(1-eps)
// *
// * =====================================================================
// *
// * .. Parameters ..
// * ..
// * .. Local Scalars ..
// * ..
// * .. External Functions ..
// * ..
// * .. External Subroutines ..
// * ..
// * .. Save statement ..
// * ..
// * .. Data statements ..
// * ..
// * .. Executable Statements ..
// *
#endregion
#region Body
if (FIRST)
{
this._dlamc2.Run(ref BETA, ref IT, ref LRND, ref EPS, ref IMIN, ref RMIN
, ref IMAX, ref RMAX);
BASE = BETA;
T = IT;
if (LRND)
{
RND = ONE;
EPS = (Math.Pow(BASE,1 - IT)) / 2;
}
else
{
RND = ZERO;
EPS = Math.Pow(BASE,1 - IT);
}
PREC = EPS * BASE;
EMIN = IMIN;
EMAX = IMAX;
SFMIN = RMIN;
SMALL = ONE / RMAX;
if (SMALL >= SFMIN)
{
// *
// * Use SMALL plus a bit, to avoid the possibility of rounding
// * causing overflow when computing 1/sfmin.
// *
SFMIN = SMALL * (ONE + EPS);
}
}
// *
if (this._lsame.Run(CMACH, "E"))
{
RMACH = EPS;
}
else
{
if (this._lsame.Run(CMACH, "S"))
{
RMACH = SFMIN;
}
else
{
if (this._lsame.Run(CMACH, "B"))
{
RMACH = BASE;
}
else
{
if (this._lsame.Run(CMACH, "P"))
{
RMACH = PREC;
}
else
{
if (this._lsame.Run(CMACH, "N"))
{
RMACH = T;
}
else
{
if (this._lsame.Run(CMACH, "R"))
{
RMACH = RND;
}
else
{
if (this._lsame.Run(CMACH, "M"))
{
RMACH = EMIN;
}
else
{
if (this._lsame.Run(CMACH, "U"))
{
RMACH = RMIN;
}
else
{
if (this._lsame.Run(CMACH, "L"))
{
RMACH = EMAX;
}
else
{
if (this._lsame.Run(CMACH, "O"))
{
RMACH = RMAX;
}
}
}
}
}
}
}
}
}
}
// *
dlamch = RMACH;
FIRST = false;
return dlamch;
// *
// * End of DLAMCH
// *
#endregion
}
}
#endregion
#region The Class: DLAMC1
// *
// ************************************************************************
// *
/// <summary>
/// -- LAPACK auxiliary routine (version 3.1) --
/// Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
/// November 2006
/// Purpose
/// =======
///
/// DLAMC1 determines the machine parameters given by BETA, T, RND, and
/// IEEE1.
///
///</summary>
public class DLAMC1
{
#region Dependencies
DLAMC3 _dlamc3;
#endregion
#region Variables
bool FIRST = false; bool LIEEE1 = false; bool LRND = false; int LBETA = 0; int LT = 0;
#endregion
public DLAMC1(DLAMC3 dlamc3)
{
#region Set Dependencies
this._dlamc3 = dlamc3;
#endregion
#region Data Initialization
//FIRST/.TRUE.
FIRST = true;
#endregion
}
public DLAMC1()
{
#region Dependencies (Initialization)
DLAMC3 dlamc3 = new DLAMC3();
#endregion
#region Set Dependencies
this._dlamc3 = dlamc3;
#endregion
#region Data Initialization
//FIRST/.TRUE.
FIRST = true;
#endregion
}
/// <summary>
/// Purpose
/// =======
///
/// DLAMC1 determines the machine parameters given by BETA, T, RND, and
/// IEEE1.
///
///</summary>
/// <param name="BETA">
/// (output) INTEGER
/// The base of the machine.
///</param>
/// <param name="T">
/// (output) INTEGER
/// The number of ( BETA ) digits in the mantissa.
///</param>
/// <param name="RND">
/// (output) LOGICAL
/// Specifies whether proper rounding ( RND = .TRUE. ) or
/// chopping ( RND = .FALSE. ) occurs in addition. This may not
/// be a reliable guide to the way in which the machine performs
/// its arithmetic.
///</param>
/// <param name="IEEE1">
/// (output) LOGICAL
/// Specifies whether rounding appears to be done in the IEEE
/// 'round to nearest' style.
///</param>
public void Run(ref int BETA, ref int T, ref bool RND, ref bool IEEE1)
{
#region Variables
double A = 0; double B = 0; double C = 0; double F = 0; double ONE = 0; double QTR = 0; double SAVEC = 0;
double T1 = 0;double T2 = 0;
#endregion
#region Prolog
// *
// * -- LAPACK auxiliary routine (version 3.1) --
// * Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
// * November 2006
// *
// * .. Scalar Arguments ..
// * ..
// *
// * Purpose
// * =======
// *
// * DLAMC1 determines the machine parameters given by BETA, T, RND, and
// * IEEE1.
// *
// * Arguments
// * =========
// *
// * BETA (output) INTEGER
// * The base of the machine.
// *
// * T (output) INTEGER
// * The number of ( BETA ) digits in the mantissa.
// *
// * RND (output) LOGICAL
// * Specifies whether proper rounding ( RND = .TRUE. ) or
// * chopping ( RND = .FALSE. ) occurs in addition. This may not
// * be a reliable guide to the way in which the machine performs
// * its arithmetic.
// *
// * IEEE1 (output) LOGICAL
// * Specifies whether rounding appears to be done in the IEEE
// * 'round to nearest' style.
// *
// * Further Details
// * ===============
// *
// * The routine is based on the routine ENVRON by Malcolm and
// * incorporates suggestions by Gentleman and Marovich. See
// *
// * Malcolm M. A. (1972) Algorithms to reveal properties of
// * floating-point arithmetic. Comms. of the ACM, 15, 949-951.
// *
// * Gentleman W. M. and Marovich S. B. (1974) More on algorithms
// * that reveal properties of floating point arithmetic units.
// * Comms. of the ACM, 17, 276-277.
// *
// * =====================================================================
// *
// * .. Local Scalars ..
// * ..
// * .. External Functions ..
// * ..
// * .. Save statement ..
// * ..
// * .. Data statements ..
// * ..
// * .. Executable Statements ..
// *
#endregion
#region Body
if (FIRST)
{
ONE = 1;
// *
// * LBETA, LIEEE1, LT and LRND are the local values of BETA,
// * IEEE1, T and RND.
// *
// * Throughout this routine we use the function DLAMC3 to ensure
// * that relevant values are stored and not held in registers, or
// * are not affected by optimizers.
// *
// * Compute a = 2.0**m with the smallest positive integer m such
// * that
// *
// * fl( a + 1.0 ) = a.
// *
A = 1;
C = 1;
// *
// *+ WHILE( C.EQ.ONE )LOOP
LABEL10:;
if (C == ONE)
{
A *= 2;
C = (double)this._dlamc3.Run(A, ONE);
C = (double)this._dlamc3.Run(C, -A);
goto LABEL10;
}
// *+ END WHILE
// *
// * Now compute b = 2.0**m with the smallest positive integer m
// * such that
// *
// * fl( a + b ) .gt. a.
// *
B = 1;
C = this._dlamc3.Run(A, B);
// *
// *+ WHILE( C.EQ.A )LOOP
LABEL20:;
if (C == A)
{
B *= 2;
C = (double)this._dlamc3.Run(A, B);
goto LABEL20;
}
// *+ END WHILE
// *
// * Now compute the base. a and c are neighbouring floating point
// * numbers in the interval ( beta**t, beta**( t + 1 ) ) and so
// * their difference is beta. Adding 0.25 to c is to ensure that it
// * is truncated to beta and not ( beta - 1 ).
// *
QTR = ONE / 4;
SAVEC = C;
C = (double)this._dlamc3.Run(C, -A);
LBETA = (int)(C + QTR);
// *
// * Now determine whether rounding or chopping occurs, by adding a
// * bit less than beta/2 and a bit more than beta/2 to a.
// *
B = LBETA;
F = (double)this._dlamc3.Run(B / 2, -B / 100);
C = (double)this._dlamc3.Run(F, A);
if (C == A)
{
LRND = true;
}
else
{
LRND = false;
}
F = (double)this._dlamc3.Run(B / 2, B / 100);
C = (double)this._dlamc3.Run(F, A);
if ((LRND) && (C == A)) LRND = false;
// *
// * Try and decide whether rounding is done in the IEEE 'round to
// * nearest' style. B/2 is half a unit in the last place of the two
// * numbers A and SAVEC. Furthermore, A is even, i.e. has last bit
// * zero, and SAVEC is odd. Thus adding B/2 to A should not change
// * A, but adding B/2 to SAVEC should change SAVEC.
// *
T1 = (double)this._dlamc3.Run(B / 2, A);
T2 = (double)this._dlamc3.Run(B / 2, SAVEC);
LIEEE1 = (T1 == A) && (T2 > SAVEC) && LRND;
// *
// * Now find the mantissa, t. It should be the integer part of
// * log to the base beta of a, however it is safer to determine t
// * by powering. So we find t as the smallest positive integer for
// * which
// *
// * fl( beta**t + 1.0 ) = 1.0.
// *
LT = 0;
A = 1;
C = 1;
// *
// *+ WHILE( C.EQ.ONE )LOOP
LABEL30:;
if (C == ONE)
{
LT += 1;
A *= LBETA;
C = (double)this._dlamc3.Run(A, ONE);
C = (double)this._dlamc3.Run(C, -A);
goto LABEL30;
}
// *+ END WHILE
// *
}
// *
BETA = LBETA;
T = LT;
RND = LRND;
IEEE1 = LIEEE1;
FIRST = false;
return;
// *
// * End of DLAMC1
// *
#endregion
}
}
#endregion
#region The Class: DLAMC2
// *
// ************************************************************************
// *
/// <summary>
/// -- LAPACK auxiliary routine (version 3.1) --
/// Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
/// November 2006
/// Purpose
/// =======
///
/// DLAMC2 determines the machine parameters specified in its argument
/// list.
///
///</summary>
public class DLAMC2
{
#region Dependencies
DLAMC3 _dlamc3; DLAMC1 _dlamc1; DLAMC4 _dlamc4; DLAMC5 _dlamc5;
#endregion
#region Variables
bool FIRST = false; bool IWARN = false; int LBETA = 0; int LEMAX = 0; int LEMIN = 0; int LT = 0; double LEPS = 0;
double LRMAX = 0;double LRMIN = 0;
#endregion
public DLAMC2(DLAMC3 dlamc3, DLAMC1 dlamc1, DLAMC4 dlamc4, DLAMC5 dlamc5)
{
#region Set Dependencies
this._dlamc3 = dlamc3; this._dlamc1 = dlamc1; this._dlamc4 = dlamc4; this._dlamc5 = dlamc5;
#endregion
#region Data Initialization
//FIRST/.TRUE.
FIRST = true;
//IWARN/.FALSE.
IWARN = false;
#endregion
}
public DLAMC2()
{
#region Dependencies (Initialization)
DLAMC3 dlamc3 = new DLAMC3();
DLAMC1 dlamc1 = new DLAMC1(dlamc3);
DLAMC4 dlamc4 = new DLAMC4(dlamc3);
DLAMC5 dlamc5 = new DLAMC5(dlamc3);
#endregion
#region Set Dependencies
this._dlamc3 = dlamc3; this._dlamc1 = dlamc1; this._dlamc4 = dlamc4; this._dlamc5 = dlamc5;
#endregion
#region Data Initialization
//FIRST/.TRUE.
FIRST = true;
//IWARN/.FALSE.
IWARN = false;
#endregion
}
/// <summary>
/// Purpose
/// =======
///
/// DLAMC2 determines the machine parameters specified in its argument
/// list.
///
///</summary>
/// <param name="BETA">
/// (output) INTEGER
/// The base of the machine.
///</param>
/// <param name="T">
/// (output) INTEGER
/// The number of ( BETA ) digits in the mantissa.
///</param>
/// <param name="RND">
/// (output) LOGICAL
/// Specifies whether proper rounding ( RND = .TRUE. ) or
/// chopping ( RND = .FALSE. ) occurs in addition. This may not
/// be a reliable guide to the way in which the machine performs
/// its arithmetic.
///</param>
/// <param name="EPS">
/// (output) DOUBLE PRECISION
/// The smallest positive number such that
///
/// fl( 1.0 - EPS ) .LT. 1.0,
///
/// where fl denotes the computed value.
///</param>
/// <param name="EMIN">
/// (output) INTEGER
/// The minimum exponent before (gradual) underflow occurs.
///</param>
/// <param name="RMIN">
/// (output) DOUBLE PRECISION
/// The smallest normalized number for the machine, given by
/// BASE**( EMIN - 1 ), where BASE is the floating point value
/// of BETA.
///</param>
/// <param name="EMAX">
/// (output) INTEGER
/// The maximum exponent before overflow occurs.
///</param>
/// <param name="RMAX">
/// (output) DOUBLE PRECISION
/// The largest positive number for the machine, given by
/// BASE**EMAX * ( 1 - EPS ), where BASE is the floating point
/// value of BETA.
///</param>
public void Run(ref int BETA, ref int T, ref bool RND, ref double EPS, ref int EMIN, ref double RMIN
, ref int EMAX, ref double RMAX)
{
#region Variables
bool IEEE = false; bool LIEEE1 = false; bool LRND = false; int GNMIN = 0; int GPMIN = 0; int I = 0; int NGNMIN = 0;
int NGPMIN = 0;double A = 0; double B = 0; double C = 0; double HALF = 0; double ONE = 0; double RBASE = 0;
double SIXTH = 0;double SMALL = 0; double THIRD = 0; double TWO = 0; double ZERO = 0;
#endregion
#region Prolog
// *
// * -- LAPACK auxiliary routine (version 3.1) --
// * Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
// * November 2006
// *
// * .. Scalar Arguments ..
// * ..
// *
// * Purpose
// * =======
// *
// * DLAMC2 determines the machine parameters specified in its argument
// * list.
// *
// * Arguments
// * =========
// *
// * BETA (output) INTEGER
// * The base of the machine.
// *
// * T (output) INTEGER
// * The number of ( BETA ) digits in the mantissa.
// *
// * RND (output) LOGICAL
// * Specifies whether proper rounding ( RND = .TRUE. ) or
// * chopping ( RND = .FALSE. ) occurs in addition. This may not
// * be a reliable guide to the way in which the machine performs
// * its arithmetic.
// *
// * EPS (output) DOUBLE PRECISION
// * The smallest positive number such that
// *
// * fl( 1.0 - EPS ) .LT. 1.0,
// *
// * where fl denotes the computed value.
// *
// * EMIN (output) INTEGER
// * The minimum exponent before (gradual) underflow occurs.
// *
// * RMIN (output) DOUBLE PRECISION
// * The smallest normalized number for the machine, given by
// * BASE**( EMIN - 1 ), where BASE is the floating point value
// * of BETA.
// *
// * EMAX (output) INTEGER
// * The maximum exponent before overflow occurs.
// *
// * RMAX (output) DOUBLE PRECISION
// * The largest positive number for the machine, given by
// * BASE**EMAX * ( 1 - EPS ), where BASE is the floating point
// * value of BETA.
// *
// * Further Details
// * ===============
// *
// * The computation of EPS is based on a routine PARANOIA by
// * W. Kahan of the University of California at Berkeley.
// *
// * =====================================================================
// *
// * .. Local Scalars ..
// * ..
// * .. External Functions ..
// * ..
// * .. External Subroutines ..
// * ..
// * .. Intrinsic Functions ..
// INTRINSIC ABS, MAX, MIN;
// * ..
// * .. Save statement ..
// * ..
// * .. Data statements ..
// * ..
// * .. Executable Statements ..
// *
#endregion
#region Body
if (FIRST)
{
ZERO = 0;
ONE = 1;
TWO = 2;
// *
// * LBETA, LT, LRND, LEPS, LEMIN and LRMIN are the local values of
// * BETA, T, RND, EPS, EMIN and RMIN.
// *
// * Throughout this routine we use the function DLAMC3 to ensure
// * that relevant values are stored and not held in registers, or
// * are not affected by optimizers.
// *
// * DLAMC1 returns the parameters LBETA, LT, LRND and LIEEE1.
// *
this._dlamc1.Run(ref LBETA, ref LT, ref LRND, ref LIEEE1);
// *
// * Start to find EPS.
// *
B = LBETA;
A = Math.Pow(B, - LT);
LEPS = A;
// *
// * Try some tricks to see whether or not this is the correct EPS.
// *
B = TWO / 3;
HALF = ONE / 2;
SIXTH = this._dlamc3.Run(B, - HALF);
THIRD = this._dlamc3.Run(SIXTH, SIXTH);
B = (double)this._dlamc3.Run(THIRD, - HALF);
B = (double)this._dlamc3.Run(B, SIXTH);
B = Math.Abs(B);
if (B < LEPS) B = LEPS;
// *
LEPS = 1;
// *
// *+ WHILE( ( LEPS.GT.B ).AND.( B.GT.ZERO ) )LOOP
LABEL10:;
if ((LEPS > B) && (B > ZERO))
{
LEPS = B;
C = (double)this._dlamc3.Run(HALF * LEPS, (Math.Pow(TWO,5)) * (Math.Pow(LEPS,2)));
C = (double)this._dlamc3.Run(HALF, -C);
B = (double)this._dlamc3.Run(HALF, C);
C = (double)this._dlamc3.Run(HALF, -B);
B = (double)this._dlamc3.Run(HALF, C);
goto LABEL10;
}
// *+ END WHILE
// *
if (A < LEPS) LEPS = A;
// *
// * Computation of EPS complete.
// *
// * Now find EMIN. Let A = + or - 1, and + or - (1 + BASE**(-3)).
// * Keep dividing A by BETA until (gradual) underflow occurs. This
// * is detected when we cannot recover the previous A.
// *
RBASE = ONE / LBETA;
SMALL = ONE;
for (I = 1; I <= 3; I++)
{
SMALL = (double)this._dlamc3.Run(SMALL * RBASE, ZERO);
}
A = (double)this._dlamc3.Run(ONE, SMALL);
this._dlamc4.Run(ref NGPMIN, ONE, LBETA);
this._dlamc4.Run(ref NGNMIN, - ONE, LBETA);
this._dlamc4.Run(ref GPMIN, A, LBETA);
this._dlamc4.Run(ref GNMIN, - A, LBETA);
IEEE = false;
// *
if ((NGPMIN == NGNMIN) && (GPMIN == GNMIN))
{
if (NGPMIN == GPMIN)
{
LEMIN = NGPMIN;
// * ( Non twos-complement machines, no gradual underflow;
// * e.g., VAX )
}
else
{
if ((GPMIN - NGPMIN) == 3)
{
LEMIN = NGPMIN - 1 + LT;
IEEE = true;
// * ( Non twos-complement machines, with gradual underflow;
// * e.g., IEEE standard followers )
}
else
{
LEMIN = Math.Min(NGPMIN, GPMIN);
// * ( A guess; no known machine )
IWARN = true;
}
}
// *
}
else
{
if ((NGPMIN == GPMIN) && (NGNMIN == GNMIN))
{
if (Math.Abs(NGPMIN - NGNMIN) == 1)
{
LEMIN = Math.Max(NGPMIN, NGNMIN);
// * ( Twos-complement machines, no gradual underflow;
// * e.g., CYBER 205 )
}
else
{
LEMIN = Math.Min(NGPMIN, NGNMIN);
// * ( A guess; no known machine )
IWARN = true;
}
// *
}
else
{
if ((Math.Abs(NGPMIN - NGNMIN) == 1) && (GPMIN == GNMIN))
{
if ((GPMIN - Math.Min(NGPMIN, NGNMIN)) == 3)
{
LEMIN = Math.Max(NGPMIN, NGNMIN) - 1 + LT;
// * ( Twos-complement machines with gradual underflow;
// * no known machine )
}
else
{
LEMIN = Math.Min(NGPMIN, NGNMIN);
// * ( A guess; no known machine )
IWARN = true;
}
// *
}
else
{
LEMIN = Math.Min(NGPMIN, Math.Min(NGNMIN, Math.Min(GPMIN, GNMIN)));
// * ( A guess; no known machine )
IWARN = true;
}
}
}
FIRST = false;
// ***
// * Comment out this if block if EMIN is ok
if (IWARN)
{
FIRST = true;
//ERROR-ERROR WRITE( 6, FMT = 9999 )LEMIN;
}
// ***
// *
// * Assume IEEE arithmetic if we found denormalised numbers above,
// * or if arithmetic seems to round in the IEEE style, determined
// * in routine DLAMC1. A true IEEE machine should have both things
// * true; however, faulty machines may have one or the other.
// *
IEEE = IEEE || LIEEE1;
// *
// * Compute RMIN by successive division by BETA. We could compute
// * RMIN as BASE**( EMIN - 1 ), but some machines underflow during
// * this computation.
// *
LRMIN = 1;
for (I = 1; I <= 1 - LEMIN; I++)
{
LRMIN = this._dlamc3.Run(LRMIN * RBASE, ZERO);
}
// *
// * Finally, call DLAMC5 to compute EMAX and RMAX.
// *
this._dlamc5.Run(LBETA, LT, LEMIN, IEEE, ref LEMAX, ref LRMAX);
}
// *
BETA = LBETA;
T = LT;
RND = LRND;
EPS = LEPS;
EMIN = LEMIN;
RMIN = LRMIN;
EMAX = LEMAX;
RMAX = LRMAX;
// *
return;
// *
// *
// * End of DLAMC2
// *
#endregion
}
}
#endregion
#region The Class: DLAMC3
// *
// ************************************************************************
// *
/// <summary>
/// -- LAPACK auxiliary routine (version 3.1) --
/// Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
/// November 2006
/// Purpose
/// =======
///
/// DLAMC3 is intended to force A and B to be stored prior to doing
/// the addition of A and B , for use in situations where optimizers
/// might hold one of these in a register.
///
///</summary>
public class DLAMC3