What is a float?


"Try out the max() function on line 3 of the editor. You can provide any number of integer or float arguments to max()."

What is meant by float here?


An integer, as we know, is a whole number which can be either negative (less than zero) or positive (greater than zero), or zero itself. This is the parent set of Natural numbers, those we count with from 1 to n.

Decimal numbers are either rational (can be written as a fraction) or irrational (cannot be written in fraction form). Both of these numbers require special attention from the computer when converting them to binary. In binary there are no decimal fractions. A complex algorithm is carried out by the ALU (arithmetic and logic unit) on the computers mother board (or part of the CPU, itself). This process is known as floating point arithmetic and is what gives us the term, float.

So a float them is any number with a decimal fraction, or more precisely, is any number between 0, inclusive, and 1, exclusive, or between -1, exclusive and 0, inclusive, if we wish to narrow down just the decimal portion of the number.

Take PI for instance. 3 is an integer. but .1415... is a float.

When we call upon math.randint() with no arguments, it returns a float.


Thank you for your answer, it cleared some things up! :slightly_smiling: However:

The module math doesn't seem to contain a function randint. The numpy module however does. But the randint fuction there doesn't work with no arguments.

What about other bases? Like base 16. Then you probably couldn't say that a float is a decimal fraction? A hexadecimal fraction then? Are there binary fractions by the way?

And irrational numbers like Pi are only approximated then by this floating point arithmatic, right? There can't be a precise fraction in whatever base. You would have to have an unending float ".1415...", but floats have to stop somewhere?


It may either be a difference between Python 2.x and Python 3.x, or I just have it confused with JavaScript. This can happen when you jump around from language to language. Paths get crossed and lines get blurred. Besides, what was I thinking? rand int. D'oh!

What I meant was, random.random() which will generate a float. My bad.

The only number system to have decimal fractions is, like the name implies, the decimal system, or base 10. Other bases need to use a complex system to represent floats. How this is performed in the computer is way beyond my comprehension.

When you get into advanced math principles in Computer Science or Applied Mathematics you will uncover the various series, sequences and identities that are in play. It is highly theoretical.

There are no fractions in binary.


Alright, thanks! :slightly_smiling:
random.random() works in Python 3 for me :slightly_smiling: