Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Matlab! HELP! Infinite Loop.

  1. Jun 30, 2010 #1
    I can't seem to figure out this question:

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

    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?

  2. jcsd
  3. Jun 30, 2010 #2


    User Avatar
    Science Advisor
    Homework Helper

    What if N happens to become equal to 253 - 1?
  4. Jun 30, 2010 #3
    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!
  5. Jun 30, 2010 #4
    when do you expect the code to get out of the while loop?

    which number satisfies your constraint?
  6. Jun 30, 2010 #5


    Staff: Mentor

    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.
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Similar Threads - Matlab HELP Infinite Date
Matlab MATLab: Not enough inputs for nlinfit Nov 16, 2017
Matlab Help needed to fix a matlab code Nov 8, 2017
New to Matlab, help with vectors Feb 20, 2016
Need help with integral Dec 23, 2015
Matlab infinite loop help Feb 18, 2011