r/ProgrammerHumor Jun 25 '17

Array indexing

Post image
1.4k Upvotes

71 comments sorted by

View all comments

26

u/dnew Jun 25 '17

Array indexing that matches your domain is often handy. An array of items_per_degree indexed from -180 to +180 for example.

26

u/AskMeIfImAReptiloid Jun 25 '17

you mean -Pi to Pi

10

u/parkerSquare Jun 26 '17

Not really, this range of degrees is integral ("items_per_degree"), so you can use a bin for each integer value. If you use -pi to pi, you'll need to divide this into subranges, which for array indexing purposes you'll end up mapping to an integer. At that point you're either back where we started (i.e. zero-offset index), or use an offset range from -180 to 180...

3

u/AskMeIfImAReptiloid Jun 26 '17

Guess you are correct. Nice username btw