Zend Framework

Conversion error in Zend_Measure_*, when using small numbers (possible precision problem)

Details

  • Type: Bug Bug
  • Status: Resolved Resolved
  • Priority: Major Major
  • Resolution: Cannot Reproduce
  • Affects Version/s: 1.10.2, 1.10.6
  • Fix Version/s: 1.10.7
  • Component/s: Zend_Measure
  • Labels:
    None

Description

When i convert small numbers to another unit/type, Zend_Measure miscalculates the values. This occurs between many of the measurement units. The example code is:

// convert 1 cubic inch to cubic centimeters
$bug=new Zend_Measure_Volume(1, Zend_Measure_Volume::CUBIC_INCH);
$bug->setType(Zend_Measure_Volume::CUBIC_CENTIMETER);
echo $bug->getValue(2); // returns -163870640693, should return 16.39

// method 2, "->convertTo()":
$bug=new Zend_Measure_Volume(1, Zend_Measure_Volume::CUBIC_INCH);
$v2=$bug->convertTo(Zend_Measure_Volume::CUBIC_CENTIMETER);
echo $v2; // returns -163 870 640 693 cm³

As far as i can tell, this happens in Zend_Measure_Volume, Zend_Measure_Area, Zend_Measure_Length and Zend_Measure_Weight - did not test others

Activity

Hide
Manuel Gomes added a comment -

Strangely, the following code also fails:

$bug=new Zend_Measure_Volume(1.0, Zend_Measure_Volume::CUBIC_INCH);
$bug->setType(Zend_Measure_Volume::CUBIC_INCH); // same unit
echo $bug->getValue(); // returns -10000000000 (!!!)

Should return "1", not "-10000000000"

Show
Manuel Gomes added a comment - Strangely, the following code also fails: $bug=new Zend_Measure_Volume(1.0, Zend_Measure_Volume::CUBIC_INCH); $bug->setType(Zend_Measure_Volume::CUBIC_INCH); // same unit echo $bug->getValue(); // returns -10000000000 (!!!) Should return "1", not "-10000000000"
Hide
Thomas Weidner added a comment -

Unable to reproduce:
With bcmath:

string '16.39' (length=5)
string '16,39 cm³' (length=10)
string '0.9999999999999999999957732' (length=27)

Without bcmath:

string '16.39' (length=5)
string '16,39 cm³' (length=10)
string '1' (length=1)

Note: Precision differences are no failure.

Show
Thomas Weidner added a comment - Unable to reproduce: With bcmath:
string '16.39' (length=5)
string '16,39 cm³' (length=10)
string '0.9999999999999999999957732' (length=27)
Without bcmath:
string '16.39' (length=5)
string '16,39 cm³' (length=10)
string '1' (length=1)
Note: Precision differences are no failure.
Hide
Thomas Weidner added a comment -

Closing as not reproduceable

Show
Thomas Weidner added a comment - Closing as not reproduceable

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: