There are two basic ways to store such things (pile of same type while averaging quality):
You have to store an amount (A) anyway (increment on pit and decrement on get), so we can forget about this.
The other value is the quality (Q), i use only one in this example with Qi as quality of item added/removed:
1) Store average quality (Qa)
Put: Qa=floor((Qa*A+Qi)/(A+1)), A+=1
Get: A-=1, return Qa
Needs memory location to hold Qmax.
Returns possibly less total q than put in, q is same for all items returned, order of insertion matters.
Option is to store more digits after the decimal point to lessen the problem, needing more memory to hold the fractions.
2) Store sum of quality (Qs)
Put: Qs+=Qi, A+=1
Get: q=floor(Qs/A), Qs-=q, A-=1, return q
Needs memory location to hold (Amax*Qmax).
Returns total q put in, items returned might oscillate +/- 1 in q, order of insertion irrelevant.
According to the effects we see we currently have 1).
Given that the extra memory for 2) is one extra byte for piles <2^8 items, or none in case 1) stores fractions, storage is cheap these days, plus the math is cheaper for 2)... I would like to have the second solution.
-
Granger
- Posts: 9255
- Joined: Mon Mar 22, 2010 2:00 pm
Re: Combining liquids/powders results in overall lower QL
⁎ Mon Mar 22, 2010 ✝ Thu Jan 23, 2020
-
Sever
- Posts: 723
- Joined: Fri Aug 28, 2009 8:38 pm
- Location: Elsewhere
Re: Combining liquids/powders results in overall lower QL
One's a 32 bit integer, the other's a 32 bit float. I don't think storing the variable is the problem, it's constantly doing floating point operations and the weird things that can happen with error.
Of course it's probably not those things because I am not a programmer.
Of course it's probably not those things because I am not a programmer.
Come back two hours earlier.
-
Granger
- Posts: 9255
- Joined: Mon Mar 22, 2010 2:00 pm
Re: Combining liquids/powders results in overall lower QL
One wouldn't want to use floats for stuff like that, you'll run into numeric instabilities.Sever wrote:Of course it's probably not those things because I am not a programmer.
http://floating-point-gui.de/ could be a starting point in case you're interested why.
Also loftar well might have cut memory useage by using smaller locations for the values.
Why, for example, should you reserve longint when you know a byte will do?
⁎ Mon Mar 22, 2010 ✝ Thu Jan 23, 2020
-
g1real
- Posts: 881
- Joined: Sun Aug 09, 2009 10:30 am
- Location: You are now breathing manually.
Re: Combining liquids/powders results in overall lower QL
welp


loftar: The inner chaos of the Jorbian mind is hard to conceal. 
jorb: It's called creative license. You know, that thing you seem to want to apply to logic, grammar and coherence?
jorb: It's called creative license. You know, that thing you seem to want to apply to logic, grammar and coherence?
-
loftar
- Posts: 9096
- Joined: Fri Apr 03, 2009 7:05 am
- Location: Your character database
Re: Combining liquids/powders results in overall lower QL
I don't understand that screenshot either. What are you mixing, what were the results, and what results were you expecting?g1real wrote:welp
"Object-oriented design is the roman numerals of computing." -- Rob Pike
-
g1real
- Posts: 881
- Joined: Sun Aug 09, 2009 10:30 am
- Location: You are now breathing manually.
Re: Combining liquids/powders results in overall lower QL
Well I would think it was rather obvious that I threw all the carrot seeds in that barrel, that seem to be dominantly in the Qa 7-9 range, and I got Qa 4 out. What I would expect is for it to give me a Qa around 8.loftar wrote:I don't understand that screenshot either. What are you mixing, what were the results, and what results were you expecting?g1real wrote:welp
Edit: I've noticed that adding 1 seed of similar but slightly lower quality to a stack of 4 doesn't lower quality, hurray, do I have to meticulously add 1 seed every time just to avoid tanking my quality?
Edit2: Nevermind, even adding 1 seed reduces quality, amber's client didn't update displayed quality until I picked it up.
loftar: The inner chaos of the Jorbian mind is hard to conceal. 
jorb: It's called creative license. You know, that thing you seem to want to apply to logic, grammar and coherence?
jorb: It's called creative license. You know, that thing you seem to want to apply to logic, grammar and coherence?