Lesson 6. Real numbers

After reading lesson 6, you’ll be able to

  • Use two types of real numbers
  • Understand the memory-versus-precision trade-off
  • Work around rounding errors in your piggy bank

Computers store and manipulate real numbers like 3.14159 using the IEEE-754 floating-point standard. Floating-point numbers can be very large or incredibly small: think galaxies and atoms. With such versatility, programming languages like JavaScript and Lua get by using floating-point numbers exclusively. Computers also support integers for whole numbers, the subject of the next lesson.

Consider this

Imagine a carnival game with three cups. The nearest cup is worth $0.10 to $1.00, the next is worth $1 to $10, and the farthest cup is worth ...

Get Get Programming with Go now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.