It also fixes a wrong entry in s_rmodes_internal.
FLOATINGPOINT_TO_FP_FROM_SBV,
FLOATINGPOINT_TO_FP_FROM_UBV});
+/* -------------------------------------------------------------------------- */
+/* Rounding Mode for Floating Points */
+/* -------------------------------------------------------------------------- */
+
+const static std::unordered_map<RoundingMode, cvc5::RoundingMode> s_rmodes{
+ {ROUND_NEAREST_TIES_TO_EVEN,
+ cvc5::RoundingMode::ROUND_NEAREST_TIES_TO_EVEN},
+ {ROUND_TOWARD_POSITIVE, cvc5::RoundingMode::ROUND_TOWARD_POSITIVE},
+ {ROUND_TOWARD_NEGATIVE, cvc5::RoundingMode::ROUND_TOWARD_NEGATIVE},
+ {ROUND_TOWARD_ZERO, cvc5::RoundingMode::ROUND_TOWARD_ZERO},
+ {ROUND_NEAREST_TIES_TO_AWAY,
+ cvc5::RoundingMode::ROUND_NEAREST_TIES_TO_AWAY},
+};
+
+const static std::unordered_map<cvc5::RoundingMode, RoundingMode>
+ s_rmodes_internal{
+ {cvc5::RoundingMode::ROUND_NEAREST_TIES_TO_EVEN,
+ ROUND_NEAREST_TIES_TO_EVEN},
+ {cvc5::RoundingMode::ROUND_TOWARD_POSITIVE, ROUND_TOWARD_POSITIVE},
+ {cvc5::RoundingMode::ROUND_TOWARD_NEGATIVE, ROUND_TOWARD_NEGATIVE},
+ {cvc5::RoundingMode::ROUND_TOWARD_ZERO, ROUND_TOWARD_ZERO},
+ {cvc5::RoundingMode::ROUND_NEAREST_TIES_TO_AWAY,
+ ROUND_NEAREST_TIES_TO_AWAY},
+ };
+
namespace {
/** Convert a cvc5::Kind (internal) to a cvc5::api::Kind (external). */
CVC5_API_TRY_CATCH_END;
}
+bool Term::isRoundingModeValue() const
+{
+ CVC5_API_TRY_CATCH_BEGIN;
+ CVC5_API_CHECK_NOT_NULL;
+ //////// all checks before this line
+ return d_node->getKind() == cvc5::Kind::CONST_ROUNDINGMODE;
+ ////////
+ CVC5_API_TRY_CATCH_END;
+}
+RoundingMode Term::getRoundingModeValue() const
+{
+ CVC5_API_TRY_CATCH_BEGIN;
+ CVC5_API_CHECK_NOT_NULL;
+ CVC5_API_ARG_CHECK_EXPECTED(
+ d_node->getKind() == cvc5::Kind::CONST_ROUNDINGMODE, *d_node)
+ << "Term to be a floating-point rounding mode value when calling "
+ "getRoundingModeValue()";
+ //////// all checks before this line
+ return s_rmodes_internal.at(d_node->getConst<cvc5::RoundingMode>());
+ ////////
+ CVC5_API_TRY_CATCH_END;
+}
+
bool Term::isFloatingPointPosZero() const
{
CVC5_API_TRY_CATCH_BEGIN;
return out << grammar.toString();
}
-/* -------------------------------------------------------------------------- */
-/* Rounding Mode for Floating Points */
-/* -------------------------------------------------------------------------- */
-
-const static std::unordered_map<RoundingMode, cvc5::RoundingMode> s_rmodes{
- {ROUND_NEAREST_TIES_TO_EVEN,
- cvc5::RoundingMode::ROUND_NEAREST_TIES_TO_EVEN},
- {ROUND_TOWARD_POSITIVE, cvc5::RoundingMode::ROUND_TOWARD_POSITIVE},
- {ROUND_TOWARD_NEGATIVE, cvc5::RoundingMode::ROUND_TOWARD_NEGATIVE},
- {ROUND_TOWARD_ZERO, cvc5::RoundingMode::ROUND_TOWARD_ZERO},
- {ROUND_NEAREST_TIES_TO_AWAY,
- cvc5::RoundingMode::ROUND_NEAREST_TIES_TO_AWAY},
-};
-
-const static std::unordered_map<cvc5::RoundingMode,
- RoundingMode,
- cvc5::RoundingModeHashFunction>
- s_rmodes_internal{
- {cvc5::RoundingMode::ROUND_NEAREST_TIES_TO_EVEN,
- ROUND_NEAREST_TIES_TO_EVEN},
- {cvc5::RoundingMode::ROUND_TOWARD_POSITIVE, ROUND_TOWARD_POSITIVE},
- {cvc5::RoundingMode::ROUND_TOWARD_POSITIVE, ROUND_TOWARD_NEGATIVE},
- {cvc5::RoundingMode::ROUND_TOWARD_ZERO, ROUND_TOWARD_ZERO},
- {cvc5::RoundingMode::ROUND_NEAREST_TIES_TO_AWAY,
- ROUND_NEAREST_TIES_TO_AWAY},
- };
-
/* -------------------------------------------------------------------------- */
/* Options */
/* -------------------------------------------------------------------------- */
*/
std::vector<Term> getTupleValue() const;
+ /**
+ * @return true if the term is a floating-point rounding mode value.
+ */
+ bool isRoundingModeValue() const;
+ /**
+ * Asserts isRoundingModeValue().
+ * @return the floating-point rounding mode value held by the term.
+ */
+ RoundingMode getRoundingModeValue() const;
+
/**
* @return true if the term is the floating-point value for positive zero.
*/
private native String getUninterpretedSortValue(long pointer);
+ /**
+ * @return true if the term is a floating-point rounding mode value.
+ */
+ public boolean isRoundingModeValue()
+ {
+ return isRoundingModeValue(pointer);
+ }
+
+ private native boolean isRoundingModeValue(long pointer);
+
+ /**
+ * Asserts isRoundingModeValue().
+ * @return the floating-point rounding mode value held by the term.
+ */
+ public RoundingMode getRoundingModeValue() throws CVC5ApiException
+ {
+ int value = getRoundingModeValue(pointer);
+ return RoundingMode.fromInt(value);
+ }
+
+ private native int getRoundingModeValue(long pointer);
+
/**
* @return true if the term is a tuple value.
*/
CVC5_JAVA_API_TRY_CATCH_END_RETURN(env, nullptr);
}
+/*
+ * Class: io_github_cvc5_api_Term
+ * Method: isRoundingModeValue
+ * Signature: (J)Z
+ */
+JNIEXPORT jboolean JNICALL Java_io_github_cvc5_api_Term_isRoundingModeValue(
+ JNIEnv* env, jobject, jlong pointer)
+{
+ CVC5_JAVA_API_TRY_CATCH_BEGIN;
+ Term* current = reinterpret_cast<Term*>(pointer);
+ return static_cast<jboolean>(current->isRoundingModeValue());
+ CVC5_JAVA_API_TRY_CATCH_END_RETURN(env, static_cast<jboolean>(false));
+}
+
+/*
+ * Class: io_github_cvc5_api_Term
+ * Method: getRoundingModeValue
+ * Signature: (J)I
+ */
+JNIEXPORT jint JNICALL Java_io_github_cvc5_api_Term_getRoundingModeValue(
+ JNIEnv* env, jobject, jlong pointer)
+{
+ CVC5_JAVA_API_TRY_CATCH_BEGIN;
+ Term* current = reinterpret_cast<Term*>(pointer);
+ return static_cast<jint>(current->getRoundingModeValue());
+ CVC5_JAVA_API_TRY_CATCH_END_RETURN(env, 0);
+}
+
/*
* Class: io_github_cvc5_api_Term
* Method: isTupleValue
string getBitVectorValue(uint32_t base) except +
bint isUninterpretedSortValue() except +
string getUninterpretedSortValue() except +
+ bint isTupleValue() except +
+ vector[Term] getTupleValue() except +
+ bint isRoundingModeValue() except +
+ RoundingMode getRoundingModeValue() except +
+
bint isFloatingPointPosZero() except +
bint isFloatingPointNegZero() except +
bint isFloatingPointPosInf() except +
set[Term] getSetValue() except +
bint isSequenceValue() except +
vector[Term] getSequenceValue() except +
- bint isTupleValue() except +
- vector[Term] getTupleValue() except +
cdef cppclass TermHashFunction:
""":return: True iff this term is a tuple value."""
return self.cterm.isTupleValue()
+ def isRoundingModeValue(self):
+ """:return: True if the term is a floating-point rounding mode value."""
+ return self.cterm.isRoundingModeValue()
+
+ def getRoundingModeValue(self):
+ """
+ Asserts isRoundingModeValue().
+ :return: the floating-point rounding mode value held by the term.
+ """
+ return RoundingMode(<int> self.cterm.getRoundingModeValue())
+
def getTupleValue(self):
"""
Asserts :py:meth:`isTupleValue()`.
ASSERT_EQ(vx.getUninterpretedSortValue(), vy.getUninterpretedSortValue());
}
+TEST_F(TestApiBlackTerm, isRoundingModeValue)
+{
+ ASSERT_FALSE(d_solver.mkInteger(15).isRoundingModeValue());
+ ASSERT_TRUE(d_solver.mkRoundingMode(RoundingMode::ROUND_NEAREST_TIES_TO_EVEN)
+ .isRoundingModeValue());
+ ASSERT_FALSE(
+ d_solver.mkConst(d_solver.getRoundingModeSort()).isRoundingModeValue());
+}
+
+TEST_F(TestApiBlackTerm, getRoundingModeValue)
+{
+ ASSERT_THROW(d_solver.mkInteger(15).getRoundingModeValue(), CVC5ApiException);
+ ASSERT_EQ(d_solver.mkRoundingMode(RoundingMode::ROUND_NEAREST_TIES_TO_EVEN)
+ .getRoundingModeValue(),
+ RoundingMode::ROUND_NEAREST_TIES_TO_EVEN);
+ ASSERT_EQ(d_solver.mkRoundingMode(RoundingMode::ROUND_TOWARD_POSITIVE)
+ .getRoundingModeValue(),
+ RoundingMode::ROUND_TOWARD_POSITIVE);
+ ASSERT_EQ(d_solver.mkRoundingMode(RoundingMode::ROUND_TOWARD_NEGATIVE)
+ .getRoundingModeValue(),
+ RoundingMode::ROUND_TOWARD_NEGATIVE);
+ ASSERT_EQ(d_solver.mkRoundingMode(RoundingMode::ROUND_TOWARD_ZERO)
+ .getRoundingModeValue(),
+ RoundingMode::ROUND_TOWARD_ZERO);
+ ASSERT_EQ(d_solver.mkRoundingMode(RoundingMode::ROUND_NEAREST_TIES_TO_AWAY)
+ .getRoundingModeValue(),
+ RoundingMode::ROUND_NEAREST_TIES_TO_AWAY);
+}
+
TEST_F(TestApiBlackTerm, getTuple)
{
Sort s1 = d_solver.getIntegerSort();
assertDoesNotThrow(() -> vy.getUninterpretedSortValue());
}
+ @Test void isRoundingModeValue() throws CVC5ApiException
+ {
+ assertFalse(d_solver.mkInteger(15).isRoundingModeValue());
+ assertTrue(
+ d_solver.mkRoundingMode(RoundingMode.ROUND_NEAREST_TIES_TO_EVEN).isRoundingModeValue());
+ assertFalse(d_solver.mkConst(d_solver.getRoundingModeSort()).isRoundingModeValue());
+ }
+
+ @Test void getRoundingModeValue() throws CVC5ApiException
+ {
+ assertThrows(CVC5ApiException.class, () -> d_solver.mkInteger(15).getRoundingModeValue());
+ assertEquals(
+ d_solver.mkRoundingMode(RoundingMode.ROUND_NEAREST_TIES_TO_EVEN).getRoundingModeValue(),
+ RoundingMode.ROUND_NEAREST_TIES_TO_EVEN);
+ assertEquals(d_solver.mkRoundingMode(RoundingMode.ROUND_TOWARD_POSITIVE).getRoundingModeValue(),
+ RoundingMode.ROUND_TOWARD_POSITIVE);
+ assertEquals(d_solver.mkRoundingMode(RoundingMode.ROUND_TOWARD_NEGATIVE).getRoundingModeValue(),
+ RoundingMode.ROUND_TOWARD_NEGATIVE);
+ assertEquals(d_solver.mkRoundingMode(RoundingMode.ROUND_TOWARD_ZERO).getRoundingModeValue(),
+ RoundingMode.ROUND_TOWARD_ZERO);
+ assertEquals(
+ d_solver.mkRoundingMode(RoundingMode.ROUND_NEAREST_TIES_TO_AWAY).getRoundingModeValue(),
+ RoundingMode.ROUND_NEAREST_TIES_TO_AWAY);
+ }
+
@Test void getTuple()
{
Sort s1 = d_solver.getIntegerSort();
import pytest
import cvc5
-from cvc5 import Kind
+from cvc5 import Kind, RoundingMode
from cvc5 import Sort, Term
from fractions import Fraction
assert vx.getUninterpretedSortValue() == vy.getUninterpretedSortValue()
+def test_is_rounding_mode_value(solver):
+ assert not solver.mkInteger(15).isRoundingModeValue()
+ assert solver.mkRoundingMode(
+ RoundingMode.RoundNearestTiesToEven).isRoundingModeValue()
+ assert not solver.mkConst(
+ solver.getRoundingModeSort()).isRoundingModeValue()
+
+
+def test_get_rounding_mode_value(solver):
+ with pytest.raises(RuntimeError):
+ solver.mkInteger(15).getRoundingModeValue()
+ assert solver.mkRoundingMode(
+ RoundingMode.RoundNearestTiesToEven).getRoundingModeValue(
+ ) == RoundingMode.RoundNearestTiesToEven
+ assert solver.mkRoundingMode(
+ RoundingMode.RoundTowardPositive).getRoundingModeValue(
+ ) == RoundingMode.RoundTowardPositive
+ assert solver.mkRoundingMode(
+ RoundingMode.RoundTowardNegative).getRoundingModeValue(
+ ) == RoundingMode.RoundTowardNegative
+ assert solver.mkRoundingMode(
+ RoundingMode.RoundTowardZero).getRoundingModeValue(
+ ) == RoundingMode.RoundTowardZero
+ assert solver.mkRoundingMode(
+ RoundingMode.RoundNearestTiesToAway).getRoundingModeValue(
+ ) == RoundingMode.RoundNearestTiesToAway
+
+
def test_get_tuple(solver):
s1 = solver.getIntegerSort()
s2 = solver.getRealSort()