Hacker News new | past | comments | ask | show | jobs | submit login

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...



> 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


What about using an actual vector library like Eigen? I wouldn’t dream of reimplementing basic maths like that.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: