My CALCULATIONs involves ranage upto 1E-680, and due to underflow matlab give result as zero.
For the calculation which involves number up to the range 1E-300, Matlab returns the expected answers.
How to handle this?
To put in other words how to USE extended double precision IEEE standard for MATALB?

回答 (1 件)

John D'Errico
John D'Errico 2020 年 4 月 25 日

0 投票

Answer, you can't. That is, if you want to use an extended precision IEEE floating point number in MATLAB, you can't. What can you do?
  1. Use the symbolic toolbox, which can handle longer precision numbers.
  2. Use my HPF toolbox, which can handle whatever precision you want. (Find HPF on the File Exchange for free download.)
  3. Use logs.
  4. You could write the calls in C or some other language where you can do your computations in some other class. But if you can do the work in that other language, why are you asking here?
That is, most of the time when you have these underflows, you really needed to do your computations using logs anyway. That makes any issue with tiny numbers go away, they just turn into negative numbers. Done.
If you absolutely think you really desperately need to use those high precision numbers then use alternatives 1 or 2. You will find your code becomes slow. But that is the cost.

4 件のコメント

Chetan Kumar Dabhi
Chetan Kumar Dabhi 2020 年 4 月 25 日
Is it possible to represent the HPF answers to the exponent format?
for example HPF output is = 0.00003567, and can it be converted to 3.567E-5?
Chetan Kumar Dabhi
Chetan Kumar Dabhi 2020 年 4 月 25 日
It seems "vpa" is also kind of same function....
John D'Errico
John D'Errico 2020 年 4 月 25 日
HPF will automatically use a scientific notation for numbers that will have many leading zeros otherwise. Thus, we see this:
X = hpf('3.567e-50',20)
X =
3.567e-50
HPF decided it was a good idea to use scientific notation for that number.
But there is no direct way to toggle scientific notation to be on all the time. It would not be difficult to write a scientific notation utility though.
function scidisp(X)
% automatically formats a scalar HPF number in scientific form.
if ~isa(X,'hpf')
error('scidisp only applies to HPF input')
end
Xsci = char(mantissa(X) + '0');
% insert a decimal point
Xsci = [Xsci(1),'.',Xsci(2:end)];
% trash trailing zeros in the mantissa.
zind = find(Xsci ~= '0',1,'last') + 1;
zind = max(zind,4);
if ~isempty(zind) && (zind < numel(Xsci))
Xsci(zind:end) = [];
end
% the sign bit?
if X.Sign == -1
Xsci = ['-',Xsci];
end
% append an exponent
Xsci = [Xsci,'e',num2str(X.Exponent-1)];
disp(Xsci)
end
That would probably work, though a bit of a kludge.
>> X = hpf('0.1',20)
X =
0.1
>> scidisp(X)
1.0e-1
>> X = hpf('0.00003567',20)
X =
0.00003567
>> scidisp(X)
3.567e-5
Chetan Kumar Dabhi
Chetan Kumar Dabhi 2020 年 4 月 26 日
Thank You John

サインインしてコメントする。

カテゴリ

タグ

質問済み:

2020 年 4 月 25 日

コメント済み:

2020 年 4 月 26 日

Community Treasure Hunt

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

Start Hunting!

Translated by