tags:

views:

144

answers:

2

I have the following C formula

bucket = (hash - _min) * ((_capacity-1) / range());

What I need to to rearrange the equation to return the _capacity instead of bucket (I have all other variables apart from _capacity). e.g.

96 = (926234929-805306368) * (( x -1) /1249540730)
836 = (1852139639-805306368) * ((x -1) /1249540730)

As you can see it's a fairly simple equation, all I need is x on the left. But my algebra is very rusty, so any help appreciated.

+6  A: 
capacity = (range() * bucket) / (hash - _min) + 1;

bucket = (hash - _min) * ((_capacity - 1) / range()); // start
bucket = ((hash - _min) * (_capacity - 1)) / range(); // rearrange
range() * bucket = (hash - _min) * (_capacity - 1); // multiply by range
(range() * bucket) / (hash - _min) = _capacity - 1; // divide by (hash - _min)
(range() * bucket) / (hash - _min) + 1 = _capacity; // add 1
capacity = (range() * bucket) / (hash - _min) + 1; // rearrange
GMan
You ninja'd me.
Renesis
Thats great, Thanks
Ben Reeves
I'm having flashbacks of my old algebra class.
Robert Harvey
+1  A: 
_capacity = 1 + bucket / (hash - _min) * range();

with the provision that hash can no longer equal _min.

wallyk
true.. but even in teh first case you'd only get 0 out as an answer.. but thats better then a DIVIDE_ZERO error
ShoeLace
If `hash` equals `_min` then in the first eq `bucket` would also be 0. That would make this equation 0/0. Which makes me wonder... why aren't computers smart enough to realize that 0/0 is not an error, it's just 0? Any equation that's valid in one form should be valid in any other form, if that form is truly equal.
Renesis
@Renesis, because sometime 0/0 = 1. Seriously. http://www.codeproject.com/KB/recipes/float_point.aspx (3rd paragraph after "Worry about Addition and Subtraction more than Multiplication and Division" for the impatient)
mctylr
@Renesis: 0/0 has nothing to do with computers being "smart enough to figure out it's 0". 0/0 is undefined; meaningless. It's not 0, nor is it anything. It just doesn't make sense. In this particular case, 0 happens to work out.
GMan
Maybe I'm just not smart enough to see why 0/0 would not be equal to 0 (if both zeros are really zero, not zero because of some precision error).
Renesis
Sounds like NAN to me.
duffymo
@Renesis, you can't see why 0/0 would not be equal to zero? The correct term for it is "indeterminant": http://mathworld.wolfram.com/Indeterminate.html
duffymo
@Renesis: 0/0 is not 0; it's meaningless. Put another way, `x = 0/0` implies that `0 = x * 0`. That's true for *every* value of x, not just 0. There is no single value that maps to 0/0, hence why it's undefined.
John Bode
@John Bode... The way you put it makes sense, thanks.
Renesis
@duffymo - Some of those values make a lot of sense, like infinity/infinity or infinity-infinity. Some of them, like infinity^0, or 1^infinity seem like they should be able to be determined.
Renesis
@Renesis: If they "make sense", why does MathWorld call them "indeterminant"? "Seem" feels like an appeal to "common sense", but that's not what a mathematician would say.
duffymo
@Renesis: Infinity is a concept, not a number. It doesn't make sense to ave infinity^0 or 1^infinity any more than it makes sense to have love^0 or 1^happiness.
GMan
"Some of those values make a lot of sense, like infinity/infinity or infinity-infinity" - let's ask Georg Cantor what he thinks: http://en.wikipedia.org/wiki/Georg_Cantor
duffymo
@duffymo I meant makes sense that they are indeterminant.
Renesis
@Gman, I'm sure if you started to use love or happiness in your equations in Calculus class you would fail.
Renesis
@Renesis: Indeed. Any time you see infinity used in place of a number, it's merely a useful notation, and not intended to be taken as a number.
GMan
@Renesis: " why aren't computers smart enough to realize that 0/0 is not an error, it's just 0?" - this statement doesn't give me confidence that you understand the issue. It's not a question of whether or not computers are smart enough; it simply can't be done. The equation isn't equal to zero, as you claimed.
duffymo
@duffymo - Didn't I specifically state that I _don't_ understand the issue? My point was that if 0/0 can be proven to equal 0, why a case wouldn't be made in the arithmetic operations for this. Obviously, as finally explained by John Bode... it is proven not to equal 0.
Renesis
@Renesis, examine this graph of f(x)=1/x and tell explain what value you'd choose for x=0: http://id.mind.net/~zona/mmts/functionInstitute/rationalFunctions/oneOverX/oneOverX.html
wallyk
@wallyk - That makes perfect sense. However, now graph f(x)=0/x -- in that graph, it seems like it would be easy to predict what the value what be for x=0 (which is the case I was originally talking about -- 0/0 not 1/0).
Renesis
@Renesis: It's true that the limit as x approaches 0 of 0/x is 0, but at 0 it is still indeed indeterminate. But I think it's clear you understand the issue anyway. :p
GMan