| 1 |
|
| #include <math.h> /* Needed for fabs() and sqrt() */ |
| 2 |
|
| #include "blas.h" |
| 3 |
|
| |
| 4 |
|
| #ifdef __cplusplus |
| 5 |
|
| extern "C" { |
| 6 |
|
| #endif |
| 7 |
|
| |
| 8 |
215 |
| double dnrm2_(int *n, double *x, int *incx) |
| 9 |
|
| { |
| 10 |
|
| long int ix, nn, iincx; |
| 11 |
|
| double norm, scale, absxi, ssq, temp; |
| 12 |
|
| |
| 13 |
|
| /* DNRM2 returns the euclidean norm of a vector via the function |
| 14 |
|
| name, so that |
| 15 |
|
| |
| 16 |
|
| DNRM2 := sqrt( x'*x ) |
| 17 |
|
| |
| 18 |
|
| -- This version written on 25-October-1982. |
| 19 |
|
| Modified on 14-October-1993 to inline the call to SLASSQ. |
| 20 |
|
| Sven Hammarling, Nag Ltd. */ |
| 21 |
|
| |
| 22 |
|
| /* Dereference inputs */ |
| 23 |
215 |
| nn = *n; |
| 24 |
215 |
| iincx = *incx; |
| 25 |
|
| |
| 26 |
215 |
▶ | if( nn > 0 && iincx > 0 ) |
Branch: 2 branches
| Branch | True | False | Total |
| if( nn > 0 && iincx > 0 ) |
215 |
0 |
215 |
| if( nn > 0 && iincx > 0 ) |
215 |
0 |
215 |
|
| 27 |
|
| { |
| 28 |
215 |
▶ | if (nn == 1) |
Branch: 1 branch
| Branch | True | False | Total |
| if (nn == 1) |
0 |
215 |
215 |
|
| 29 |
|
| { |
| 30 |
0 |
| norm = fabs(x[0]); |
| 31 |
|
| } |
| 32 |
|
| else |
| 33 |
|
| { |
| 34 |
215 |
| scale = 0.0; |
| 35 |
215 |
| ssq = 1.0; |
| 36 |
|
| |
| 37 |
|
| /* The following loop is equivalent to this call to the LAPACK |
| 38 |
|
| auxiliary routine: CALL SLASSQ( N, X, INCX, SCALE, SSQ ) */ |
| 39 |
|
| |
| 40 |
3010 |
▶ | for (ix=(nn-1)*iincx; ix>=0; ix-=iincx) |
Branch: 1 branch
| Branch | True | False | Total |
| for (ix=(nn-1)*iincx; ix>=0; ix-=iincx) |
2795 |
215 |
3010 |
|
| 41 |
|
| { |
| 42 |
2795 |
▶ | if (x[ix] != 0.0) |
Branch: 1 branch
| Branch | True | False | Total |
| if (x[ix] != 0.0) |
2795 |
0 |
2795 |
|
| 43 |
|
| { |
| 44 |
2795 |
| absxi = fabs(x[ix]); |
| 45 |
2795 |
▶ | if (scale < absxi) |
Branch: 1 branch
| Branch | True | False | Total |
| if (scale < absxi) |
390 |
2405 |
2795 |
|
| 46 |
|
| { |
| 47 |
390 |
| temp = scale / absxi; |
| 48 |
390 |
| ssq = ssq * (temp * temp) + 1.0; |
| 49 |
390 |
| scale = absxi; |
| 50 |
|
| } |
| 51 |
|
| else |
| 52 |
|
| { |
| 53 |
2405 |
| temp = absxi / scale; |
| 54 |
2405 |
| ssq += temp * temp; |
| 55 |
|
| } |
| 56 |
|
| } |
| 57 |
|
| } |
| 58 |
215 |
| norm = scale * sqrt(ssq); |
| 59 |
|
| } |
| 60 |
|
| } |
| 61 |
|
| else |
| 62 |
0 |
| norm = 0.0; |
| 63 |
|
| |
| 64 |
215 |
| return norm; |
| 65 |
|
| |
| 66 |
|
| } /* dnrm2_ */ |
| 67 |
|
| |
| 68 |
|
| #ifdef __cplusplus |
| 69 |
|
| } |
| 70 |
|
| #endif |