Bug #64760 [Csd]: var_export() does not use full precision for floating-point numbers

From: Date: Tue, 19 Nov 2013 22:03:05 +0000
Subject: Bug #64760 [Csd]: var_export() does not use full precision for floating-point numbers
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-182843@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=64760&edit=1

 ID:                 64760
 Updated by:         yohgaki@php.net
 Reported by:        cf0hay at gmail dot com
 Summary:            var_export() does not use full precision for
                     floating-point numbers
 Status:             Closed
 Type:               Bug
 Package:            Variables related
 Operating System:   Linux 64bit (PHP 64bit too)
 PHP Version:        5.4.14
 Assigned To:        yohgaki
 Block user comment: N
 Private report:     N

 New Comment:

I've mentioned in NEWS that this bug was fixed in 5.4/5.5.

I can understand your proposal, but UPGRADING is for new release..


Previous Comments:
------------------------------------------------------------------------
[2013-11-14 03:13:21] whatthejeff@php.net

This might also be worth mentioning in the UPGRADING file and/or the documentation as it caused some
confusion in the PHPUnit project: https://github.com/sebastianbergmann/phpunit/issues/1052

------------------------------------------------------------------------
[2013-11-14 03:09:47] whatthejeff@php.net

Corrected link: https://github.com/php/php-src/pull/525

------------------------------------------------------------------------
[2013-11-14 03:07:47] whatthejeff@php.net

This change can break tests on some systems. See https://github.com/php/php-src/pull/525.

------------------------------------------------------------------------
[2013-10-29 11:29:37] yohgaki@php.net

Committed fix, but not auto closed. Closing

 3cf2682083fc1c8635b02c4cf77bdf12c5e5da35

------------------------------------------------------------------------
[2013-10-23 09:09:26] yohgaki@php.net

The difference came from 

var_export()
-------------------------------------------------------
	case IS_DOUBLE:
		tmp_len = spprintf(&tmp_str, 0,"%.*H", (int) EG(precision), Z_DVAL_PP(struc));
		smart_str_appendl(buf, tmp_str, tmp_len);
		efree(tmp_str);
		break;-------------------------------------------------------



serialize()
-------------------------------------------------------
		case IS_DOUBLE: {
				char *s;

				smart_str_appendl(buf, "d:", 2);
				s = (char *) safe_emalloc(PG(serialize_precision), 1, MAX_LENGTH_OF_DOUBLE + 1);
				php_gcvt(Z_DVAL_P(struc), PG(serialize_precision), '.', 'E', s);
				smart_str_appends(buf, s);
				smart_str_appendc(buf, ';');
				efree(s);
				return;
			}
-------------------------------------------------------

var_export() uses precision=14 while serialize() uses precision=17 by default.

-------
[yohgaki@dev php-5.5]$ php -e precision=17 scr.php
error of serialize(): 0
error of var_export(): 0
-------

Since var_export() is better to behave like serialize(), var_export() is better to use
PG(serialize_precision) instead of PG(precision).

------------------------------------------------------------------------


The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at

    https://bugs.php.net/bug.php?id=64760


-- 
Edit this bug report at https://bugs.php.net/bug.php?id=64760&edit=1


Thread (7 messages)

« previous php.bugs (#182843) next »