Skip to content

Commit 8b4eeca

Browse files
committed
Lint/FloatComparison
Comparing floats for exact quality is error prone due to lack of precision. Rubocop is trying to protect us from this subtle issue. However, in this specific case, calling Float.zero? is the same thing[1] so there is no behavior change. [1] https://github.com/ruby/ruby/blob/b6b31f673d9514a8af8992b0f7abb8b0597d87af/internal/numeric.h#L153
1 parent 70d9fa3 commit 8b4eeca

File tree

2 files changed

+2
-8
lines changed

2 files changed

+2
-8
lines changed

.rubocop_todo.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -612,10 +612,6 @@ Lint/EnsureReturn:
612612
Exclude:
613613
- 'lib/puppet/configurer.rb'
614614

615-
Lint/FloatComparison:
616-
Exclude:
617-
- 'lib/puppet/pops/types/types.rb'
618-
619615
Lint/HashCompareByIdentity:
620616
Exclude:
621617
- 'lib/puppet/pops/serialization/serializer.rb'

lib/puppet/pops/types/types.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1879,10 +1879,8 @@ def self.new_function(type)
18791879
def from_args(from)
18801880
from = from.downcase if from.is_a?(String)
18811881
case from
1882-
when Float
1883-
from != 0.0
1884-
when Integer
1885-
from != 0
1882+
when Float, Integer
1883+
!from.zero?
18861884
when false, 'false', 'no', 'n'
18871885
false
18881886
else

0 commit comments

Comments
 (0)