[erlang-bugs] erlang:monotonic_time() is negative

Jesper Louis Andersen jesper.louis.andersen@REDACTED
Tue Sep 1 15:43:03 CEST 2015


On Tue, Sep 1, 2015 at 2:20 PM, Sergej Jurečko <sergej.jurecko@REDACTED>
wrote:

> Using 18.0.3 on OS X 10.10.5. I even tried rebooting the machine to check
> if the time turns negative after a while, but it seems it is always
> negative.
>
> erlang:monotonic_time().
> -576460736152226213
>

This is the normal behavior. In order to use the full 60 bit signed value,
it is custom to start at a negative number when starting a new Erlang node:

1> os:type().
{unix,freebsd}
2> erlang:monotonic_time().
-576460743520961806

1> os:type().
{unix,sunos}
2> erlang:monotonic_time().
-576460744933281955

And so on. You can only use monotonic_time() for doing checks relative to
itself, as in:

B = erlang:monotonic_time(),
do_work(),
E = erlang:monotonic_time(),
Elapsed = erlang:convert_time_unit(E - B, native, micro_seconds),
...

As Loic writes, check the document on time and time correction.



-- 
J.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-bugs/attachments/20150901/78d1853f/attachment.htm>


More information about the erlang-bugs mailing list