简体   繁体   中英

What exactly is the difference between 'float' and 'double' floating point storage types?

I've seen examples of the terms "float" and "double" being applied to different scenarios and seem to understand that bits and bytes serve some role, but I cannot find a clear explanation of what the difference is . Memory constraints seem like the cause of such differentiation (??), but I really just want to know specifically what one is vs. the other .

Further, how does one tell if data is classified (or should be stored) as "float" vs. "double"?

How do these concepts apply to decimal values (vs. binary)?


Context : I have a series of variables stored in a .csv table for which I'm trying to define "storage type." Some are integers, others are strings and still others are numbers with decimals. I'm just trying to figure out how to define "storage type" for each.

Floating point is a way to represent numbers that is used in computers, and is explained elsewhere, for example here and here . Double just uses more bits than float, so double has more precision and range.

In a CSV file, numbers are stored as text, for example using the five characters "27.37". Floating point is a way of representing numbers that is used internally by computers, so the numbers you have in your CSV file are not floating-point numbers at all. They are neither floats nor doubles.

When these numbers are to be processed by a computer, the text format is (typically) converted to an internal format, usually one of float and double. You can't decide which by looking at the text version of the number, since it in itself is neither. You have to decide based on the precision and speed you need. In most cases I would recommend to use double, since doubles have higher precision, and are very fast on typical modern computers. You can save some space, and sometimes gain some speed, by using float, but that is only needed in exceptional cases.

But, to contradict myself: In some cases you can look at a number written as text, and determine whether it can be stored as a float or a double. For example, if you find the number "0.333333333333333314829616256247390992939472198486328125" written just like that, it isn't a float or a double in itself, but this particular number, with all those decimals, can be stored as a double but not as a float. If stored as a float, with its fewer bits, it would be converted to "0.3333333432674407958984375".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM