Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

I gave a more thorough explanation of this in Re: shocking imprecision. But the essential component is that we tend to think nothing of expressing 1/3rd as 0.33 in base 10, and casually understand out of habit that 0.33 + 0.33 + 0.33 is strictly 0.99, but implicitly 1 when dealing with decimal representations of fractions. However we are not as accustomed to dealing with binary fractional arithmetic.

In base 10, any fraction that can be expressed as k/((2^n)*(5^m)) will have a terminating expansion, and any that cannot be expressed as such will not. In Base 2, the number must be able to be expressed as k/2^n to have a terminating expansion, and any that cannot be expressed as such will not terminate, meaning it cannot be expressed in a finite number of bits.

Let's look at 0.01: 0.01 is approximately 1000/(2**16) or 1000/(2**17). Both are terrible approximations. Closer would be 10000/(2**20). But that's still a pretty poor approximation. And your calculation is relying on exactness, not approximations.


Dave


In reply to Re: While loop with addition goes weird by davido
in thread While loop with addition goes weird by chiel

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (3)
As of 2024-04-19 17:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found