
To make matters worse, it’s often impossible to exactly represent numbers with terminating decimal expansion in binary! Numbers with infinite decimal expansions cause rounding errors when stored as a floating-point data type in computer memory, which itself is finite. Regardless of their decimal expansion, rational numbers such as the number representing one-third always look elegant and compact in the fractional notation.

The repeated digits are commonly denoted with an ellipsis (0.33333…) in the decimal notation. However, some can have an infinite recurring decimal expansion with one or more digits repeated over a period. On the other hand, most rational numbers have a terminating decimal expansion. If you were to plot their histogram, then each digit would have a roughly similar frequency. For example, the decimal expansion of pi (π) never runs out of digits that seem to have a random distribution. Irrational numbers always have a non-terminating and non-repeating decimal expansion. However, that’s not the whole story when you factor in infinite continued fractions that can approximate irrational numbers: After all, the very definition of a rational number states that you can express it as a quotient, or a fraction, of two integers as long as the denominator is nonzero. The fractional notation is typically associated with rational numbers only. But can you recall the last time you used fractions? If you can’t, then that’s because decimal notation is central in calculators and computers nowadays.

On the other hand, fractions are more convenient in performing symbolic algebra by hand, which is why they’re mainly used in school. Finally, decimal numbers can communicate precision by keeping the trailing and leading zeros. Comparing decimals is also more straightforward since they already have a common denominator-the base of the system. Expressing a number in decimal notation is perhaps more intuitive because it resembles a percentage. Neither of these is better or more precise than the other. Within the decimal system itself, you can represent some numbers using alternative notations:

However, while people prefer the decimal system (base-10), computers work best in the binary system (base-2). You can choose any base or radix for such a system. Today, most people use a positional numeral system based on Hindu-Arabic symbols. There have been various systems of expressing numbers visually over the centuries. Finally, rational numbers contain integers and natural numbers. Real numbers are, in turn, comprised of rational and irrational numbers. At the very top, you’ll find complex numbers that include imaginary and real numbers.

There are many more types of numbers in mathematics, but these are the most relevant in day-to-day life. If you don’t remember the classification of numbers, here’s a quick refresher: Types of Numbers You should already be comfortable with these topics if you want to make the most out of this tutorial.
INFINITE FRACTION CONVERTER CODE
However, you’ll be in a good place to work through all the code examples that follow if you’re familiar with more advanced concepts such as Python’s built-in collections module, itertools module, and generators. The majority of this tutorial goes over the fractions module, which in itself doesn’t require in-depth Python knowledge other than an understanding of its numeric types. Know when to choose Fraction over Decimal or float.Represent fractions exactly with infinite precision.Convert between decimal and fractional notation.
INFINITE FRACTION CONVERTER HOW TO
You’ll also learn about their weaknesses and how to make the best use of them along the way. Towards the end of this tutorial, you’ll see a few hands-on examples where fractions are the most suitable and elegant choice. That’s essential if you plan to work with financial data or if you require infinite precision for your calculations. Even though it may not be well-known, it’s a useful tool to have under your belt because it can help address the shortcomings of floating-point arithmetic in binary. The fractions module in Python is arguably one of the most underused elements of the standard library.
