3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-04-25 01:55:32 +00:00
z3/src/api/java/RatNum.java
George Karpenkov dfc80d3b69 Do not needlessly catch exceptions in Java bindings
A lot of existing code in Java bindings catches exceptions just to
silence them later.

This is:
a) Unnecessary: it is OK for a function to throw a RuntimeException
without declaring it.
b) Highly unidiomatic and not recommended by Java experts (see Effective
Java and others)
c) Confusing as has the potential to hide the existing bugs and have
them resurface at the most inconvenient/unexpected moment.
2016-06-12 14:14:11 +02:00

86 lines
1.8 KiB
Java

/**
Copyright (c) 2012-2014 Microsoft Corporation
Module Name:
RatNum.java
Abstract:
Author:
@author Christoph Wintersteiger (cwinter) 2012-03-15
Notes:
**/
package com.microsoft.z3;
import java.math.BigInteger;
/**
* Rational Numerals
**/
public class RatNum extends RealExpr
{
/**
* The numerator of a rational numeral.
**/
public IntNum getNumerator()
{
return new IntNum(getContext(), Native.getNumerator(getContext().nCtx(),
getNativeObject()));
}
/**
* The denominator of a rational numeral.
**/
public IntNum getDenominator()
{
return new IntNum(getContext(), Native.getDenominator(getContext().nCtx(),
getNativeObject()));
}
/**
* Converts the numerator of the rational to a BigInteger
**/
public BigInteger getBigIntNumerator()
{
IntNum n = getNumerator();
return new BigInteger(n.toString());
}
/**
* Converts the denominator of the rational to a BigInteger
**/
public BigInteger getBigIntDenominator()
{
IntNum n = getDenominator();
return new BigInteger(n.toString());
}
/**
* Returns a string representation in decimal notation.
* Remarks: The result
* has at most {@code precision} decimal places.
**/
public String toDecimalString(int precision)
{
return Native.getNumeralDecimalString(getContext().nCtx(), getNativeObject(),
precision);
}
/**
* Returns a string representation of the numeral.
**/
@Override
public String toString() {
return Native.getNumeralString(getContext().nCtx(), getNativeObject());
}
RatNum(Context ctx, long obj)
{
super(ctx, obj);
}
}