Skip to content

Commit

Permalink
Protect against NaN's
Browse files Browse the repository at this point in the history
Added warns to try to help us track down what situation is actually causing
this issue.

This is related to Issue eric#13.
  • Loading branch information
eric committed May 20, 2012
1 parent e4cd69e commit a5e526a
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion lib/metriks/exponentially_decaying_sample.rb
Expand Up @@ -80,7 +80,19 @@ def rescale(now, next_time)
@start_time = Time.now
@values.keys.each do |key|
value = @values.delete(key)
@values[key * Math.exp(-@alpha * (@start_time - old_start_time))] = value
new_key = key * Math.exp(-@alpha * (@start_time - old_start_time))

if key.nan?
warn "ExponentiallyDecayingSample found a key of NaN. old_start_time: #{old_start_time.to_f} start_time: #{@start_time.to_f}"
next
end

if new_key.nan?
warn "ExponentiallyDecayingSample found a new_key of NaN. key: #{key} old_start_time: #{old_start_time.to_f} start_time: #{@start_time.to_f}"
next
end

@values[new_key] = value
end
end
end
Expand Down

0 comments on commit a5e526a

Please sign in to comment.