now() and arithmetic

Per Hedeland per@REDACTED
Mon May 6 14:00:03 CEST 2002


"Bruce Fitzsimons" <Bruce@REDACTED> wrote:
>
>PS Here are my amazingly simple routines.
>
>now_to_timeval() ->
>    now_to_timeval(now()).
>
>now_to_timeval({MegaSecs, Secs, MicroSecs}) ->
>    {MegaSecs*1000000+Secs, MicroSecs}.
>
>timeval_to_now({Secs, MicroSecs}) ->
>    {trunc(Secs / 1000000), Secs rem 1000000, MicroSecs}.

Hm, any particular reason you want timevals? If you want to calculate
differences, they're only marginally less awkward than now() values.
Since you have bignums, you could just convert into microseconds instead
- and bignums will be used for your timeval-seconds in any case.

If bignums had existed in Erlang when now() was implemented, it would
probably just have returned a single integer instead (and then Ulf would
have requested the current implementation for efficiency reasons:-).

--Per Hedeland
per@REDACTED



More information about the erlang-questions mailing list