I am having some issues doing basic math with Java. I don’t know why I am getting 0 as a result of multiplying n*n*n only in one case. (see below) I need this not to be zero because I have to divide timing/n*n*n to get that big O performance. Also if I can get that working the output may look like 0.00000 but I want to multiply that by like 100,000 just so I can see numbers and find any trends in performance.
You can see the values of n and timing in the first two number columns.
- n is Integer
- timing is Long
This is my output statement,
System.out.println(fmt.format("%20s %20d %20d %20d %20d %20d%n", "Alg. 1", n, timing, n*n*n, timing/(n*n), timing /*((double)timing/((double)n*Math.log((double)n)))*/));
My results,
Alg. 1 256 4 16777216 0 4
Alg. 1 512 22 134217728 0 22
Alg. 1 1024 173 1073741824 0 173
Alg. 1 2048 1362 0 0 1362
Please keep in mind I need to perform this log math also. Any tips or fixes for that would also be appreciated!
Note: I am not dividing at all in the statement n*n*n and I am getting 0 in column four row four.
Can someone also please tell me how to get this to output decimal places that are accurate not just 0.000000. My new arithmetic is ((float)(timing/((long)n)*n*n)*100000. I am multiplying by 100000 as said above because I want to see something in the decimal places. I should be seeing 0.0159139 with this equation when n is 2048 and timing is 1362. I just see 0.000000 though. Any suggestions?
20483 is 233 which overflows using 32-bit arithmetic. Use a
longor adoubleto handle numbers this big.(Demo at ideone.com)