Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

floating and integers....?

why do we need integers and floating in processor?thank you

like image 323
amy Avatar asked Nov 05 '22 17:11

amy


1 Answers

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

like image 89
High Performance Mark Avatar answered Nov 16 '22 13:11

High Performance Mark