Uploaded image for project: 'Couchbase PHP client library'
  1. Couchbase PHP client library
  2. PCBC-219

Floating point error in PHP Couchbase Library 1.1

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 1.1.2
    • Fix Version/s: 1.1.4, 1.2.2
    • Component/s: library
    • Security Level: Public
    • Labels:
      None

      Description

      --------------
      $value = 50.00;
      $couchbase->set('testvalue',$value,300);
      echo "getting value now... ";
      var_dump($couchbase->get('testvalue'));
      -------------
      float(5011)
      Not 50.00.

      Diving into the couchbase console, it is stored correctly. Something is wrong with the get method coming out of the PHP extension.
      This is happening on any 2 decimal number with .00 as the extension. Caught this in an ecommerce application ... needless to say $ impact of giving someone $5011 instead of $50.00 is damaging.
      Can anyone confirm this behavior in their environments?

      # Subject Project Status CR V
      For Gerrit Dashboard: &For+PCBC-219=message:PCBC-219

        Activity

        Hide
        trond Trond Norbye added a comment -

        This was already fixed in some version before 1.1.4. I added a new testcase to verify this.

        http://review.couchbase.org/25694

        Show
        trond Trond Norbye added a comment - This was already fixed in some version before 1.1.4. I added a new testcase to verify this. http://review.couchbase.org/25694
        Hide
        shaunt Shaun Tilford added a comment -

        We are now running on 1.1.5 and still see the issue happening. Noted on over a dozen of our boxes here, both in development and production environments.

        Show
        shaunt Shaun Tilford added a comment - We are now running on 1.1.5 and still see the issue happening. Noted on over a dozen of our boxes here, both in development and production environments.
        Hide
        trond Trond Norbye added a comment -

        What is your platform and PHP version so I can try to reproduce this?

        Show
        trond Trond Norbye added a comment - What is your platform and PHP version so I can try to reproduce this?
        Hide
        shaunt Shaun Tilford added a comment -

        PHP 5.4.12, CentOS release 5.6 (Final)

        Show
        shaunt Shaun Tilford added a comment - PHP 5.4.12, CentOS release 5.6 (Final)
        Hide
        trond Trond Norbye added a comment -

        I've had some trouble installing CentOS 5.6 locally, but so far I've tested it with success on:

        Ubuntu 13.04
        MacOS X
        CentOS 6 (php from yum)
        CentOS 5.7 (PHP 5.4.16)

        I have get access to a CentOS 5.6 system to debug the problem there

        Show
        trond Trond Norbye added a comment - I've had some trouble installing CentOS 5.6 locally, but so far I've tested it with success on: Ubuntu 13.04 MacOS X CentOS 6 (php from yum) CentOS 5.7 (PHP 5.4.16) I have get access to a CentOS 5.6 system to debug the problem there
        Hide
        trond Trond Norbye added a comment -

        Hi, I finally got around to get access to a 5.6 box, but I doesn't fail there either:

        [trondn@ip-10-36-176-84]~/compile/php-ext-couchbase/example% cat /etc/redhat-release
        CentOS release 5.6 (Final)
        [trondn@ip-10-36-176-84]~/compile/php-ext-couchbase/example% /opt/php/bin/php --version
        PHP 5.4.16 (cli) (built: Jun 17 2013 16:44:15)
        Copyright (c) 1997-2013 The PHP Group
        Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies
        [trondn@ip-10-36-176-84]~/compile/php-ext-couchbase/example% cat float.php
        <?php

        $cb = new Couchbase("localhost");

        $val = 50.0;
        var_dump($cb->set("foo", $val));
        var_dump($cb->get("foo"));
        ?>
        [trondn@ip-10-36-176-84]~/compile/php-ext-couchbase/example% /opt/php/bin/php -c couchbase.ini float.php
        string(19) "5776353753026134016"
        float(50)

        Show
        trond Trond Norbye added a comment - Hi, I finally got around to get access to a 5.6 box, but I doesn't fail there either: [trondn@ip-10-36-176-84] ~/compile/php-ext-couchbase/example% cat /etc/redhat-release CentOS release 5.6 (Final) [trondn@ip-10-36-176-84] ~/compile/php-ext-couchbase/example% /opt/php/bin/php --version PHP 5.4.16 (cli) (built: Jun 17 2013 16:44:15) Copyright (c) 1997-2013 The PHP Group Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies [trondn@ip-10-36-176-84] ~/compile/php-ext-couchbase/example% cat float.php <?php $cb = new Couchbase("localhost"); $val = 50.0; var_dump($cb->set("foo", $val)); var_dump($cb->get("foo")); ?> [trondn@ip-10-36-176-84] ~/compile/php-ext-couchbase/example% /opt/php/bin/php -c couchbase.ini float.php string(19) "5776353753026134016" float(50)
        Hide
        ingenthr Matt Ingenthron added a comment -

        Note, this was 64-bit, but the bug didn't indicate whether it was observed on 32-bit or 64-bit.

        Show
        ingenthr Matt Ingenthron added a comment - Note, this was 64-bit, but the bug didn't indicate whether it was observed on 32-bit or 64-bit.
        Hide
        avsej Sergey Avseyev added a comment -

        FYI there is a patch related http://review.couchbase.org/35567

        Show
        avsej Sergey Avseyev added a comment - FYI there is a patch related http://review.couchbase.org/35567

          People

          • Assignee:
            trond Trond Norbye
            Reporter:
            trond Trond Norbye
          • Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Gerrit Reviews

              There are no open Gerrit changes