why do we need integers and floating in processor?thank you
Integers are for counting, floating-point numbers are for calculating. We have them both in maths (where they are called integers and real numbers respectively) so we need them in algorithms and in programs too. End of story.
Sure, the range of most fp number implementations is larger than the range of most integer implementations but I could invent a language tomorrow in which I allow 512-bit integers but only 16-bit floating-point numbers (1 sign bit, 3 exponent bits, 12 significand bits). The integers are still not closed under division and the floating-point numbers are still no use for counting because while there is a successor function on fp numbers there isn't on real numbers and we like to pretend that fp numbers are a close implementation of real numbers.
No, integers are not easier on the processor, the processor does fundamental boolean logic operations on bits. And if processor X1 does integer arithmetic faster than fp arithmetic, a trawl through the memory banks will find a counter example.
We don't even need fp numbers for fractions, we could use pairs of integers to represent numerator and denominator.
The absolute precision of integers is why we use them for counting. For all practical purposes the precision of existing fp implementations is enough (now, there's a wild claim to attract disagreement !)
Regards
Mark
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With