lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

On Wed, January 25, 2017 13:29, Gabríel Arthúr Pétursson wrote:

>> The os.clock function uses the 'clock' system call. On that particular
>> system you refer to, `clock_t`, the return value of clock, is defined
>> as a 32-bit integer.
>> What you're seeing is that integer wrapping around due to overflow.

Hello again,

   If I may briefly follow up on my original post, here's a vastly
   simpler program that illustrates the issue:


local prevclock, thisclock = 0.0, 0.0

   prevclock = thisclock
   thisclock = os.clock( )
until thisclock < 0

print( prevclock, thisclock )


   On a 32-bit computer, we get:

$ lua clocktest.lua
2147.483647	-2147.483647

   So yes indeed, the value returned by 'os.clock( )' wraps around
   after 2^31-1 microseconds, nicely confirming Gabriel's explanation.


PS: The Royal Society for the Prevention of Cruelty to Computers
    asks that you kindly refrain from running the above program
    on a 64-bit computer :-)

Joseph Manning / Computer Science / UCC Cork Ireland /