20package com.microsoft.z3;
40 super(ctx, Native.rcfMkRational(ctx.
nCtx(), value));
50 super(ctx, Native.rcfMkSmallInt(ctx.
nCtx(), value));
67 return new RCFNum(ctx, Native.rcfMkPi(ctx.
nCtx()));
77 return new RCFNum(ctx, Native.rcfMkE(ctx.
nCtx()));
87 return new RCFNum(ctx, Native.rcfMkInfinitesimal(ctx.
nCtx()));
101 if (coefficients ==
null || coefficients.length == 0) {
102 throw new Z3Exception(
"Polynomial coefficients cannot be empty");
105 int n = coefficients.length;
106 long[] a =
new long[n];
107 long[] roots =
new long[n];
109 for (
int i = 0; i < n; i++) {
110 a[i] = coefficients[i].getNativeObject();
113 int numRoots = Native.rcfMkRoots(ctx.
nCtx(), n, a, roots);
116 for (
int i = 0; i < numRoots; i++) {
117 result[i] =
new RCFNum(ctx, roots[i]);
131 return new RCFNum(getContext(), Native.rcfAdd(getContext().nCtx(),
133 other.getNativeObject()));
144 return new RCFNum(getContext(), Native.rcfSub(getContext().nCtx(),
146 other.getNativeObject()));
157 return new RCFNum(getContext(), Native.rcfMul(getContext().nCtx(),
159 other.getNativeObject()));
170 return new RCFNum(getContext(), Native.rcfDiv(getContext().nCtx(),
172 other.getNativeObject()));
181 return new RCFNum(getContext(), Native.rcfNeg(getContext().nCtx(),
191 return new RCFNum(getContext(), Native.rcfInv(getContext().nCtx(),
202 return new RCFNum(getContext(), Native.rcfPower(getContext().nCtx(),
203 getNativeObject(), k));
214 return Native.rcfLt(getContext().nCtx(), getNativeObject(),
215 other.getNativeObject());
226 return Native.rcfGt(getContext().nCtx(), getNativeObject(),
227 other.getNativeObject());
238 return Native.rcfLe(getContext().nCtx(), getNativeObject(),
239 other.getNativeObject());
250 return Native.rcfGe(getContext().nCtx(), getNativeObject(),
251 other.getNativeObject());
262 return Native.rcfEq(getContext().nCtx(), getNativeObject(),
263 other.getNativeObject());
274 return Native.rcfNeq(getContext().nCtx(), getNativeObject(),
275 other.getNativeObject());
284 return Native.rcfIsRational(getContext().nCtx(), getNativeObject());
293 return Native.rcfIsAlgebraic(getContext().nCtx(), getNativeObject());
302 return Native.rcfIsInfinitesimal(getContext().nCtx(), getNativeObject());
311 return Native.rcfIsTranscendental(getContext().nCtx(), getNativeObject());
321 return Native.rcfNumToString(getContext().nCtx(), getNativeObject(),
342 return Native.rcfNumToDecimalString(getContext().nCtx(),
343 getNativeObject(), precision);
353 void addToReferenceQueue() {
354 getContext().getReferenceQueue().storeReference(
this, RCFNumRef::new);
357 private static class RCFNumRef
extends Z3ReferenceQueue.Reference<RCFNum> {
359 private RCFNumRef(RCFNum referent, java.lang.ref.ReferenceQueue<Z3Object> q) {
364 void decRef(Context ctx,
long z3Obj) {
365 Native.rcfDel(ctx.nCtx(), z3Obj);
369 private void checkContext(RCFNum other) {
370 if (getContext() != other.getContext()) {
371 throw new Z3Exception(
"RCF numerals from different contexts");
static RCFNum mkE(Context ctx)
static RCFNum mkPi(Context ctx)
String toString(boolean compact)
static RCFNum[] mkRoots(Context ctx, RCFNum[] coefficients)
boolean isTranscendental()
RCFNum(Context ctx, String value)
static RCFNum mkInfinitesimal(Context ctx)
String toDecimal(int precision)
RCFNum(Context ctx, int value)
boolean neq(RCFNum other)
boolean isInfinitesimal()