Mapping two integers to one, in a unique and deterministic way

Cantor pairing function is really one of the better ones out there considering its simple, fast and space efficient, but there is something even better published at Wolfram by Matthew Szudzik, here. The limitation of Cantor pairing function (relatively) is that the range of encoded results doesn’t always stay within the limits of a 2N … Read more

How does C compute sin() and other math functions?

In GNU libm, the implementation of sin is system-dependent. Therefore you can find the implementation, for each platform, somewhere in the appropriate subdirectory of sysdeps. One directory includes an implementation in C, contributed by IBM. Since October 2011, this is the code that actually runs when you call sin() on a typical x86-64 Linux system. … Read more

How can I remove the decimal part from JavaScript number?

You could use… Math.trunc() (truncate fractional part, also see below) Math.floor() (round down) Math.ceil() (round up) Math.round() (round to nearest integer) …dependent on how you wanted to remove the decimal. Math.trunc() isn’t supported on all platforms yet (namely IE), but you could easily use a polyfill in the meantime. Another method of truncating the fractional … Read more

How to determine if a list of polygon points are in clockwise order?

Some of the suggested methods will fail in the case of a non-convex polygon, such as a crescent. Here’s a simple one that will work with non-convex polygons (it’ll even work with a self-intersecting polygon like a figure-eight, telling you whether it’s mostly clockwise). Sum over the edges, (x2 − x1)(y2 + y1). If the … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)