This Gitlab instance will require Two-Factor-Authentication from 2021-10-01. Read how to enable 2FA.

basicmath_large.c 3.42 KB
Newer Older
kuhnm's avatar
kuhnm committed
1 2
#include "snipmath.h"
#include <math.h>
kuhnm's avatar
kuhnm committed
3
#include <stdio.h>
kuhnm's avatar
kuhnm committed
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21

/* The printf's may be removed to isolate just the math calculations */

int main(void)
{
  double  a1 = 1.0, b1 = -10.5, c1 = 32.0, d1 = -30.0;
  double  x[3];
  double X;
  int     solutions;
  int i;
  unsigned long l = 0x3fed0169L;
  struct int_sqrt q;
  long n = 0;

  /* solve soem cubic functions */
  printf("********* CUBIC FUNCTIONS ***********\n");
  /* should get 3 solutions: 2, 6 & 2.5   */
  SolveCubic(a1, b1, c1, d1, &solutions, x);  
kuhnm's avatar
kuhnm committed
22 23 24 25
  /* printf("Solutions:"); */
  /* for(i=0;i<solutions;i++) */
  /*   printf(" %f",x[i]); */
  /* printf("\n"); */
kuhnm's avatar
kuhnm committed
26 27 28 29

  a1 = 1.0; b1 = -4.5; c1 = 17.0; d1 = -30.0;
  /* should get 1 solution: 2.5           */
  SolveCubic(a1, b1, c1, d1, &solutions, x);  
kuhnm's avatar
kuhnm committed
30 31 32 33
  /* printf("Solutions:"); */
  /* for(i=0;i<solutions;i++) */
  /*   printf(" %f",x[i]); */
  /* printf("\n"); */
kuhnm's avatar
kuhnm committed
34 35 36

  a1 = 1.0; b1 = -3.5; c1 = 22.0; d1 = -31.0;
  SolveCubic(a1, b1, c1, d1, &solutions, x);
kuhnm's avatar
kuhnm committed
37 38 39 40
  /* printf("Solutions:"); */
  /* for(i=0;i<solutions;i++) */
  /*   printf(" %f",x[i]); */
  /* printf("\n"); */
kuhnm's avatar
kuhnm committed
41 42 43

  a1 = 1.0; b1 = -13.7; c1 = 1.0; d1 = -35.0;
  SolveCubic(a1, b1, c1, d1, &solutions, x);
kuhnm's avatar
kuhnm committed
44 45 46 47
  /* printf("Solutions:"); */
  /* for(i=0;i<solutions;i++) */
  /*   printf(" %f",x[i]); */
  /* printf("\n"); */
kuhnm's avatar
kuhnm committed
48 49 50

  a1 = 3.0; b1 = 12.34; c1 = 5.0; d1 = 12.0;
  SolveCubic(a1, b1, c1, d1, &solutions, x);
kuhnm's avatar
kuhnm committed
51 52 53 54
  /* printf("Solutions:"); */
  /* for(i=0;i<solutions;i++) */
  /*   printf(" %f",x[i]); */
  /* printf("\n"); */
kuhnm's avatar
kuhnm committed
55 56 57

  a1 = -8.0; b1 = -67.89; c1 = 6.0; d1 = -23.6;
  SolveCubic(a1, b1, c1, d1, &solutions, x);
kuhnm's avatar
kuhnm committed
58 59 60 61
  /* printf("Solutions:"); */
  /* for(i=0;i<solutions;i++) */
  /*   printf(" %f",x[i]); */
  /* printf("\n"); */
kuhnm's avatar
kuhnm committed
62 63 64

  a1 = 45.0; b1 = 8.67; c1 = 7.5; d1 = 34.0;
  SolveCubic(a1, b1, c1, d1, &solutions, x);
kuhnm's avatar
kuhnm committed
65 66 67 68
  /* printf("Solutions:"); */
  /* for(i=0;i<solutions;i++) */
  /*   printf(" %f",x[i]); */
  /* printf("\n"); */
kuhnm's avatar
kuhnm committed
69 70 71

  a1 = -12.0; b1 = -1.7; c1 = 5.3; d1 = 16.0;
  SolveCubic(a1, b1, c1, d1, &solutions, x);
kuhnm's avatar
kuhnm committed
72 73 74 75
  /* printf("Solutions:"); */
  /* for(i=0;i<solutions;i++) */
  /*   printf(" %f",x[i]); */
  /* printf("\n"); */
kuhnm's avatar
kuhnm committed
76 77 78 79 80 81 82

  /* Now solve some random equations */
  for(a1=1;a1<10;a1+=1) {
    for(b1=10;b1>0;b1-=.25) {
      for(c1=5;c1<15;c1+=0.61) {
	   for(d1=-1;d1>-5;d1-=.451) {
		SolveCubic(a1, b1, c1, d1, &solutions, x);  
kuhnm's avatar
kuhnm committed
83 84 85 86
		/* printf("Solutions:"); */
		/* for(i=0;i<solutions;i++) */
		/*   printf(" %f",x[i]); */
		/* printf("\n"); */
kuhnm's avatar
kuhnm committed
87 88 89 90 91 92 93 94 95 96 97 98 99
	   }
      }
    }
  }


  printf("********* INTEGER SQR ROOTS ***********\n");
  /* perform some integer square roots */
  for (i = 0; i < 100000; i+=2)
    {
      usqrt(i, &q);
			// remainder differs on some machines
     // printf("sqrt(%3d) = %2d, remainder = %2d\n",
kuhnm's avatar
kuhnm committed
100 101
     /* printf("sqrt(%3d) = %2d\n", */
     /* 	     i, q.sqrt); */
kuhnm's avatar
kuhnm committed
102 103 104 105 106 107
    }
  printf("\n");
  for (l = 0x3fed0169L; l < 0x3fed4169L; l++)
    {
	 usqrt(l, &q);
	 //printf("\nsqrt(%lX) = %X, remainder = %X\n", l, q.sqrt, q.frac);
kuhnm's avatar
kuhnm committed
108
	 /* printf("sqrt(%lX) = %X\n", l, q.sqrt); */
kuhnm's avatar
kuhnm committed
109 110 111 112 113
    }


  printf("********* ANGLE CONVERSION ***********\n");
  /* convert some rads to degrees */
kuhnm's avatar
kuhnm committed
114
  /*   for (X = 0.0; X <= 360.0; X += 1.0) */
kuhnm's avatar
kuhnm committed
115
  for (X = 0.0; X <= 360.0; X += .001)
kuhnm's avatar
kuhnm committed
116 117
    deg2rad(X);
    /* printf("%3.0f degrees = %.12f radians\n", X, deg2rad(X)); */
kuhnm's avatar
kuhnm committed
118 119 120
  puts("");
/*   for (X = 0.0; X <= (2 * PI + 1e-6); X += (PI / 180)) */
  for (X = 0.0; X <= (2 * PI + 1e-6); X += (PI / 5760))
kuhnm's avatar
kuhnm committed
121 122
    rad2deg(X);
    /* printf("%.12f radians = %3.0f degrees\n", X, rad2deg(X)); */
kuhnm's avatar
kuhnm committed
123 124 125 126
  
  
  return 0;
}