|
Safiya Dogara Bashir/sdbashir2001@yahoo.com - 07 Sep 2008
The floats are a subset of the rational numbers. A given rational number may or may not be exactly representable a float, depending on the base of the float, its length, and the rational number in question, so not all rational numbers are floats - in other words, the binary floats are a different set from the decimal floats, and so on. It is correct to refer to floats as fractional numbers, although slightly misleading since that description could be understood to mean "magnitude smaller than unity."
Examples:
1/5 can be represented exactly as a decimal fraction in only one digit [0.2], but it has no exact base 2 fraction representation of any length. It is a rational number, in base 2 [1/101(2)] or any other base, but it is a nonterminating fraction in base 2.
1/3 is a nonterminating fraction in base 2 or base 10 but it is 0.1(3).
10^(1/2), pi and e are irrational numbers and cannot be exactly represented by any finite-length number in any base.
Please note that in most languages floats (also called "reals" in some languages) are stored in base 2, not base 10. (BASIC and COBOL and perhaps others offer "currency" or "BCD" data types in which numbers are stored as either fixed or floating point decimals, however.) I haven't read far enough yet to know how PHP stores its floats, but if it is compatible with C then floats are stored in base 2 - this is the usual choice since decimal representations tend to inflict a considerable performance hit on commonly-available computer hardware.
A PHP learner - 07 Sep 2008
The floats are a subset of the rational numbers. A given rational number may or may not be exactly representable a float, depending on the base of the float, its length, and the rational number in question, so not all rational numbers are floats - in other words, the binary floats are a different set from the decimal floats, and so on. It is correct to refer to floats as fractional numbers, although slightly misleading since that description could be understood to mean "magnitude smaller than unity."
Examples:
1/5 can be represented exactly as a decimal fraction in only one digit [0.2], but it has no exact base 2 fraction representation of any length. It is a rational number, in base 2 [1/101(2)] or any other base, but it is a nonterminating fraction in base 2.
1/3 is a nonterminating fraction in base 2 or base 10 but it is 0.1(3).
10^(1/2), pi and e are irrational numbers and cannot be exactly represented by any finite-length number in any base.
Please note that in most languages floats (also called "reals" in some languages) are stored in base 2, not base 10. (BASIC and COBOL and perhaps others offer "currency" or "BCD" data types in which numbers are stored as either fixed or floating point decimals, however.) I haven't read far enough yet to know how PHP stores its floats, but if it is compatible with C then floats are stored in base 2 - this is the usual choice since decimal representations tend to inflict a considerable performance hit on commonly-available computer hardware.
Rik - 07 Sep 2008
This is wrt Kyle's comment. A rational number is one that could be expressed as p/q where p and q are integers. So, the two number representation is in fact more appropriate for rational numbers than for fractions in general.
Floats are rationals, because they are a number, divided by a power of the base. However, not all rationals are representable as floats. 1/3 is a rational number. It cannot be represented as a float, because it translates to an infinitely recurring decimal representation.
So, if you consider defining floats as fractions to be innacurate, then so defining them as rationals. Neither set is completely covered by floats.
Kyle - 07 Sep 2008
Technically, I'd consider a "float" to be more of a rational number, rather than a fractional number. It can have a floating point decimal in it, and it is stored as a large integer with axponential of ten, e.g. 314159265e-8. I'd imagine fractions as being two integers stored, and the computer would have to compute it each time it used it (5 and 8 make 5/8, which computes to .625). Fractional numbers cannot always be accurately converted into floats, though, as 1/3 does not have a displayable decimal equivallent.
A PHP User - 07 Sep 2008
What about the "boolean" / "bool" variable type?
Dirk
Add comment
Please note that by posting a comment here you are committing it to the public domain. This is important so that others can make use of your code themselves, and also so that I can incorporate helpful notes directly into the main text. Comments are limited to 2000 characters in length.
If you are reporting an error in the content, please tell me directly.
|