realmax + 1 infinity?
조회 수: 8 (최근 30일)
이전 댓글 표시
Hello!
How come is realmax + 1 not inifity when typed into command window?
Thank you.
댓글 수: 0
채택된 답변
Stephen23
2019년 4월 11일
편집: Stephen23
2019년 4월 11일
Because the value 1 is nowhere near the smallest value that can be added to realmax to create a new value. You would need to add a value that is more than half the difference between representable values around the magnitude of realmax. To get that value try using eps:
>> val = eps(realmax) % much bigger than 1.
val = 1.9958e+292
>> realmax + val/2
ans = Inf
>> realmax + val/3
ans = 1.7977e+308
This is exactly the same as if you add 1e-300 to 10: the answer is 10, because 1e-300 is nowhere near the difference in representable values around the magnitude 10, so adding 1e-300 makes absolutely no difference to the 10.
추가 답변 (1개)
Steven Lord
2019년 4월 11일
If you handed Bill Gates or Scrooge McDuck a $1 bill, it doesn't change what he'll report for his net worth. A single dollar is negligible compared to how much money he has already.
Similarly, if you add 1 to realmax it doesn't change the value since 1 is negligible compared to realmax. If you want to know how much you'd need to add to realmax to make it not negligible, take a look at the eps function.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Numeric Types에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!