SRL Archive - OSR Help

Just simple gp/hour for proggy


djborec

2012-02-05 19:03:01

Hello , i have this method for counting gp per hour for my proggy in script, but after some time it starts to show negative numbers instead of real gp/hour.

Its working like 15-20minutes and then starts showing negative numbers.
What could be wrong with it?

here is part of proggy:
 WriteLn(' Money per Hour: ' +ToStr(((3600000*iTabsMade)/GetTimeRunning)*194));

lilcmp1

2012-02-05 19:23:52

What does iTabsMade look like? Since TimeRunning isn't negative that's the only place I'd think a negative could occur.

djborec

2012-02-05 19:27:11

From: lilcmp1
What does iTabsMade look like? Since TimeRunning isn't negative that's the only place I'd think a negative could occur.


Well iTabsMade is used only once in the end of procedure make tabs , and in form

iTabsMade:=iTabsMade+26; 

so I do not think that it could goes to negative.


Not sure about TimeRunning and how it works.

Nebula

2012-02-05 21:57:54

this should work:

GPPH := Round((GP * 3600) / (GetTimeRunning / 1000));

Er1k

2012-02-05 23:24:18

I will just explain why it wouldn't work with the first line.

(3600000*iTabsMade)/GetTimeRunning)*194

Math operations are calculated from left to right (unless overriden by parentheses).
You got an numerical overflow from the first multiplication 3600000 * something, so it will show negative numbers.

Nebula has shown one correct way of doing this. Divide one hour by gettimerunning first before multiplying your other params.

When doing multiplication with large numbers, think about the magnitude you're dealing with before deciding the order of the operations.

djborec

2012-02-06 04:58:05

From: nosaj.421
I will just explain why it wouldn't work with the first line.

(3600000*iTabsMade)/GetTimeRunning)*194

Math operations are calculated from left to right (unless overriden by parentheses).
You got an numerical overflow from the first multiplication 3600000 * something, so it will show negative numbers.

Nebula has shown one correct way of doing this. Divide one hour by gettimerunning first before multiplying your other params.

When doing multiplication with large numbers, think about the magnitude you're dealing with before deciding the order of the operations.


Thanks . I thought there could be problem with that ,but I did not realize how big can be that number.