Skip to content

Commit fe6aec2

Browse files
committed
Address 64 bit issues
1 parent 025f1ec commit fe6aec2

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

src/Encoder/IntegerEncoder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public function supports($value)
2222

2323
public function encode($value, $depth, array $options, callable $encode)
2424
{
25-
$string = number_format($value, 0, '.', '');
25+
$string = (string) $value;
2626

2727
if ($value === 1 << (PHP_INT_SIZE * 8 - 1)) {
2828
$string = sprintf('(int)%s%s', $options['whitespace'] ? ' ' : '', $string);

src/InvalidOptionException.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Riimu\Kit\PHPEncoder;
44

55
/**
6+
* Exception that gets thrown if invalid encoder options are used.
67
* @author Riikka Kalliomäki <[email protected]>
78
* @copyright Copyright (c) 2015, Riikka Kalliomäki
89
* @license http://opensource.org/licenses/mit-license.php MIT License

tests/tests/EncodingTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,13 @@ public function testFloatIntegers()
125125
public function testMaximumFloatIntegers()
126126
{
127127
$encoder = new PHPEncoder(['float.integers' => true]);
128+
$positive = FloatEncoder::FLOAT_MAX - 1;
129+
$negative = -FloatEncoder::FLOAT_MAX + 1;
128130

129131
$this->assertEncode(FloatEncoder::FLOAT_MAX, '9.0071992547409927E+15', $encoder);
130132
$this->assertEncode(-FloatEncoder::FLOAT_MAX, '-9.0071992547409927E+15', $encoder);
131-
$this->assertEncode(FloatEncoder::FLOAT_MAX - 1, '9007199254740991', $encoder);
132-
$this->assertEncode(-FloatEncoder::FLOAT_MAX + 1, '-9007199254740991', $encoder);
133+
$this->assertEncode(number_format($positive, 0, '', '') + 0, '9007199254740991', $encoder, $positive);
134+
$this->assertEncode(number_format($negative, 0, '', '') + 0, '-9007199254740991', $encoder, $negative);
133135
}
134136

135137
public function testLargeFloatIntegers()

0 commit comments

Comments
 (0)