cprover
Toggle main menu visibility
Loading...
Searching...
No Matches
mathematical_types.cpp
Go to the documentation of this file.
1
/*******************************************************************\
2
3
Module: Mathematical types
4
5
Author: Daniel Kroening, kroening@kroening.com
6
Maria Svorenova, maria.svorenova@diffblue.com
7
8
\*******************************************************************/
9
12
13
#include "
mathematical_types.h
"
14
15
#include "
std_expr.h
"
16
19
bool
is_number
(
const
typet
&type)
20
{
21
const
irep_idt
&
id
= type.
id
();
22
return
id
== ID_rational ||
id
== ID_real ||
id
== ID_integer ||
23
id
== ID_natural ||
id
== ID_complex ||
id
== ID_unsignedbv ||
24
id
== ID_signedbv ||
id
== ID_floatbv ||
id
== ID_fixedbv;
25
}
26
27
constant_exprt
integer_typet::zero_expr
()
const
28
{
29
return
constant_exprt
{ID_0, *
this
};
30
}
31
32
constant_exprt
integer_typet::one_expr
()
const
33
{
34
return
constant_exprt
{ID_1, *
this
};
35
}
36
37
constant_exprt
natural_typet::zero_expr
()
const
38
{
39
return
constant_exprt
{ID_0, *
this
};
40
}
41
42
constant_exprt
natural_typet::one_expr
()
const
43
{
44
return
constant_exprt
{ID_1, *
this
};
45
}
46
47
constant_exprt
rational_typet::zero_expr
()
const
48
{
49
return
constant_exprt
{ID_0, *
this
};
50
}
51
52
constant_exprt
rational_typet::one_expr
()
const
53
{
54
return
constant_exprt
{ID_1, *
this
};
55
}
56
57
constant_exprt
real_typet::zero_expr
()
const
58
{
59
return
constant_exprt
{ID_0, *
this
};
60
}
61
62
constant_exprt
real_typet::one_expr
()
const
63
{
64
return
constant_exprt
{ID_1, *
this
};
65
}
66
67
bool
integer_range_typet::includes
(
const
mp_integer
&singleton)
const
68
{
69
return
from
() <= singleton && singleton <=
to
();
70
}
71
72
constant_exprt
integer_range_typet::one_expr
()
const
73
{
74
PRECONDITION
(
includes
(1));
75
return
constant_exprt
{ID_1, *
this
};
76
}
77
78
constant_exprt
integer_range_typet::zero_expr
()
const
79
{
80
PRECONDITION
(
includes
(0));
81
return
constant_exprt
{ID_0, *
this
};
82
}
83
84
void
integer_range_typet::from
(
const
mp_integer
&
from
)
85
{
86
set
(ID_from,
integer2string
(
from
));
87
}
88
89
void
integer_range_typet::to
(
const
mp_integer
&
to
)
90
{
91
set
(ID_to,
integer2string
(
to
));
92
}
93
94
mp_integer
integer_range_typet::from
()
const
95
{
96
return
string2integer
(
get_string
(ID_from));
97
}
98
99
mp_integer
integer_range_typet::to
()
const
100
{
101
return
string2integer
(
get_string
(ID_to));
102
}
103
104
mp_integer
integer_range_typet::size
()
const
105
{
106
auto
difference =
to
() -
from
();
107
return
difference >= 0 ? difference + 1 : 0;
108
}
109
110
bool
integer_range_typet::empty
()
const
111
{
112
return
to
() <
from
();
113
}
constant_exprt
A constant literal expression.
Definition
std_expr.h:3007
integer_range_typet::zero_expr
constant_exprt zero_expr() const
Definition
mathematical_types.cpp:78
integer_range_typet::one_expr
constant_exprt one_expr() const
Definition
mathematical_types.cpp:72
integer_range_typet::empty
bool empty() const
Definition
mathematical_types.cpp:110
integer_range_typet::includes
bool includes(const mp_integer &) const
Definition
mathematical_types.cpp:67
integer_range_typet::size
mp_integer size() const
Definition
mathematical_types.cpp:104
integer_range_typet::from
mp_integer from() const
Definition
mathematical_types.cpp:94
integer_range_typet::to
mp_integer to() const
Definition
mathematical_types.cpp:99
integer_typet::one_expr
constant_exprt one_expr() const
Definition
mathematical_types.cpp:32
integer_typet::zero_expr
constant_exprt zero_expr() const
Definition
mathematical_types.cpp:27
irept::set
void set(const irep_idt &name, const irep_idt &value)
Definition
irep.h:412
irept::id
const irep_idt & id() const
Definition
irep.h:388
irept::get_string
const std::string & get_string(const irep_idt &name) const
Definition
irep.h:401
natural_typet::zero_expr
constant_exprt zero_expr() const
Definition
mathematical_types.cpp:37
natural_typet::one_expr
constant_exprt one_expr() const
Definition
mathematical_types.cpp:42
rational_typet::zero_expr
constant_exprt zero_expr() const
Definition
mathematical_types.cpp:47
rational_typet::one_expr
constant_exprt one_expr() const
Definition
mathematical_types.cpp:52
real_typet::zero_expr
constant_exprt zero_expr() const
Definition
mathematical_types.cpp:57
real_typet::one_expr
constant_exprt one_expr() const
Definition
mathematical_types.cpp:62
typet
The type of an expression, extends irept.
Definition
type.h:29
is_number
bool is_number(const typet &type)
Returns true if the type is a rational, real, integer, natural, complex, unsignedbv,...
Definition
mathematical_types.cpp:19
mathematical_types.h
Mathematical types.
string2integer
const mp_integer string2integer(const std::string &n, unsigned base)
Definition
mp_arith.cpp:54
integer2string
const std::string integer2string(const mp_integer &n, unsigned base)
Definition
mp_arith.cpp:103
mp_integer
BigInt mp_integer
Definition
smt_terms.h:17
PRECONDITION
#define PRECONDITION(CONDITION)
Definition
invariant.h:463
std_expr.h
API to expression classes.
irep_idt
dstringt irep_idt
Definition
verification_result.h:16
util
mathematical_types.cpp
Generated by
1.17.0