Ok, as there seem to be some experts about floating-point numbers here, there is one aspect that I never understood:
floats are stored as a fractional part, which is binary encoded, and an integer-type exponent. The first leads to the famous rounding errors as there is no exact representation of most fractions. Can someone explain to me why it has been defined this way? Having 1 bit sign, 11 bit exponent, and 52 bit mantissa, I would have stored the (in the meantime well known) number 211496.26 as 21149626E-2, i.e. I would have stored a 52 bit integer number and appropriate exponent. This way there should be no rounding errors and one would always have a guaranteed precision of ~15 significant digits. ----- Original Message ----- From: Keith Medcalf <kmedc...@dessus.com> To: SQLite mailing list <sqlite-users@mailinglists.sqlite.org> Sent: Monday, December 17, 2018, 20:12:29 Subject: [sqlite] Question about floating point The "nearest" representation of 211496.26 is 211496.26000000000931323. The two representable IEEE-754 double precision floating point numbers bounding 211496.26 are: 211496.26000000000931323 211496.2599999999802094 The difference between 211496.25999999992 (which is itself a truncated representation -- the actual stored value should presumably be 211496.25999999992200173) and 211496.26000000000931323 is 8.73114913702011e-11, or 3 ULP. Applying half-even rounding at the second "decimal place" to 211496.25999999992 (which when multiplied by 100 is 21149625.9999999925494194 which half-even rounds to 21149626.0 which when divided by 100 is 211496.26000000000931323 or exactly the "nearest representable IEEE-754 double precision floating point number" to 211496.26 --- The fact that there's a Highway to Hell but only a Stairway to Heaven says a lot about anticipated traffic volume. >-----Original Message----- >From: sqlite-users [mailto:sqlite-users- >boun...@mailinglists.sqlite.org] On Behalf Of Simon Slavin >Sent: Monday, 17 December, 2018 10:36 >To: SQLite mailing list >Subject: Re: [sqlite] Question about floating point >On 17 Dec 2018, at 5:16pm, James K. Lowden <jklow...@schemamania.org> >wrote: >> IEEE >> double-precision floating point is accurate to within 15 decimal >> digits. >First, the problem is not storage it's calculation. >Second, the thread was started because a floating point calculation >in SQLite, exactly as it is run today, led to the following value: >211496.25999999992 >which is typical of such problems. Please don't consider that >there's no problem until you have solved that problem. >Simon. >_______________________________________________ >sqlite-users mailing list >sqlite-users@mailinglists.sqlite.org >http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users _______________________________________________ sqlite-users mailing list sqlite-users@mailinglists.sqlite.org http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users _______________________________________________ sqlite-users mailing list sqlite-users@mailinglists.sqlite.org http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users