-
Notifications
You must be signed in to change notification settings - Fork 23.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
incrbyfloat behaviour with bigger number than 127 #3695
Comments
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. |
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 ... |
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) |
Hi, |
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 ***@***.***> 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
<#3695 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AABDsFDDa01epFLv_UIalKR8DY9Thsj4ks5rsKBWgaJpZM4LQ9g_>
.
--
Regards,
Marc
|
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 ). |
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.
The text was updated successfully, but these errors were encountered: