I am confused as to why there can be rounding errors in floating point numbers. Can someone show me an example or two? What are their min and max values? Does that mean I get every (well not every..if not how much?) number and decimal in between the min/max?
So if I wanted to hold a population of a country. i.e. USA, should I choose ints over floats for this purpose or would they have no effect. Memory, efficiency, taken into account. And what would be the answer if are not taken into account? The population count will be whole numbers.
These are questions are quite rudimentary, and on the web in lengthy detail, but I am just having trouble piecing them together as they get really complicated.
Thank you for your time.
PS: Please let me know via comment if this questions is badly worded. I will edit so it can get clearer.
No you
cannotshould not use float. Both float & int are 32 bit storage types & you gain nothing range wise.For example, if the max value of signed int
2147483647is tried as a float gives you2.14748e+09So if it was a population count you lost the
3647.The best you can use is a 64 bit type int (type
long longin C/C++) in cases for a longer range.Edit:
Regarding Efficiency, the most efficient type is always the
intwith word size of a machine.Floating point numbers require the machine to use a math processing unit additionally.
So if it’s a 32 bit machine, int 32 bit is the fastest & most efficient.