Comparing Integers and Doubles
databasearchitects.blogspot.com
Comparing Integers and Doubles
1–10 of 14 posts
Re: Comparing Integers and Doubles
#2Re: Comparing Integers and Doubles
#3The only reasonable way to compare rationals is the decimal expansion of the string.
Re: Comparing Integers and Doubles
#4or you could learn about how to do comparisons with floating point numbers
Re: Comparing Integers and Doubles
#5Both ints and floats represent real, rational values, but every operation in no way matches math. Associative? No. Commutative? No. Partially Ordered? No. Weakly Ordered? No. Symmetric? No. Reflexive? No. Antisymmetric? No. Nothing. The only reasonable way to compare rationals is the decimal expansion of the string.
https://en.wikipedia.org/wiki/Floating-point_arithmetic#Accu...
Re: Comparing Integers and Doubles
#6Both ints and floats represent real, rational values, but every operation in no way matches math. Associative? No. Commutative? No. Partially Ordered? No. Weakly Ordered? No. Symmetric? No. Reflexive? No. Antisymmetric? No. Nothing. The only reasonable way to compare rationals is the decimal expansion of the string.
What exactly do you say is not commutative? This Wikipedia article claims that at least floating-point addition and multiplication are both commutative: https://en.wikipedia.org/wiki/Floating-point_arithmetic#Accu...
Re: Comparing Integers and Doubles
#7Both ints and floats represent real, rational values, but every operation in no way matches math. Associative? No. Commutative? No. Partially Ordered? No. Weakly Ordered? No. Symmetric? No. Reflexive? No. Antisymmetric? No. Nothing. The only reasonable way to compare rationals is the decimal expansion of the string.
Careful, someone is liable to throw this in an LLM prompt and get back code expanding the ASCII characters for string values like "1/346".
Re: Comparing Integers and Doubles
#8This was one of the bigger hidden performance issues when I was working on Hive - the default coercion goes to Double, which has a bad hash code implementation [1] & causes joins to cluster & chain, which caused every miss on the hashtable to probe that many away from the original index.
The hashCode itself was smeared to make values near Machine epsilon to hash to the same hash bucket so that .equals could do its join, but all of this really messed up the folks who needed 22 digit numeric keys (eventually Decimal implementation handled it by adding a big fixed integer).
Databases and Double join keys was one of the red-flags in a SQL query, mostly if you see it someone messed up something.
Re: Comparing Integers and Doubles
#9Both ints and floats represent real, rational values, but every operation in no way matches math. Associative? No. Commutative? No. Partially Ordered? No. Weakly Ordered? No. Symmetric? No. Reflexive? No. Antisymmetric? No. Nothing. The only reasonable way to compare rationals is the decimal expansion of the string.