Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

If we're on embedded hardware, or can't use floats for some reason, we use 22/7. It's called fixed point arithmetic. Most CPUs have an integer instruction that multiplies into a double-precision integer result, and an instruction that takes a double-precision integer dividend.

So to scale by pi, we multiply by 355, then divide by 113.



Is that any better than just multiplying by pi * 2^n and then shifting right by n?




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

Search: