These forums have been archived and are now read-only.

The new forums are live and can be found at https://forums.eveonline.com/

EVE Technology Lab

 
  • Topic is locked indefinitely.
 

Trouble with Manufacturing Formula

First post
Author
Star Killer14
Core World Imperium
#1 - 2015-03-22 20:48:35 UTC
Hello everyone,

First time I have been in this area of the forums so let me know if this would be better asked else where.

I am trying to figure out why the equation isn't working for me, I am almost always 1 material short, a few times I am correct, from when I check it in game. I tried using two different formulas to see if it was a decimal error.

The formula I have found and am trying to replicate is
materialsRequired = max(runs,ceil(round(runs∗baseQuantity∗materialModifier,2))

I am using Java and my exact lines are:

DecimalFormat production = new DecimalFormat("0.###");

double required = Math.max(Math.ceil(Double.parseDouble(production.format(Math.round(runs*22*.882)))),runs);
(Made sure to take 3 deicimals)

double required2 = Math.max(Math.ceil(Math.round(runs*22*.882)),runs);
(Didn't worry about the decimals)

Thanks for any help you can give
Steve Ronuken
Fuzzwork Enterprises
Vote Steve Ronuken for CSM
#2 - 2015-03-23 19:51:46 UTC
Can you give examples where you're short, and when you're correct?

Woo! CSM XI!

Fuzzwork Enterprises

Twitter: @fuzzysteve on Twitter

Star Killer14
Core World Imperium
#3 - 2015-03-23 19:57:38 UTC
I just got it to work. I was using pulse shield emitters as my example from in game and as it turns out I was having rounding issues. I thought this was the problem but I wasn't sure and eventually just did it step by step using a calculator to find where it was messing up. Thanks for the help.
Steve Ronuken
Fuzzwork Enterprises
Vote Steve Ronuken for CSM
#4 - 2015-03-23 20:01:49 UTC
Heh.

doing it with a calculator's what I'd have done. And breaking it out into each of the steps and echoing that out.

got me round a problem I was having with integer division, where it should have been floats.

Woo! CSM XI!

Fuzzwork Enterprises

Twitter: @fuzzysteve on Twitter

Aineko Macx
#5 - 2015-03-29 10:44:38 UTC
Just a headsup: Float precision can bite you in exactly this scenario. Since floats are incapable of representing some integers without precision problems, ceil() will round up some of the values that should actually be integers.

The solution is to do a float modulo dividing your value by 1.0 and checking if the result is smaller than 0.0000000001. If so, you can ignore the discrepancy and apply round(), ceil() otherwise.
Steve Ronuken
Fuzzwork Enterprises
Vote Steve Ronuken for CSM
#6 - 2015-03-29 21:13:51 UTC
Aineko Macx wrote:
Just a headsup: Float precision can bite you in exactly this scenario. Since floats are incapable of representing some integers without precision problems, ceil() will round up some of the values that should actually be integers.

The solution is to do a float modulo dividing your value by 1.0 and checking if the result is smaller than 0.0000000001. If so, you can ignore the discrepancy and apply round(), ceil() otherwise.



The other way to manage it is to throw in a round at 2 decimal place precision, before the ceil.

iirc, it's how CCP manages it.

Woo! CSM XI!

Fuzzwork Enterprises

Twitter: @fuzzysteve on Twitter