4 stars based on
The edition of Hour of Code includes a new blocks-based, Star Wars themed coding lesson. In one of the exercises — a simple sprite-based game — you are asked to code a loop that adds to your score every time R2-D2 encounters a Rebel Pilot.
Furthermore, every time you add this to the score, rounding may occur double-precision floating-point has a fixed precision of 53 bits. One strategy for printing double-precision floating-point numbers is to round them to 17 significant digits; that way, they are guaranteed to round-trip convert back to binary account alifelong same double-precision number. But that is not what is done here; that would make the scores 0. Another strategy for printing floating-point numbers is to binary account alifelong them to the shortest number that will round-trip.
In this case, that would be 0. You can show this binary account alifelong using my decimal to floating-point converter. After the second and third encounters, it displayed Infinity — also as expected. The maximum value of a double-precision number is options trading account uk online binary account alifelong.
This is not so much an anomaly as a demonstration of the limits and properties of floating-point. In other exercises, where you can run up a higher score, you can see similar printing anomalies using the 0. The next one for which this happens is after the eighth score; it prints the digit value 0.
I suppose you could prevent entering floating-point numbers — but then where would the life lesson be? Do you remember the confusion caused by the fact that the SP FP value nearest to pi is bigger than the true value of pi, but the nearest DP FP value is smaller?? Your email address will not be published. Skip to content The edition of Hour of Code includes a new blocks-based, Star Wars themed coding lesson.
My take on puzzle 9 in the Star Wars Hour of Code lesson click image to enlarge Here specifically is the code block: My code for puzzle 9. Get articles binary account alifelong e-mail. Leave a Reply Cancel reply Your email address will not be published.
Binary Images From Silicon Valley. My Fretlight Guitar Binary Clock: