template_lapack_lamch.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #ifndef TEMPLATE_LAPACK_LAMCH_HEADER
00036 #define TEMPLATE_LAPACK_LAMCH_HEADER
00037
00038
00039 #include <stdio.h>
00040 #include <iostream>
00041 #include <limits>
00042
00043
00044
00045 template<class Treal>
00046 Treal template_lapack_d_sign(const Treal *a, const Treal *b)
00047 {
00048 Treal x;
00049 x = (*a >= 0 ? *a : - *a);
00050 return( *b >= 0 ? x : -x);
00051 }
00052
00053
00054
00055 #define log10e 0.43429448190325182765
00056 template<class Treal>
00057 Treal template_blas_lg10(Treal *x)
00058 {
00059 return( log10e * template_blas_log(*x) );
00060 }
00061
00062
00063
00064
00065
00066
00067
00068
00069 template<class Treal>
00070 int template_lapack_lassq(const integer *n, const Treal *x, const integer *incx,
00071 Treal *scale, Treal *sumsq)
00072 {
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125 integer i__1, i__2;
00126 Treal d__1;
00127
00128 Treal absxi;
00129 integer ix;
00130
00131 --x;
00132
00133
00134 if (*n > 0) {
00135 i__1 = (*n - 1) * *incx + 1;
00136 i__2 = *incx;
00137 for (ix = 1; i__2 < 0 ? ix >= i__1 : ix <= i__1; ix += i__2) {
00138 if (x[ix] != 0.) {
00139 absxi = (d__1 = x[ix], absMACRO(d__1));
00140 if (*scale < absxi) {
00141
00142 d__1 = *scale / absxi;
00143 *sumsq = *sumsq * (d__1 * d__1) + 1;
00144 *scale = absxi;
00145 } else {
00146
00147 d__1 = absxi / *scale;
00148 *sumsq += d__1 * d__1;
00149 }
00150 }
00151
00152 }
00153 }
00154 return 0;
00155
00156
00157
00158 }
00159
00160
00161
00162
00163
00164 template<class Treal>
00165 double template_lapack_pow_di(Treal *ap, integer *bp)
00166 {
00167 Treal pow, x;
00168 integer n;
00169 unsigned long u;
00170
00171 pow = 1;
00172 x = *ap;
00173 n = *bp;
00174
00175 if(n != 0)
00176 {
00177 if(n < 0)
00178 {
00179 n = -n;
00180 x = 1/x;
00181 }
00182 for(u = n; ; )
00183 {
00184 if(u & 01)
00185 pow *= x;
00186 if(u >>= 1)
00187 x *= x;
00188 else
00189 break;
00190 }
00191 }
00192 return(pow);
00193 }
00194
00195
00196
00197
00198 template<class Treal>
00199 Treal template_lapack_lamch(const char *cmach, Treal dummyReal)
00200 {
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245 Treal rmach, ret_val;
00246
00247
00248 rmach = 0;
00249 if (template_blas_lsame(cmach, "E")) {
00250 rmach = std::numeric_limits<Treal>::epsilon();
00251 } else if (template_blas_lsame(cmach, "S")) {
00252 rmach = std::numeric_limits<Treal>::min();
00253 } else if (template_blas_lsame(cmach, "B")) {
00254
00255 rmach = 2.0;
00256 } else if (template_blas_lsame(cmach, "P")) {
00257
00258 rmach = 2.0 * std::numeric_limits<Treal>::epsilon();
00259 } else if (template_blas_lsame(cmach, "N")) {
00260 std::cout << "ERROR in template_lapack_lamch: case N not implemented." << std::endl;
00261 throw "ERROR in template_lapack_lamch: case N not implemented.";
00262 } else if (template_blas_lsame(cmach, "R")) {
00263 std::cout << "ERROR in template_lapack_lamch: case R not implemented." << std::endl;
00264 throw "ERROR in template_lapack_lamch: case R not implemented.";
00265 } else if (template_blas_lsame(cmach, "M")) {
00266 std::cout << "ERROR in template_lapack_lamch: case M not implemented." << std::endl;
00267 throw "ERROR in template_lapack_lamch: case M not implemented.";
00268 } else if (template_blas_lsame(cmach, "U")) {
00269 std::cout << "ERROR in template_lapack_lamch: case U not implemented." << std::endl;
00270 throw "ERROR in template_lapack_lamch: case U not implemented.";
00271 } else if (template_blas_lsame(cmach, "L")) {
00272 std::cout << "ERROR in template_lapack_lamch: case L not implemented." << std::endl;
00273 throw "ERROR in template_lapack_lamch: case L not implemented.";
00274 } else if (template_blas_lsame(cmach, "O")) {
00275 std::cout << "ERROR in template_lapack_lamch: case O not implemented." << std::endl;
00276 throw "ERROR in template_lapack_lamch: case O not implemented.";
00277 }
00278
00279 ret_val = rmach;
00280 return ret_val;
00281
00282
00283
00284 }
00285
00286
00287
00288 #endif