Hendricks266, on 18 September 2012 - 11:53 PM, said:
Should be simple. What should the names of these commands be? {l,}distxyz?
Adding these seems sensible, since what we have now with
dist and
ldist can lead to kind of API-inverted code ("set sprite positions, call
dist, reset positions." Ugh.)
By the way, they compute pretty crude approximations to the hypotenuse length, for example
ldist is
125/128 * max(x,y) + 53/128 * min(x,y).
See the second answer for
this question on stackoverflow for the idea behind it (53/128 = 0.41406, sqrt(2)-1 = 0.41421, approximately).
Quote
I'm less sure about those ones being useful. The composite ones like "sin(a - b)" can make sense in a floating point setting, where computing them in a special fashion may significantly increase accuracy, but with integers being the only numeric type in CON, there's not much to be gained. For the hypotenuse length, we have
calchypotenuse (unwieldy long name for fear of name collisions). I'm not very happy with the way it turned out though, it currently has a discontinuity at the squared hypotenuse equalling INT32_MAX. X raised to the Y
th power is something that CON is missing, but again, with only integers there doesn't seem to be much use for it, since you'd most often use Y=2 or Y=3.
Mod and
abs would not add anything really new. This leaves the tangent and the logarithm: the first can be calculated by a ratio of the sine to the cosine (with appropriate scaling), and a base-2 log could be useful (but possible to code as loop currently
[*]), the natural one looking out of place again.
[*]edit: I'm thinking about the rounded variety here, like "log2(9)=3".