Page 1 of 1

Old bug in macros.h

Posted: 02 Jun 2006 23:02
by ASM
There is a bug in CHANCE16 macros which causes industry growth miscalculation with smooth economy. Its in SVN since revision 1.
Patch for 0.4.7 attached, should apply to trunk too.

Re: Old bug in macros.h

Posted: 03 Jun 2006 02:26
by Ryalla
ASM wrote:There is a bug in CHANCE16 macros which causes industry growth miscalculation with smooth economy. Its in SVN since revision 1.
Patch for 0.4.7 attached, should apply to trunk too.
If it's been in macros.h since revision 1, how do you know it's an error? :P

Re: Old bug in macros.h

Posted: 03 Jun 2006 12:39
by ASM
Ryalla wrote:If it's been in macros.h since revision 1, how do you know it's an error? :P
Because it makes smooth economy unusable :(
With it we have 20/1024 chance of production decrease and same chance of production increase, so industries doesn't grow at all.

Re: Old bug in macros.h

Posted: 04 Jun 2006 10:15
by SirkoZ
ASM wrote:
Ryalla wrote:If it's been in macros.h since revision 1, how do you know it's an error? :P
Because it makes smooth economy unusable :(
With it we have 20/1024 chance of production decrease and same chance of production increase, so industries doesn't grow at all.
Indeed it is - smooth economy without my improved patch (didn't touch the macros though) is totally unusable - industries mostly decrease if they are being used and increase if they are not used... :-S

At any rate - I'll test your patch...

Posted: 04 Jun 2006 12:03
by SirkoZ
Wow - it's already been included into trunk...

It works - quite nicely - now 2 more bugs with the current smooth_economy - IT_FARM_2 = tropical maize_farm doesn't plant any fields and once industry production decreases to 32/40 units per month it does not increase anymore, which is annoying - here is a quick fix for those 2 bugs.

Posted: 19 Jun 2006 21:29
by henrik
And this is why macros are evil and should rarely be used. Inline functions are so much better for this kind of thing!

Posted: 19 Jun 2006 21:45
by MeusH
Can anyone explain me the patch by ASM? How do a and (a) differ?

Posted: 19 Jun 2006 21:58
by SirkoZ
henrik wrote:And this is why macros are evil and should rarely be used. Inline functions are so much better for this kind of thing!
Oh cry me a river - it's fixed now, ain't it?

Posted: 19 Jun 2006 22:00
by SirkoZ
MeusH wrote:Can anyone explain me the patch by ASM? How do a and (a) differ?
It takes into account all of the a, especially if a is something like
x + ((20 * pct_transported) >> 8 ). ;-)

Posted: 20 Jun 2006 18:44
by hertogjan
MeusH wrote:Can anyone explain me the patch by ASM? How do a and (a) differ?
It's about what happens at the precompiling stage. Suppose you have the code

Code: Select all

#define SQUARE(a) a*a
which you want to use to square a number.
Now if you put in something like

Code: Select all

SQUARE(2+3);
it is changed to 2+3*2+3 (it just replaces a by 2+3), which equals 11, and not 25 which you were after. To prevent this from happening, you'll have to define

Code: Select all

#define SQUARE(a) (a)*(a)
Now

Code: Select all

SQUARE(2+3);
will be changed to (2+3)*(2+3), yielding the correct result 25.

[edit]Whoops. Don't forget to check when copy-pasting next time :mrgreen:[/edit]

Posted: 20 Jun 2006 19:00
by glx

Code: Select all

#define SQUARE(a) (a)*(a)
return the correct value :)

Posted: 20 Jun 2006 19:09
by Darkvater
glx wrote:

Code: Select all

#define SQUARE(a) (a)*(a)
return the correct value :)
Let's turn it into this, shall we? ;)

Code: Select all

#define SQUARE(a) ((a)*(a))

Posted: 20 Jun 2006 20:42
by MeusH
Thank you so much for answers :)