Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.19 KB | None | 0 0
  1. /*
  2. *
  3. CSC 1350 lab #6
  4. @author Brandon Do
  5. @since 10/22/2019
  6. Course: CSC 1350 Section: 3
  7. Instructor Dr. Duncan
  8.  
  9. */
  10. public class AuxMath {
  11.  
  12. public static double nLog(double x){
  13.  
  14. if (x < 0 )
  15. return Double.NaN;
  16.  
  17. double y,o;
  18. double z = 0;
  19. for(double i = 1; i < 10000; i+=2){
  20.  
  21. y = ((x - 1) / (x + 1));
  22. o = y;
  23. for(double t = 1; t < i; t++){
  24. o = o * y;
  25. }
  26. o = (o * (1 / i));
  27. z += o;
  28. }
  29. z *= 2;
  30.  
  31. return z;
  32.  
  33. }
  34.  
  35. public static double xpon(double x){
  36. double f = 3, y = 2, o, z = 0;
  37.  
  38. for(int i = 1; i < 400; i++){
  39. o = x;
  40. //find x^i
  41. for(double t = 0; t < i; t++){
  42. o = o * x;
  43. }
  44. // x^i / y
  45. o = (o / y);
  46.  
  47. // Add to total
  48. z += o;
  49.  
  50. // Calcualte y (2 * 3 * 4 * 5 * 6 * ...)
  51. y *= f;
  52. f++;
  53. }
  54. return (1 + x + z);
  55. }
  56.  
  57. public static double bLog(double x, double b){
  58. double z = (nLog(x) / nLog(b));
  59. if (Double.isInfinite(z))
  60. z = Double.NaN;
  61.  
  62. return z;
  63. }
  64.  
  65. public static double pwr(double x, double n){
  66. double y = 0,z, o;
  67. if (x == 0){
  68. if (n <= 0)
  69. y = Double.NaN;
  70. else
  71. y = 0;
  72. }else if (n == 0){
  73. y = 1;
  74. }else if (x == 1){
  75. y = 1;
  76. }else if (n == 1){
  77. y = 1;
  78. }else if (x != 0 && n == -1){
  79. y = (1 / x);
  80. }else if (x > 0){
  81. z = n * nLog(x);
  82. y = xpon(z);
  83. }else if (x < 0){
  84. o = n % 2;
  85. if (o == 0){
  86. z = n * nLog(x);
  87. y = xpon(z);
  88. }else{
  89. z = n * nLog(x);
  90. y = -xpon(z);
  91. }
  92. }
  93. return y;
  94. }
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement