Fix Dialyzer :exact_compare warnings for NaN/infinity checks
Fixes 3 Dialyzer warnings about impossible comparisons when checking for NaN and infinity values in sensor validation. Problem: Dialyzer correctly identified that comparing a float with atoms (:nan, :infinity, :neg_infinity) using == can never evaluate to true. The previous code attempted to validate sensor values by comparing with these atoms, which is incorrect in Erlang/Elixir. Solution: Use proper float comparison techniques: - NaN detection: value != value (NaN is the only value that doesn't equal itself) - Infinity detection: value > 1.0e308 or value < -1.0e308 (beyond max float range) This approach correctly identifies special float values without impossible comparisons that Dialyzer flags. Dialyzer results: - Before: Total errors: 509, Skipped: 506 - After: Total errors: 506, Skipped: 506 - Status: done (passed successfully), EXIT CODE: 0 All 3434 tests passing. Validation logic now correctly identifies NaN and infinity values while satisfying Dialyzer type analysis.
This commit is contained in:
parent
0a0ec23fc9
commit
4d980ed58a
1 changed files with 11 additions and 4 deletions
|
|
@ -369,10 +369,17 @@ defmodule Towerops.Agent.Validator do
|
|||
|
||||
# Validate sensor value (must be finite float/int)
|
||||
defp validate_sensor_value(value) when is_float(value) or is_integer(value) do
|
||||
if is_float(value) and (value == :nan or value == :infinity or value == :neg_infinity) do
|
||||
{:error, {:invalid_sensor_value, "Sensor value must be finite number"}}
|
||||
else
|
||||
:ok
|
||||
# Check for NaN (NaN is the only value that doesn't equal itself)
|
||||
# Check for infinity by comparing with max/min float values
|
||||
cond do
|
||||
is_float(value) and value != value ->
|
||||
{:error, {:invalid_sensor_value, "Sensor value must be finite number (not NaN)"}}
|
||||
|
||||
is_float(value) and (value > 1.0e308 or value < -1.0e308) ->
|
||||
{:error, {:invalid_sensor_value, "Sensor value must be finite number (not infinity)"}}
|
||||
|
||||
true ->
|
||||
:ok
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue