Hello,
I'm facing a following problem with using incrbyfloat() command. As you can see all operations with numbers below 128 are OK but above it there is some very weird rounding used:
redis /var/lib/redis/redis.sock> set testkey 10 OK redis /var/lib/redis/redis.sock> incrbyfloat testkey 0.1 "10.1" redis /var/lib/redis/redis.sock> set testkey 127 OK redis /var/lib/redis/redis.sock> incrbyfloat testkey 0.1 "127.1" redis /var/lib/redis/redis.sock> set testkey 128 OK redis /var/lib/redis/redis.sock> incrbyfloat testkey 0.1 "128.10000000000000001" redis /var/lib/redis/redis.sock> set testkey 1000 OK redis /var/lib/redis/redis.sock> incrbyfloat testkey 0.1 "1000.09999999999999998" redis /var/lib/redis/redis.sock> set testkey 1000 OK redis /var/lib/redis/redis.sock> incrbyfloat testkey -0.1 "999.90000000000000002"
Problem is same with redis-2.8.13 and redis-3.2.6 (and I guess it's here from implementation of incrbyfloat in 2.6.0). Tested on Linux Centos 6.2 el6.x86_64.
Thanks.
Regards.
JS.
Comment From: badboy
Welcome to the wonderful world of IEEE 754 math & displaying those floating numbers. It's hard and not precise. You will always find cases where it is imprecise.
Comment From: john357smith
Take a cheap basic portable calculator and write 1000 + 0.1. Will you get a 1000.09999999999999998? Try it in some of commerical or non-commercial DB engines (Oracle, Maria etc.). Will you get 1000.09999999999999998? No and no. Because it's correctly implemented. I'm aware of problems with implementation of floating numbers but this is basic operation and must work corectly.
Welcome to the real world ...
Comment From: badboy
Redis kinda tried to make the output more humanfriendly, which obviously fails in your case (but it's more your libc to blame than Redis)
Comment From: TONYHOKAN
Hi, I am facing the same problem. Is that nothing Redis can be enhanced for the precision problem?
Comment From: mgravell
This isn't a precision problem; it is a "fundamental design of floating point arithmetic" thing, and the only "problem" is our human expectation of rounding working like we would do it with our frail weak fleshy brains.
Now, what could be done is that somebody could write a "module" that uses some arbitrary precision "big number" library to implement an auxiliary set of commands like "bigincrby" - I'm not volunteering, though.
Marc
On 3 April 2017 at 08:31, TONYHOKAN notifications@github.com wrote:
Hi, I am facing the same problem. Is that nothing Redis can be enhanced for the precision problem?
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/antirez/redis/issues/3695#issuecomment-291068516, or mute the thread https://github.com/notifications/unsubscribe-auth/AABDsFDDa01epFLv_UIalKR8DY9Thsj4ks5rsKBWgaJpZM4LQ9g_ .
-- Regards,
Marc
Comment From: filipecosta90
I believe this issue can be closed, given it's related to double precision IEEE floating point (double) to ASCII string conversion and is not an issue ( neither of redis or strtod() with is used for the IEEE arithmetic ).