Search code examples
javavariablesmethodsnotation

Java- Notation for /variable/


When writing a method in java, I noticed that these two functions return the same value.

// Riemann-Siegel theta function using the approximation by the Stirling series
public static double theta (double t) {
return (t/2.0 * StrictMath.log(t/2.0/StrictMath.PI) - t/2.0
    - StrictMath.PI/8.0 + 1.0/48.0/t + 7.0/5760.0/t/t/t);
}

// Riemann-Siegel theta function using the approximation by the Stirling series
public static double theta2 (double t) {
return (t/2.0 * Math.log(t/(2.0*Math.PI)) - t/2.0
    - Math.PI/8.0 + 1.0/(48.0*Math.pow(t, 1)) + 7.0/(5760*Math.pow(t, 3)));
}

What is

7.0/5760.0/t/t/t

doing? Why is this the same as 7.0/(5760*t^3)?


Solution

  • the expression 7.0/5760.0/t1/t2/t3 will be computed from L-R. like-

    r=(7.0/5760.0)
    r1=(result/t1)
    r2=(r1/t2)
    r3=(r2/t3)
    

    and r3 is your final result

    if you have expression like 8/2*2*2 it will be calculated as same i've explained earlier but in 8/2*(2*2) expression (2*2) will be calculated first because perathesis has higher priority then /. it is also aplly in case of math.pow() function because functions also have the higher priority the operators.