Skip to content

Commit

Permalink
Added float comparison null checks (#33421)
Browse files Browse the repository at this point in the history
  • Loading branch information
GrahamCampbell authored Jul 3, 2020
1 parent 1116adb commit a22ad1f
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -1179,6 +1179,10 @@ public function originalIsEquivalent($key, $current)
return $this->castAttribute($key, $current) ==
$this->castAttribute($key, $original);
} elseif ($this->hasCast($key, ['real', 'float', 'double'])) {
if (($current === null && $original !== null) || ($current !== null && $original === null)) {
return false;
}

return abs($this->castAttribute($key, $current) - $this->castAttribute($key, $original)) < PHP_FLOAT_EPSILON * 4;
} elseif ($this->hasCast($key)) {
return $this->castAttribute($key, $current) ===
Expand Down

0 comments on commit a22ad1f

Please sign in to comment.