필터 지우기
필터 지우기

what is the significance of 3.3121686421112381E-170 ?

조회 수: 4 (최근 30일)
Adam Wozniak
Adam Wozniak 2019년 3월 19일
편집: Mike Hosea 2019년 3월 20일
using matlab coder, the following is produced. real_T is a double precision floating point.
What is the significance of 3.3121686421112381E-170 ? Why was this specific number chosen, and not some other number?
/* Function for MATLAB Function: '<S1>/MATLAB Function' */
static real_T MyThing_norm(const real_T x[3])
{
real_T y;
real_T scale;
real_T absxk;
real_T t;
scale = 3.3121686421112381E-170;
absxk = fabs(x[0]);
if (absxk > 3.3121686421112381E-170) {
y = 1.0;
scale = absxk;
} else {
t = absxk / 3.3121686421112381E-170;
y = t * t;
}
absxk = fabs(x[1]);
if (absxk > scale) {
t = scale / absxk;
y = y * t * t + 1.0;
scale = absxk;
} else {
t = absxk / scale;
y += t * t;
}
absxk = fabs(x[2]);
if (absxk > scale) {
t = scale / absxk;
y = y * t * t + 1.0;
scale = absxk;
} else {
t = absxk / scale;
y += t * t;
}
return scale * sqrt(y);
}
  댓글 수: 3
Adam Wozniak
Adam Wozniak 2019년 3월 19일
I believe it is just finding the magnitude (or norm) of the vector.
return sqrt(x[0]*x[0]+x[1]*x[1]+x[2]*x[2]);
Walter Roberson
Walter Roberson 2019년 3월 19일
It looks like it is doing some kind of internal rescaling to prevent underflow. It just isn't obvious to me why 1E-170 is the boundary point, rather than sqrt(realmin) .

댓글을 달려면 로그인하십시오.

채택된 답변

Mike Hosea
Mike Hosea 2019년 3월 20일
편집: Mike Hosea 2019년 3월 20일
Walter is on the right track.
What we see above is essentually a loop-unrolled version of the reference BLAS algorithm of DNRM2. The algorithm, having much longer vectors in mind, was designed to avoid unnecessary overflow and underflow while still making just one pass through the data. Unfortunately, the reference BLAS implementation asks whether abs(x(k)) ~= 0 in the loop. Floating point equality/inequality comparisons are not welcome when the generated code must adhere, say, to the MISRA standard, and calls to NORM are quite common, so we considered how to modify the algorithm without the ~= 0 comparisons.
The number in question is the largest initial value of the scale variable that guarantees that (abs(x(k))/scale)^2 does not underflow and is not denormal for any value of abs(x(k)) > 0, i.e. (abs(x(k))/scale)^2 >= realmin. Hence, the initial value of scale is eps*sqrt(realmin).

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 MATLAB Coder에 대해 자세히 알아보기

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by