Skip to content
Permalink
Browse files
Guard against negative time deltas
Despite the use of `erlang:monotonic_time/0`, it is still possible on
some platforms, such as sleeping/awakening laptops, for time to move
in surprising directions. When this happens, and a negative time delta
is passed to `timebin/1`, it crashes with:

bad arithmetic expression at math:log10/1 <= ioq_server:timebin/1(line:480)

This adds a guard to return `0` for negative numbers as well as zero.
  • Loading branch information
jaydoane committed Apr 5, 2022
1 parent a91feea commit 7c6cd10040db2b11adde2232512adec1f6842404
Showing 1 changed file with 1 addition and 1 deletion.
@@ -474,7 +474,7 @@ upsert(Tab, Key, Incr) ->
ets:insert(Tab, {Key, Incr})
end.

timebin(0) ->
timebin(V) when V =< 0 ->
0;
timebin(V) ->
trunc(10*math:log10(V)).

0 comments on commit 7c6cd10

Please sign in to comment.