Hi guys, so I took it up on Slava's words,
I haven't tested much as I just wrote it.
But it seems like it works. (i think the calculation is ok too, but my
math is lousy so..)
there are two versions, one is based on an array, the other on a hashtable.
anyway, you can see it as public domain, if you want to refine and put
in the library, go ahead.