Author: wyoung
Date: Thu Aug 15 20:36:33 2013
New Revision: 2748
URL: http://svn.gna.org/viewcvs/mysqlpp?rev=2748&view=rev
Log:
Added plan for improving FP comparison
Modified:
trunk/Wishlist
Modified: trunk/Wishlist
URL:
http://svn.gna.org/viewcvs/mysqlpp/trunk/Wishlist?rev=2748&r1=2747&r2=2748&view=diff
==============================================================================
--- trunk/Wishlist (original)
+++ trunk/Wishlist Thu Aug 15 20:36:33 2013
@@ -53,6 +53,57 @@
o The escape_q() functions aren't returning the right value when
dealing with Null<T> wrapped types, such as sql_blob_null.
+
+ o The current method SSQLS uses to compare floating point numbers
+ is highly dubious. It just subtracts them, and checks that the
+ absolute difference is under some threshold. According to this
+ current rule, $1,000,010,000 is the same as $1,000,000,000,
+ which means Larry Ellison should send me a check for tens of
+ thousands of dollars, since it is an insignificant amount.
+
+ For backards compatibility, we should keep this method, but we
+ should add these two more mathematically sound methods:
+
+ - Percentage: Divide the smaller number into the larger, then
+ compare against a threshold. The default should be
+ something like 1.000001 (1 ppm), which lets us make much
+ finer distinctions without running out of precision, more
+ on the order of the amount of money Bill Gates loses in his
+ couch cushions.
+
+ - Logarithmic, or "Bels": Same as percentage, but on a log10
+ scale so it works better for FP numbers, which are based on
+ powers of 10. Logarithms are more costly than division,
+ and we still need a division for this, so it shouldn't be
+ the new default.
+
+ 1 ppm is ~4.3e-7, which is below what single-precision FP
+ can distinguish. Increasing the threshold to a value you
+ *can* distinghish with a 32-bit IEEE float makes it ignore
+ significant amounts of money in Bill Gates' couch cusions.
+ (Hundreds of dollars.) Therefore, we should use something
+ like 1e-7 or 1e-8 anyway, and make it clear that the default
+ threshold is only suitable for doubles.
+
+ It's probably more efficient to change the algorithm from:
+
+ double diff = log10(a > b ? a / b : b / a);
+
+ to:
+
+ double diff = fabs(log10(a / b));
+
+ Logarithms give the same magnitude result for a/b as b/a,
+ differing only in sign. fabs() is probably implemented as
+ an intrinsic that just clears a single bit, which should be
+ cheaper than a floating point comparison followed by a jump.
+
+ With suitable tuning, this method would allow you to
+ distinguish the change lost by a single Pentagon contractor's
+ lobbyist to a single couch, on a single occasion, as compared
+ to the combined net worth of all Pentagon contractors and
+ their employees, assigns, mistresses, and, ah, hired help.
+ If you use doubles, anyway.
v3.3 Plan: Finish SSQLS v2
_______________________________________________
Mysqlpp-commits mailing list
[email protected]
https://mail.gna.org/listinfo/mysqlpp-commits