What is the difference between float and double ? Everywhere it is written that double similar to float , but with a large range, but when I created the tables, MySQL suggested that both float(255,30) and double(255,30) maximum dimensions. So what kind of double precision can we talk about?

And what is the double double precision? I read that float is stored as an exponent, and double is a double Integer (the integer and fractional parts). But based on the article on Habré What you need to know about floating-point arithmetic

It seems to me that inside and float and double will be equally stored in the form of mantis, etc., just that one will take 4 байта , and the other - 8 байт .

  • one
    double is not double int, it certainly occupies 64 bits, but its structure is the same as that of float, only more bits are given to the mantissa and the degree of ru.wikipedia.org/wiki/… - Mike
  • And once more bits are stored then accuracy is higher. because the exact value cannot be stored, it is stored closest to it. And this is the nearest float may be much more different from what is required than the double - Mike

1 answer 1

Everything seems to be right for you - indeed, float takes 4 bytes, and double - respectively 8 bytes. Numbers in brackets after specifying the type do not refer to how the number will be stored, but how it will be presented in decimal form: the first parameter is the maximum total number of digits in the number, the second is the maximum number of decimal places (for example, when specifying FLOAT(7,4) or DOUBLE(7,4) number will be represented as -999.9999 ).

  • Good. But give an example when I can put in a double a number greater or more accurate than in a float. Because now I have the impression that just one occupies 4 bytes, and the second - 8. - Joseph Katzman
  • one
    @JosephKatzman Create a table with a field of one type and another and insert there say, 1/3 and immediately see the difference. sqlfiddle.com/#!9/198400/1 (although its rounding is still on fiddle, better on a real database through some sort of MySQL workshop look) - Mike
  • 2
    such an example also clearly shows where accuracy is sometimes important: create table test(f float(255,30), d double(255,30)); insert into test values(1.1, 1.1); select f - 0.1 as f, d - 0.1 as d from test; create table test(f float(255,30), d double(255,30)); insert into test values(1.1, 1.1); select f - 0.1 as f, d - 0.1 as d from test; (it’s on fiddle: sqlfiddle.com/#!9/af0d2f/2 ) - Alex Chermenin