Why 999^999-999^999 is NaN?

조회 수: 1 (최근 30일)
Fahmy Shandy
Fahmy Shandy 2019년 12월 18일
답변: David Goodmanson 2019년 12월 18일
The reason i'm asking this because of i'm working on Adam-Bashforth with 20 steps. It has a big number. Maybe has 20 digits? I don't know, i'm not count the digit.
But as you know, the ABM use the constant to evaluate the ODE with initial condition. And it has alternating form like plus and minus.
And when i use the ABM-7, it's fine, there is no calculation involving Inf and NaN. But, when i use ABM-20 which is has a big constant in each , it turns out in iteration 38th, it changed into,*Inf*. And as i said before, the formula in ABM has alternating plus and minus. And it's possible to adding and substracting "Inf" on it.
And we know, if we type Inf-Inf in command window, it will be NaN isn't it?
Why it's happen?
And i'm sure there is no mistake about my formula. I derive the formula by myself with maple, and checked it the first term to make ABM-8, and it's match with my book, so i'm sure there is no mistake on my formula.
My main question is :
If we dealing with a formula or a function, that has very large constant, is it possible it gives us NaN as the result?
Thanks

답변 (2개)

Walter Roberson
Walter Roberson 2019년 12월 18일
If we dealing with a formula or a function, that has very large constant, is it possible it gives us NaN as the result
Yes, certainly.
>> log10(999)*999
ans =
2996.56592273776
That is, 999^999 would be 10^2996.56592273776 which far exceeds 10^308.254715559917 that is the maximum value that can be stored in IEEE double precision.
If you cannot work with log space, then you have a few options:

David Goodmanson
David Goodmanson 2019년 12월 18일
HI Fahmy,
>> realmax
ans = 1.7977e+308
That's the largest floating point number in Mallab, which uses IEEE754 64 bit double precision. For anything larger,
>> 1e309
ans = Inf
and of course inf - inf will give NaN.

카테고리

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

제품


릴리스

R14SP1

Community Treasure Hunt

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

Start Hunting!

Translated by