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.
diff --git a/src/ioq_server.erl b/src/ioq_server.erl
index 2fce2ef..8eb30a0 100644
--- a/src/ioq_server.erl
+++ b/src/ioq_server.erl
@@ -474,7 +474,7 @@
ets:insert(Tab, {Key, Incr})
end.
-timebin(0) ->
+timebin(V) when V =< 0 ->
0;
timebin(V) ->
trunc(10*math:log10(V)).