Skip to content

Commit 9bee071

Browse files
committed
convert status codes <-> truth_t values (flintlib#2297)
1 parent 726ee2d commit 9bee071

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

doc/source/gr.rst

+8
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,14 @@ that the value is not computable:
230230

231231
.. function:: void truth_println(truth_t x)
232232

233+
.. function:: truth_t gr_in_domain(int status)
234+
235+
Returns ``T_TRUE`` when ``status`` is ``GR_SUCCESS``, ``T_FALSE`` when ``GR_DOMAIN`` is set but ``GR_UNABLE`` is not, and ``T_UNKNOWN`` otherwise.
236+
237+
.. function:: int gr_check(truth_t t)
238+
239+
Maps ``T_TRUE`` to ``GR_SUCCESS``, ``T_FALSE`` to ``GR_DOMAIN``, and ``T_UNKNOWN`` to ``GR_UNABLE``.
240+
233241
Context operations
234242
-------------------------------------------------------------------------------
235243

src/gr.h

+25
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,31 @@ GR_INLINE truth_t truth_not(truth_t x)
5151
return T_UNKNOWN;
5252
}
5353

54+
GR_INLINE truth_t gr_in_domain(int status)
55+
{
56+
if (status == GR_SUCCESS)
57+
return T_TRUE;
58+
else if (status & GR_UNABLE)
59+
return T_UNKNOWN;
60+
else if (status & GR_DOMAIN)
61+
return T_FALSE;
62+
else
63+
return T_UNKNOWN;
64+
}
65+
66+
GR_INLINE int gr_check(truth_t t)
67+
{
68+
switch (t)
69+
{
70+
case T_TRUE:
71+
return GR_SUCCESS;
72+
case T_FALSE:
73+
return GR_DOMAIN;
74+
case T_UNKNOWN:
75+
return GR_UNABLE;
76+
}
77+
}
78+
5479
GR_INLINE void truth_println(truth_t x)
5580
{
5681
if (x == T_TRUE) flint_printf("T_TRUE\n");

0 commit comments

Comments
 (0)