Skip to content

Commit

Permalink
Fix mode when precision=0. Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
Yasuo Ohgaki authored and bukka committed Jun 26, 2016
1 parent 5f5dc04 commit c715504
Show file tree
Hide file tree
Showing 2 changed files with 172 additions and 1 deletion.
2 changes: 1 addition & 1 deletion main/snprintf.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ PHPAPI char *php_gcvt(double value, int ndigit, char dec_point, char exponent, c
{
char *digits, *dst, *src;
int i, decpt, sign;
int mode = ndigit > 0 ? 2 : 0;
int mode = ndigit >= 0 ? 2 : 0;

if (mode == 0) {
ndigit = 17;
Expand Down
171 changes: 171 additions & 0 deletions tests/basic/precision.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
--TEST--
precision setting test
--INI--
precision=14
serialize_precision=17
--FILE--
<?php
$v = array(123456789.012345678901234567890, 10/3, 987e100);

echo "INI".PHP_EOL;
ini_set('precision', -1);
ini_set('serialize_precision', -1);
echo ini_get('precision'), PHP_EOL;
echo ini_get('serialize_precision'), PHP_EOL;
echo "OUTPUTS".PHP_EOL;
echo join($v, ' ').PHP_EOL;
print join($v, ' ').PHP_EOL;
var_dump(serialize($v));
var_export($v);echo PHP_EOL;


echo "INI".PHP_EOL;
ini_set('precision', 0);
ini_set('serialize_precision', 0);
echo ini_get('precision'), PHP_EOL;
echo ini_get('serialize_precision'), PHP_EOL;
echo "OUTPUTS".PHP_EOL;
echo join($v, ' ').PHP_EOL;
print join($v, ' ').PHP_EOL;
var_dump(serialize($v));
var_export($v);echo PHP_EOL;

echo "INI".PHP_EOL;
ini_set('precision', 9);
ini_set('serialize_precision', 9);
echo ini_get('precision'), PHP_EOL;
echo ini_get('serialize_precision'), PHP_EOL;
echo "OUTPUTS".PHP_EOL;
echo join($v, ' ').PHP_EOL;
print join($v, ' ').PHP_EOL;
var_dump(serialize($v));
var_export($v);echo PHP_EOL;

echo "INI".PHP_EOL;
ini_set('precision', 14);
ini_set('serialize_precision', 14);
echo ini_get('precision'), PHP_EOL;
echo ini_get('serialize_precision'), PHP_EOL;
echo "OUTPUTS".PHP_EOL;
echo join($v, ' ').PHP_EOL;
print join($v, ' ').PHP_EOL;
var_dump(serialize($v));
var_export($v);echo PHP_EOL;

echo "INI".PHP_EOL;
ini_set('precision', 17);
ini_set('serialize_precision', 17);
echo ini_get('precision'), PHP_EOL;
echo ini_get('serialize_precision'), PHP_EOL;
echo "OUTPUTS".PHP_EOL;
echo join($v, ' ').PHP_EOL;
print join($v, ' ').PHP_EOL;
var_dump(serialize($v));
var_export($v);echo PHP_EOL;

echo "INI".PHP_EOL;
ini_set('precision', 25);
ini_set('serialize_precision', 25);
echo ini_get('precision'), PHP_EOL;
echo ini_get('serialize_precision'), PHP_EOL;
echo "OUTPUTS".PHP_EOL;
echo join($v, ' ').PHP_EOL;
print join($v, ' ').PHP_EOL;
var_dump(serialize($v));
var_export($v);echo PHP_EOL;

echo "INI".PHP_EOL;
ini_set('precision', 100);
ini_set('serialize_precision', 100);
echo ini_get('precision'), PHP_EOL;
echo ini_get('serialize_precision'), PHP_EOL;
echo "OUTPUTS".PHP_EOL;
echo join($v, ' ').PHP_EOL;
print join($v, ' ').PHP_EOL;
var_dump(serialize($v));
var_export($v);echo PHP_EOL;
--EXPECT--
INI
-1
-1
OUTPUTS
123456789.01234567 3.3333333333333335 9.87E+102
123456789.01234567 3.3333333333333335 9.87E+102
string(72) "a:3:{i:0;d:123456789.01234567;i:1;d:3.3333333333333335;i:2;d:9.87E+102;}"
array (
0 => 123456789.01234567,
1 => 3.3333333333333335,
2 => 9.87E+102,
)
INI
0
0
OUTPUTS
1.0E+8 3 1.0E+103
1.0E+8 3 1.0E+103
string(47) "a:3:{i:0;d:1.0E+8;i:1;d:3.0E+0;i:2;d:1.0E+103;}"
array (
0 => 1.0E+8,
1 => 3.0E+0,
2 => 1.0E+103,
)
INI
9
9
OUTPUTS
123456789 3.33333333 9.87E+102
123456789 3.33333333 9.87E+102
string(55) "a:3:{i:0;d:123456789;i:1;d:3.33333333;i:2;d:9.87E+102;}"
array (
0 => 123456789,
1 => 3.33333333,
2 => 9.87E+102,
)
INI
14
14
OUTPUTS
123456789.01235 3.3333333333333 9.87E+102
123456789.01235 3.3333333333333 9.87E+102
string(66) "a:3:{i:0;d:123456789.01235;i:1;d:3.3333333333333;i:2;d:9.87E+102;}"
array (
0 => 123456789.01235,
1 => 3.3333333333333,
2 => 9.87E+102,
)
INI
17
17
OUTPUTS
123456789.01234567 3.3333333333333335 9.8700000000000007E+102
123456789.01234567 3.3333333333333335 9.8700000000000007E+102
string(86) "a:3:{i:0;d:123456789.01234567;i:1;d:3.3333333333333335;i:2;d:9.8700000000000007E+102;}"
array (
0 => 123456789.01234567,
1 => 3.3333333333333335,
2 => 9.8700000000000007E+102,
)
INI
25
25
OUTPUTS
123456789.0123456716537476 3.33333333333333348136307 9.870000000000000687310143E+102
123456789.0123456716537476 3.33333333333333348136307 9.870000000000000687310143E+102
string(109) "a:3:{i:0;d:123456789.0123456716537476;i:1;d:3.33333333333333348136307;i:2;d:9.870000000000000687310143E+102;}"
array (
0 => 123456789.0123456716537476,
1 => 3.33333333333333348136307,
2 => 9.870000000000000687310143E+102,
)
INI
100
100
OUTPUTS
123456789.01234567165374755859375 3.333333333333333481363069950020872056484222412109375 9.87000000000000068731014283095442748328521861543465424509123736073120616987695396574376473706259651E+102
123456789.01234567165374755859375 3.333333333333333481363069950020872056484222412109375 9.87000000000000068731014283095442748328521861543465424509123736073120616987695396574376473706259651E+102
string(218) "a:3:{i:0;d:123456789.01234567165374755859375;i:1;d:3.333333333333333481363069950020872056484222412109375;i:2;d:9.87000000000000068731014283095442748328521861543465424509123736073120616987695396574376473706259651E+102;}"
array (
0 => 123456789.01234567165374755859375,
1 => 3.333333333333333481363069950020872056484222412109375,
2 => 9.87000000000000068731014283095442748328521861543465424509123736073120616987695396574376473706259651E+102,
)

0 comments on commit c715504

Please sign in to comment.