Timstamp problem

Discussion of Inner Space

Moderators: Lavish Software Team, Moderators

Post Reply
Jon100
Non-Subscriber
Posts: 32
Joined: Wed Nov 24, 2004 1:38 pm

Timstamp problem

Post by Jon100 » Mon Jul 28, 2008 5:44 am

I'm getting a wierd bug in some of my code, in which I am setting a bailout timer (the time to stop doing something). Depending on which way I set it I can get up to a minute's difference in time, which I can't explain.

In the example below bailout is being set to now + 5mins. Using the Inc[300] method it works correctly, but using +300 I get a number which is between 4:00 and 4:59 ahead of now! If I set myTime to a random int value, all three method sucessfully add 300 (seconds) to it.

Just doing echo ${Math.Calc[${Time.Timestamp}+300]} repeatedly shows that we are getting the same number for an entire minute, where it should be updating every second!

Why does this happen?

Code: Select all

function main()
{
	declare myTime int local ${Time.Timestamp}
	declare bailout int local

	consoleclear
	echo now=${myTime}
	
	bailout:Set[${myTime}+300]
	echo "5mins=${bailout} (Plus operator)"

	bailout:Set[${Math.Calc[${myTime}+300]}]
	echo "5mins=${bailout} (Math.Calc)"

	bailout:Set[${myTime:Inc[300]}]
	echo "5mins=${bailout} (Inc method)"
}
now=1217241352
5mins=1217241600 (Plus operator)
5mins=1217241600 (Math.Calc)
5mins=1217241652 (Inc method)
Jon100 / Dorset
"No of course I don't use that macro thingy to 6 box... I just use 6 keyboards at once..."

Lax
Owner
Posts: 6634
Joined: Fri Jun 18, 2004 6:08 pm

Post by Lax » Mon Jul 28, 2008 3:39 pm

Math.Calc is doing 64-bit floating point calculations. When doing timestamp math (or other whole number/integer math) you will be better off using Math.Calc64, which is doing 64-bit integer calculations.

Jon100
Non-Subscriber
Posts: 32
Joined: Wed Nov 24, 2004 1:38 pm

Post by Jon100 » Tue Jul 29, 2008 2:25 am

Thanks Lax :)
Jon100 / Dorset
"No of course I don't use that macro thingy to 6 box... I just use 6 keyboards at once..."

Post Reply