Skip to content

Commit f42ce70

Browse files
authored
Merge pull request #5116 from martin-frbg/issue5110
Handle INCX=0 in ?NRM2
2 parents c54f541 + 7478c10 commit f42ce70

File tree

1 file changed

+63
-1
lines changed

1 file changed

+63
-1
lines changed

interface/nrm2.c

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,37 @@ FLOATRET NAME(blasint *N, FLOAT *x, blasint *INCX){
6161
#else
6262
return fabsf(x[0]);
6363
#endif
64+
#endif
65+
66+
if (incx == 0)
67+
#ifndef COMPLEX
68+
#ifdef DOUBLE
69+
return (sqrt((double)n)*fabs(x[0]));
70+
#else
71+
return (sqrt((float)n)*fabsf(x[0]));
72+
#endif
73+
#else
74+
#ifdef DOUBLE
75+
{
76+
double fr=fabs(x[0]);
77+
double fi=fabs(x[1]);
78+
double fmin=MIN(fr,fi);
79+
double fmax=MAX(fr,fi);
80+
if (fmax==0.) return(fmax);
81+
if (fmax==fmin) return(sqrt((double)n)*sqrt(2.)*fmax);
82+
return (sqrt((double)n) * fmax * sqrt (1. + (fmin/fmax)*(fmin/fmax)));
83+
}
84+
#else
85+
{
86+
float fr=fabs(x[0]);
87+
float fi=fabs(x[1]);
88+
float fmin=MIN(fr,fi);
89+
float fmax=MAX(fr,fi);
90+
if (fmax==0.) return(fmax);
91+
if (fmax==fmin) return(sqrt((float)n)*sqrt(2.)*fmax);
92+
return (sqrt((float)n) * fmax * sqrt (1. + (fmin/fmax)*(fmin/fmax)));
93+
}
94+
#endif
6495
#endif
6596

6697
if (incx < 0)
@@ -97,13 +128,44 @@ FLOAT CNAME(blasint n, FLOAT *x, blasint incx){
97128

98129
if (n <= 0) return 0.;
99130

100-
#ifndef COMPLEX
131+
#ifndef COMPLEX
101132
if (n == 1)
102133
#ifdef DOUBLE
103134
return fabs(x[0]);
104135
#else
105136
return fabsf(x[0]);
106137
#endif
138+
#endif
139+
140+
if (incx == 0)
141+
#ifndef COMPLEX
142+
#ifdef DOUBLE
143+
return (sqrt((double)n)*fabs(x[0]));
144+
#else
145+
return (sqrt((float)n)*fabsf(x[0]));
146+
#endif
147+
#else
148+
#ifdef DOUBLE
149+
{
150+
double fr=fabs(x[0]);
151+
double fi=fabs(x[1]);
152+
double fmin=MIN(fr,fi);
153+
double fmax=MAX(fr,fi);
154+
if (fmax==0.) return(fmax);
155+
if (fmax==fmin) return(sqrt((double)n)*sqrt(2.)*fmax);
156+
return (sqrt((double)n) * fmax * sqrt (1. + (fmin/fmax)*(fmin/fmax)));
157+
}
158+
#else
159+
{
160+
float fr=fabs(x[0]);
161+
float fi=fabs(x[1]);
162+
float fmin=MIN(fr,fi);
163+
float fmax=MAX(fr,fi);
164+
if (fmax==0.) return(fmax);
165+
if (fmax==fmin) return(sqrt((float)n)*sqrt(2.)*fmax);
166+
return (sqrt((float)n) * fmax * sqrt (1. + (fmin/fmax)*(fmin/fmax)));
167+
}
168+
#endif
107169
#endif
108170

109171
if (incx < 0)

0 commit comments

Comments
 (0)