# Solved Math issues

Discussion in 'Spigot Plugin Development' started by MrDienns, Apr 16, 2017.

1. ### MrDienns

I have a starting value of 1000

This value must be multiplied by 1.5 (or 50%) for an x given amount of times.

So for example:

I want to multiply 1000 by 50% for 34 times.

Example: 1000 > 1500 > 2250 > ....

Please note that I'm using BigIntegers for this instead of normal Integers.

I'm unable to figger this out in Java code. Any help would be great.

2. ### DizMizzer

1000*1.5^n where N is the amount of times

3. ### Photon Supporter

1000 * Math.pow(1.5, x), given x as your variable. Use a long for this.

4. ### xTimPugz

Just make a for loop and do this calculation in there. Something like this:
Code (Text):

double base = 1000;
for(int i = 0; i < x; i++) base *= 1.5;

If this is wrong tell me, it's a quick draft.

• Like x 1
5. ### finnbon

You're not wrong but see the previous replies to see why you're not right either.

6. ### ExpDev

This isn't the way you would go about it. What @DizMizzer & @Photon suggests would be the appropriate way.

8. ### ExpDev

I would assume so. And easier and more convenient, but I'm checking it now

9. ### xTimPugz

I'm quite sure that their way under the hood also uses a for loop. I could be wrong though.
In my little time as a developer one of the few things I understood is that performance is everything!
Thanks

• Like x 1
10. ### DizMizzer

Our way is faster because we aren't storing the variable over and over. This is also basic math not really programming

11. ### xTimPugz

Could be, the thing is this is a more direct approach with indeed more code (which is a bad thing).

12. ### ExpDev

Test finished. Actually not as expected.
Code (Text):
1 - Result: 1.9175105923288408E8. Operation took 768 nano seconds.
2 - Result: 1.9175105923288408E8. Operation took 13056 nano seconds.
1 = Your method @xTimPugz.
2 = @Photon 's method

Code if you wanna try it yourself.

EDIT: So basically, double as fast. Considerably faster for a computer, but not noticeable to a human eye.

EDIT 2: @xTimPugz take a look at the edit. That's pretty odd. Your method proved to be faster. I just confused the results with my ignorance.

EDIT 3: @DizMizzer , @xTimPugz 's method is actually faster

#12
Last edited: Apr 16, 2017
• Informative x 1
13. ### MrDienns

Thanks for all the help! I got it working.

I'll have to think of a better formula to generate a required exp amount. When a player reaches level 90, it needs 9223372036854775807 (actual number) exp points to become level 91...

14. ### xTimPugz

Well yeah I guess that's because under the hood 5 to the power of 5 is just the same as 5 * 5 * 5 *5 *5.

• Like x 2
15. ### ExpDev

Haha, glad you proved them wrong (me, as well)

16. ### xTimPugz

I don't really care about that haha I just want to enjoy my time on the forums and help around where I can hehe. Just thought it'd be helpful.

• Like x 1