开发者

reverse formula conversion

I have a formula which calculate position for Y, here it is:

double y = ...;
double minX = ..;
double scaleY = ..;
int MAX_COORD = (1 << 16) - 1;
int sy = ~(int)((y - minY) / scaleY * MAX_COORD) & 0xFFFF;

and now i have sy, and i need to calculate y like this:

y = (sy * scaleY) / MAX_COORD + minY;

but conversion is not equals.. i think it because I don't know 开发者_开发问答how to converse ~ and & operators.


~x is -x-1, it is it's own inverse.

x & 0xffff is the same as x % 65536. Since several values can map to the same result you cannot invert it, but if the result is in the proper range you can just treat it like the identity, i.e. leave it out.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜