4 ms·
If I heard this question, I'd be more confused than anything. The answer seems like it's just return x*x but I'd probably be more interested in why squaring num
by xmprt 5y ago
If I heard this question, I'd be more confused than anything. The answer seems like it's just return x*x but I'd probably be more interested in why squaring numbers is so important that it needs a special function. Maybe I'm supposed to implement a BigInteger class or something like it...
- Jare 5y ago> why squaring numbers is so important that it needs a special function I've had pow2() in pretty much every codebase I'd worked on, ever. pow2(x1-x0) looks nicer and less error prone than (x1-x0)*(x1-x0), and less verbose and distracting than first separating to a local var as dx = x1-x0
- toxik 5y agoWhat about using an actual vector library like Eigen? I wouldn’t dream of reimplementing basic maths like that.