Skip to content

Commit 7f4b611

Browse files
committed
fix a few footnotes
1 parent 8f58e4d commit 7f4b611

File tree

2 files changed

+36
-39
lines changed

2 files changed

+36
-39
lines changed

10_binary_counter.html

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -461,9 +461,7 @@ <h3>Counter storage</h3>
461461
<p>I think it is very beautiful.
462462
We could compete with Steve Jobs for elegance of our design<sup id="fnref:11"><a href="#fn:11" rel="footnote">11</a></sup>.</p>
463463

464-
<p><strong>Exercise:</strong> In <a href="https://en.wikipedia.org/wiki/Numerical_analysis">numerical analysis</a>,
465-
whenever you sum up large number you don&rsquo;t really want to
466-
add small quantities to big quantities.
464+
<p><strong>Exercise:</strong> In numerical analysis, whenever you sum up large numbers you don&rsquo;t really want to add small quantities to big quantities.
467465
Bad things happen to the errors<sup id="fnref:12"><a href="#fn:12" rel="footnote">12</a></sup>.
468466
Use this code to write a function which sums arrays of <code>double</code>.</p>
469467

@@ -576,7 +574,7 @@ <h2>Code</h2>
576574
* * *
577575
</code></pre>
578576

579-
<p>Or as <a href="https://en.wikipedia.org/wiki/Peter_Gustav_Lejeune_Dirichlet)">Dirichlet</a> put it: &ldquo;Whether you arrange soldiers in rows or columns, you still have the same number of soldiers&rdquo;.</p>
577+
<p>Or as <a href="https://en.wikipedia.org/wiki/Peter_Gustav_Lejeune_Dirichlet">Dirichlet</a> put it: &ldquo;Whether you arrange soldiers in rows or columns, you still have the same number of soldiers&rdquo;.</p>
580578

581579
<p>An example of an operation which is not commutative is string concatenation.</p>
582580

@@ -640,22 +638,23 @@ <h2>Code</h2>
640638
<a href="https://signalvnoise.com/posts/2710-designed-by-apple-in-california">Designed in Cupertino</a>, assembled in China.
641639
So let&rsquo;s try to assemble our machine in Palo Alto.<a href="#fnref:11" rev="footnote">&#8617;</a></li>
642640
<li id="fn:12">
643-
<p>Floating point arithmetic can involve many tricky details,
644-
but the basic issue Alex is referring to is straightforward.
645-
We often use scientific notation to write larger numbers as a decimal to a power,
646-
when they would otherwise be very long to write out.
647-
For example <code>1,450,000,000 == 1.45 * 10^9</code>.
648-
However, adding two numbers in this form can only be done accurately if they are roughly of the same power,
649-
otherwise the larger of the two is still the best representation:
650-
<code>1.45 * 10^9 + 1 ~= 1.45 * 10^9</code>.</p>
651-
652-
<p><code>float</code> and <code>double</code> have very similar limitations, and give the best results
653-
when operations are applied to values of similar magnitudes.
654-
To try for yourself, compare these two expressions in a program:</p>
655-
656-
<pre><code>double x = (152500.0 * 5000.0);
657-
double y = (152500.0 * 5000.0) + 0.01;
658-
</code></pre><a href="#fnref:12" rev="footnote">&#8617;</a></li>
641+
<p>Alex is referring to the following issue:
642+
When floating point numbers become very large they can no longer represent small nearby increments.
643+
So if many small numbers are accumulated in order, the sum may grow large enough to ignore the contribution of any particular element.
644+
To see for yourself, observe that:</p>
645+
646+
<pre><code>double x = 1.45 * pow(2, 60);
647+
assert(x == x + 1.0);
648+
</code></pre>
649+
650+
<p>This is because floats are represented as a base and exponent, and the magnitude of the exponent constrains the precision.</p>
651+
652+
<p>If we forget about computers, and think about science or engineeing, it&rsquo;s natural to consider:</p>
653+
654+
<pre><code>1.45 * 2^60 + 1 ~= 1.45 * 2^60
655+
</code></pre>
656+
657+
<p>because the <code>1</code> is not very significant to the overall magnitutde.</p><a href="#fnref:12" rev="footnote">&#8617;</a></li>
659658
</ol>
660659
</div>
661660

10_binary_counter.md

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ we're just rebalancing parentheses[^min-not-commutative].
271271

272272
"Hello, " + "World!" != "World!" + "Hello, "
273273

274-
[dirichlet]: https://en.wikipedia.org/wiki/Peter_Gustav_Lejeune_Dirichlet)
274+
[dirichlet]: https://en.wikipedia.org/wiki/Peter_Gustav_Lejeune_Dirichlet
275275

276276
## Binary counting and reduction
277277

@@ -405,24 +405,24 @@ we can make this counter and it will work for us.
405405

406406
An **overflow** is when the last adder has a non-zero carry.
407407

408-
[^errors]: Floating point arithmetic can involve many tricky details,
409-
but the basic issue Alex is referring to is straightforward.
410-
We often use scientific notation to write larger numbers as a decimal to a power,
411-
when they would otherwise be very long to write out.
412-
For example `1,450,000,000 == 1.45 * 10^9`.
413-
However, adding two numbers in this form can only be done accurately if they are roughly of the same power,
414-
otherwise the larger of the two is still the best representation:
415-
`1.45 * 10^9 + 1 ~= 1.45 * 10^9`.
408+
[^floating-point-error]: Alex is referring to the following issue:
409+
When floating point numbers become very large they can no longer represent small nearby increments.
410+
So if many small numbers are accumulated in order, the sum may grow large enough to ignore the contribution of any particular element.
411+
To see for yourself, observe that:
416412

417-
`float` and `double` have very similar limitations, and give the best results
418-
when operations are applied to values of similar magnitudes.
419-
To try for yourself, compare these two expressions in a program:
413+
double x = 1.45 * pow(2, 60);
414+
assert(x == x + 1.0);
420415

421-
double x = (152500.0 * 5000.0);
422-
double y = (152500.0 * 5000.0) + 0.01;
416+
This is because floats are represented as a base and exponent, and the magnitude of the exponent constrains the precision.
417+
418+
If we forget about computers, and think about science or engineeing, it's natural to consider:
419+
420+
1.45 * 2^60 + 1 ~= 1.45 * 2^60
421+
422+
because the `1` is not very significant to the overall magnitutde.
423+
423424

424425
[adder]: https://en.wikipedia.org/wiki/Adder_(electronics)
425-
[numerics]: https://en.wikipedia.org/wiki/Numerical_analysis
426426
[merge-sort]: https://en.wikipedia.org/wiki/Merge_sort
427427
[binomial]: https://en.wikipedia.org/wiki/Binomial_heap
428428

@@ -565,10 +565,8 @@ for members, then you overwrite all the work with an assignment.
565565
I think it is very beautiful.
566566
We could compete with Steve Jobs for elegance of our design[^alex-apple-joke].
567567

568-
**Exercise:** In [numerical analysis][numerics],
569-
whenever you sum up large number you don't really want to
570-
add small quantities to big quantities.
571-
Bad things happen to the errors[^errors].
568+
**Exercise:** In numerical analysis, whenever you sum up large numbers you don't really want to add small quantities to big quantities.
569+
Bad things happen to the errors[^floating-point-error].
572570
Use this code to write a function which sums arrays of `double`.
573571

574572
**Exercise:** Rewrite `min_element` using this code (just `min_element`, don't worry about second best).

0 commit comments

Comments
 (0)