Modulo function

Alhifar

Member
Does anybody know if I'm doing something wrong while using the mod (%) operator? I'm trying to calculate the current time from a timestamp for use in a log file, but the following script is outputting an incorrect result.
This:
Code:
void main()
{
	print(1231377629%86400);
}

Outputs:
Code:
4864.0

While google tells me that 1231377629 % 86400 = 4829. Anybody have any ideas?

EDIT: This is on r6733 if it matters.
 

Veracity

Developer
Staff member
How peculiar.

Code:
int a = 1231377629;
int b = 86400;

int c = a / b;
int d = a % b;

print( "a / b = " + c );
print( "a % b = " + d );
print( "a - b * (a / b ) = " + ( a - (b * c ) ) );

gives

> mod.ash

a / b = 14252
a % b = 4864
a - b * (a / b ) = 4829

Edit: actually, it becomes clear when we see the floating point result you got - which is confirmed by looking at the code. It's converting the numbers to floats - not even doubles - and losing precision.

I'll look into it.

Edit: Fixed in 6739. Yikes.
 
Top