use of org.apfloat.FixedPrecisionApfloatHelper in project symja_android_library by axkr.
the class ApfloatNum method valueOf.
public static ApfloatNum valueOf(final BigInteger numerator, final BigInteger denominator) {
FixedPrecisionApfloatHelper h = EvalEngine.getApfloat();
Apfloat n = new Apfloat(numerator, h.precision());
Apfloat d = new Apfloat(denominator, h.precision());
return new ApfloatNum(h.divide(n, d));
}
use of org.apfloat.FixedPrecisionApfloatHelper in project symja_android_library by axkr.
the class ApcomplexNum method atan2.
@Override
public IExpr atan2(IExpr value) {
try {
if (value instanceof ApcomplexNum) {
Apcomplex th = fApcomplex;
Apcomplex x = ((ApcomplexNum) value).fApcomplex;
// compute r = sqrt(x^2+y^2)
FixedPrecisionApfloatHelper h = EvalEngine.getApfloat();
final Apcomplex r = h.sqrt(h.add(h.multiply(x, x), h.multiply(th, th)));
if (x.real().compareTo(Apfloat.ZERO) >= 0) {
// compute atan2(y, x) = 2 atan(y / (r + x))
return valueOf(h.multiply(h.atan(h.divide(th, h.add(r, x))), new Apfloat(2)));
} else {
// compute atan2(y, x) = +/- pi - 2 atan(y / (r - x))
return valueOf(h.add(h.multiply(h.atan(h.divide(th, h.subtract(r, x))), new Apfloat(-2)), h.pi()));
}
}
return IComplexNum.super.atan2(value);
} catch (ArithmeticException aex) {
// Indeterminate expression `1` encountered.
IOFunctions.printMessage(S.ArcTan, "indet", F.list(F.ArcTan(value, this)), EvalEngine.get());
return S.Indeterminate;
}
}
use of org.apfloat.FixedPrecisionApfloatHelper in project symja_android_library by axkr.
the class ApcomplexNum method copySign.
@Override
public IExpr copySign(double d) {
FixedPrecisionApfloatHelper h = EvalEngine.getApfloat();
Apfloat sign = new Apfloat(d);
return valueOf(//
h.copySign(fApcomplex.real(), sign), h.copySign(fApcomplex.imag(), sign));
}
Aggregations