Nestharus
o-o
- Reaction score
- 83
After much effort, I've come up with this for lossy compression in save/load ; ).
Lossy compression is commonly used on hero experience, hero x,y coordinates, and player gold. The most common equation for gold is R2I(gold/100), which cuts off the last 2 digits. The problem with this is that it fails with smaller values.
The equation I present will still get the max of 10,000 for gold like the above but with better results ; ).
This does lose accuracy, but it's extremely good and works on any size numbers.
You can also compress multiple times.
The current exponents I have set up seem to be the magic numbers ; ).
Demonstration:
995995 -> 9973
9973 -> 995952
As can be seen, rather than getting 995000, 995952 was retrieved, which is quite a bit closer to the real value.
123456 -> 2479
2479 -> 123428
357832393 -> 504026
504026 -> 357832192
Side by side
357832393
357832192
Yes, the retrieved value is only 201 off from the actual number while storing a 9 digit number as a 6 digit number.
Lossy compression is commonly used on hero experience, hero x,y coordinates, and player gold. The most common equation for gold is R2I(gold/100), which cuts off the last 2 digits. The problem with this is that it fails with smaller values.
The equation I present will still get the max of 10,000 for gold like the above but with better results ; ).
JASS:
library CompressInt
//performs lossy compression on integers
//compressed number = number^(2/3)
//decompressed number = roundDown(number^1.5+.5)
function CompressInt takes integer n returns integer
return R2I(Pow(n,2/3.))
endfunction
function DecompressInt takes integer n returns integer
return R2I(Pow(n,1.5)+.5)
endfunction
endlibrary
This does lose accuracy, but it's extremely good and works on any size numbers.
You can also compress multiple times.
The current exponents I have set up seem to be the magic numbers ; ).
Demonstration:
995995 -> 9973
9973 -> 995952
As can be seen, rather than getting 995000, 995952 was retrieved, which is quite a bit closer to the real value.
123456 -> 2479
2479 -> 123428
357832393 -> 504026
504026 -> 357832192
Side by side
357832393
357832192
Yes, the retrieved value is only 201 off from the actual number while storing a 9 digit number as a 6 digit number.