Prevent over- or underflow
I am calling gges and I want to get the eigenvalues. In the Application Notes I read this di开发者_运维技巧sclaimer:
The quotients alphar(j)/beta(j) and alphai(j)/beta(j) may easily over- or underflow, and beta(j) may even be zero. Thus, you should avoid simply computing the ratio. However, alphar and alphai will be always less than and usually comparable with norm(A) in magnitude, and beta always less than and usually comparable with norm(B).
I want to prevent over- or underflow and stop the program with an error:
do i=1,N
if (sometest(alphar(i), beta(i)) then
stop 'Eigenvalues over- or underflow!'
endif
Lambda(i) = alphar(i)/beta(i)
enddo
Thanks in advance
Overflow would mean, that the result is larger then huge, thus sometest could be:
abs(alphar(i)) > abs(beta(i))*huge(alphar(i))
For the underflow the result would be smaller than tiny, thus sometest could be:
abs(alphar(i)) < abs(beta(i))*tiny(alphar(i))
huge and tiny are intrinsic functions.
Edit: Actually on second thought the testing for overflow might not be so good, as the multiplication itself leads to an overflow if abs(beta(i)) is larger than 1. Thus you need to capture this. You could do the overflow test only, if beta is smaller than 1, and the underflow test only if it smaller than 1.
精彩评论