Matlab Infinite Loop: Understanding N < N+1 and Double Precision Variables"

  • Context: MATLAB 
  • Thread starter Thread starter darthxepher
  • Start date Start date
  • Tags Tags
    Infinite Loop Matlab
Click For Summary

Discussion Overview

The discussion revolves around a MATLAB code snippet that involves a while loop comparing a variable N to N + 1, specifically focusing on whether this will result in an infinite loop when using IEEE double precision variables. Participants are exploring the implications of double precision and its effects on numerical comparisons in programming.

Discussion Character

  • Exploratory
  • Technical explanation
  • Debate/contested

Main Points Raised

  • One participant, Darthxepher, suggests that the code will result in an infinite loop because N is always compared to a value that is theoretically one unit greater than itself.
  • Another participant questions the scenario where N might equal 253 - 1, implying a specific case that could affect the loop's behavior.
  • A participant expresses confusion regarding double precision and the IEEE rules, indicating a need for clarification on these concepts.
  • Another participant asks when the code is expected to exit the while loop and what number would satisfy the comparison constraint.
  • A repeated post by Darthxepher elaborates on the characteristics of IEEE double precision, noting that when N approaches the largest representable value, adding 1 may not yield a different result due to the limitations of floating-point representation.

Areas of Agreement / Disagreement

Participants exhibit uncertainty regarding the behavior of the code, with some agreeing on the potential for an infinite loop while others raise specific scenarios and questions that introduce ambiguity. No consensus is reached on the outcome of the loop.

Contextual Notes

Participants highlight the limitations of IEEE double precision, including the smallest and largest representable values, but do not resolve how these limitations specifically affect the loop's execution in this context.

darthxepher
Messages
56
Reaction score
0
I can't seem to figure out this question:

N = 1;
while N < N + 1
N = N*10
end

All variables are IEEE double precision. Will the code above result in an infinite loop?

I believe this will be a infinite loop because the value N is always going to be compared to a value 1 unit greater than itself, but what does that its double precision have to do with anything?

Thanks,
Darthxepher
 
Physics news on Phys.org
What if N happens to become equal to 253 - 1?
 
I am not sure what you mean by that. I am having a big misunderstanding with the concept of double precision and the IEEE rules. Please explain. I must understand!
 
when do you expect the code to get out of the while loop?

which number satisfies your constraint?
 
darthxepher said:
I can't seem to figure out this question:

N = 1;
while N < N + 1
N = N*10
end

All variables are IEEE double precision. Will the code above result in an infinite loop?

I believe this will be a infinite loop because the value N is always going to be compared to a value 1 unit greater than itself, but what does that its double precision have to do with anything?
Numbers that follow the IEEE specifications are stored in specific amounts of memory, which means that there is a smallest possible value and a largest possible value. When N is at or near the largest possible value, and you add 1 to it, you don't get the next larger value. "IEEE double precision" refers to the IEEE 754 standard for floating point arithmetic. Here's a link to a wiki article on it - http://en.wikipedia.org/wiki/IEEE_754.
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 4 ·
Replies
4
Views
10K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 7 ·
Replies
7
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K