Skip to content

Instantly share code, notes, and snippets.

@bit-hack
Created September 27, 2018 00:20
Show Gist options
  • Save bit-hack/5344ee502e891b3df0aef771230f31b9 to your computer and use it in GitHub Desktop.
Save bit-hack/5344ee502e891b3df0aef771230f31b9 to your computer and use it in GitHub Desktop.
Taylor seried to calculate pi in fixed point
#include <stdint.h>
int main() {
const int32_t fx = 1048576;
int32_t z = 4 * fx;
int32_t j = -1;
for (int32_t i = 3; i < 4096; i += 2) {
z += j * (4 * fx) / i;
j = j * -1;
}
const float pi = float(z) / float(1 * fx);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment