Skip to content
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

Closed
john357smith opened this issue Dec 19, 2016 · 6 comments
Closed

incrbyfloat behaviour with bigger number than 127 #3695

john357smith opened this issue Dec 19, 2016 · 6 comments
Labels
state:to-be-closed requesting the core team to close the issue

Comments

@john357smith
Copy link

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.

@badboy
Copy link
Contributor

badboy commented Dec 19, 2016

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.

@john357smith
Copy link
Author

john357smith commented Dec 19, 2016

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 ...

@badboy
Copy link
Contributor

badboy commented Dec 19, 2016

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)

@TONYHOKAN
Copy link

Hi,
I am facing the same problem. Is that nothing Redis can be enhanced for the precision problem?

@mgravell
Copy link

mgravell commented Apr 3, 2017 via email

@filipecosta90 filipecosta90 added the state:to-be-closed requesting the core team to close the issue label Mar 28, 2021
@filipecosta90
Copy link
Contributor

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 ).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
state:to-be-closed requesting the core team to close the issue
Projects
None yet
Development

No branches or pull requests

6 participants