Skip to content

Commit

Permalink
Fixed MachineFloatingPoint and improve the related Test Class
Browse files Browse the repository at this point in the history
  • Loading branch information
lestcape committed Feb 13, 2024
1 parent efa7ec6 commit 688b235
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
6 changes: 3 additions & 3 deletions src/Sav/Record/Info/MachineFloatingPoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@ public function read(Buffer $buffer)

public function write(Buffer $buffer)
{
if ($this->sysmis === 0.0) {
if (!isset($this->sysmis)) {
$this->sysmis = -PHP_FLOAT_MAX;
}

if ($this->highest === 0.0) {
if (!isset($this->highest)) {
$this->highest = PHP_FLOAT_MAX;
}

if ($this->lowest === 0.0) {
if (!isset($this->lowest)) {
$this->lowest = -PHP_FLOAT_MAX;
}

Expand Down
14 changes: 6 additions & 8 deletions tests/MachineFloatingPointTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ public function provider()
],
[
[],
// -1.7976931348623E+308 php min double
// 1.7976931348623E+308 php max double
// -1.7976931348623E+308 php min double -PHP_FLOAT_MAX
// 1.7976931348623E+308 php max double PHP_FLOAT_MAX
[
'sysmis' => -1.7976931348623158E+308,
'highest' => 1.7976931348623158E+308,
'lowest' => -1.7976931348623158E+308,
'sysmis' => -PHP_FLOAT_MAX,
'highest' => PHP_FLOAT_MAX,
'lowest' => -PHP_FLOAT_MAX,
],
],
];
Expand All @@ -54,10 +54,8 @@ public function testWriteRead(array $attributes, array $expected)
$read = MachineFloatingPoint::fill($buffer);
$this->assertEquals(40, $buffer->position());
foreach ($expected as $key => $value) {
$expected = 0;
$actual = @bcsub($value, $read->{$key});
$msg = "Wrong value received for '$key', expected '$value', got '{$read->{$key}}'";
$this->assertEquals($expected, $actual, $msg);
$this->assertEquals($value, $read->{$key}, $msg);
}
}
}

0 comments on commit 688b235

Please sign in to comment.