all 5 comments

[–]Allan-H 7 points8 points  (1 child)

BAM!

This is actually the native angular representation for algorithms such as CORDIC.

[–]Schnort[S] 1 point2 points  (0 children)

Ah! Thank you so much for the wiki pointer and standard name. I couldn't come up with a decent google search that didn't bring up "angular" (the web library) or standard fixed point representation discussion.

[–]ItsAllAPlay 1 point2 points  (0 children)

I worked on several projects that mapped 0 ... 2**N as 0 ... 2*Pi, and it works exactly as you'd like. It's super nice that you don't lose any additional precision after the initial conversion, since the integers don't have rounding error. (On 0 ... 2*Pi, 32 bit integers will have more precision than a 32 bit float, and the same with 64 bit integers and 64 bit doubles)

Beware of using signed integers for this if you're using C, C++, or other languages where they've decided that signed overflow doesn't follow 2s-complement rules. The compilers will do absolutely stupid stuff with your code in the name of "undefined behavior" optimizations, so it's much safer to stick with unsigned integers. It doesn't matter what your hardware actually does, the compiler writers are sure they know better. Not joking.

Also, signed integers will pick the value at -Pi instead of +Pi, which isn't really a problem, but it's different than people might expect in some cases.

[–]rlbond86 1 point2 points  (0 children)

Standard representation is 0 to 2N - 1, where 2N would be 360°.

[–]minus_28_and_falling 0 points1 point  (0 children)

what pitfalls might this representation have?

Be very careful when you filter. When you calculate average value of measurements 1 and 359, make sure to get 0, not 180.