Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- *
- CSC 1350 lab #6
- @author Brandon Do
- @since 10/22/2019
- Course: CSC 1350 Section: 3
- Instructor Dr. Duncan
- */
- public class AuxMath {
- public static double nLog(double x){
- if (x < 0 )
- return Double.NaN;
- double y,o;
- double z = 0;
- for(double i = 1; i < 10000; i+=2){
- y = ((x - 1) / (x + 1));
- o = y;
- for(double t = 1; t < i; t++){
- o = o * y;
- }
- o = (o * (1 / i));
- z += o;
- }
- z *= 2;
- return z;
- }
- public static double xpon(double x){
- double f = 3, y = 2, o, z = 0;
- for(int i = 1; i < 400; i++){
- o = x;
- //find x^i
- for(double t = 0; t < i; t++){
- o = o * x;
- }
- // x^i / y
- o = (o / y);
- // Add to total
- z += o;
- // Calcualte y (2 * 3 * 4 * 5 * 6 * ...)
- y *= f;
- f++;
- }
- return (1 + x + z);
- }
- public static double bLog(double x, double b){
- double z = (nLog(x) / nLog(b));
- if (Double.isInfinite(z))
- z = Double.NaN;
- return z;
- }
- public static double pwr(double x, double n){
- double y = 0,z, o;
- if (x == 0){
- if (n <= 0)
- y = Double.NaN;
- else
- y = 0;
- }else if (n == 0){
- y = 1;
- }else if (x == 1){
- y = 1;
- }else if (n == 1){
- y = 1;
- }else if (x != 0 && n == -1){
- y = (1 / x);
- }else if (x > 0){
- z = n * nLog(x);
- y = xpon(z);
- }else if (x < 0){
- o = n % 2;
- if (o == 0){
- z = n * nLog(x);
- y = xpon(z);
- }else{
- z = n * nLog(x);
- y = -xpon(z);
- }
- }
- return y;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement