Formal power series/Java: Difference between revisions

m
→‎{{header|Java}}: should be inverseCoef in div function
(Move long example to its own page)
 
m (→‎{{header|Java}}: should be inverseCoef in div function)
 
Line 1:
{{works with|Java|1.5+}}
 
Copied from the D example. Java has no generic numeric interface, and has no templates, so we cannot make it work for all numeric types at the same time. Because the Java library does not come with a Fraction class (and I am too lazy to implement one, although there is one in Apache Commons Math), here I will just hard-code it to use doubles (64-bit floating-point numbers) instead of fractions. It won't be as pretty, but it can be changed to Fraction or any other type trivially by substituting the types.
<lang java5>import java.util.*;
 
Line 93:
double res = 0;
for (int i = 0; i <= n; i++)
res += term.get(i) * rhs.term.getinverseCoef(n-i);
return res;
}
Anonymous user