Skip to content

Instantly share code, notes, and snippets.

@nerdralph
Created November 12, 2020 23:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nerdralph/f630ba44093241d05bdaf12c11a19a6a to your computer and use it in GitHub Desktop.
Save nerdralph/f630ba44093241d05bdaf12c11a19a6a to your computer and use it in GitHub Desktop.
generate lookup table for powers of 1.414, i.e. sqrt(2)
// Ralph Doncaster 2020 public domain software
// generate lookup table for powers of sqrt(2)
#include <stdio.h>
#include <math.h>
int main()
{
double sqrt2 = sqrt(2.0);
for (double d = 2; d <= 16; d += 1) {
printf( "1.414^%d = %lf\n", (int)d, pow(sqrt2, d) );
}
printf("powers[] = { 0");
for (double d = 2; d <= 16; d += 1) {
printf( ", %d", (int) (pow(sqrt2, d) + 0.5) );
}
printf(" };\n");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment