Skip to content

introduce zero_expr() and one_expr() for number types #8441

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions src/util/mathematical_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

#include "mathematical_types.h"

#include "std_expr.h"

/// Returns true if the type is a rational, real, integer, natural, complex,
/// unsignedbv, signedbv, floatbv or fixedbv.
bool is_number(const typet &type)
Expand All @@ -21,3 +23,43 @@
id == ID_natural || id == ID_complex || id == ID_unsignedbv ||
id == ID_signedbv || id == ID_floatbv || id == ID_fixedbv;
}

constant_exprt integer_typet::zero_expr() const

Check warning on line 27 in src/util/mathematical_types.cpp

View check run for this annotation

Codecov / codecov/patch

src/util/mathematical_types.cpp#L27

Added line #L27 was not covered by tests
{
return constant_exprt{ID_0, *this};

Check warning on line 29 in src/util/mathematical_types.cpp

View check run for this annotation

Codecov / codecov/patch

src/util/mathematical_types.cpp#L29

Added line #L29 was not covered by tests
}

constant_exprt integer_typet::one_expr() const

Check warning on line 32 in src/util/mathematical_types.cpp

View check run for this annotation

Codecov / codecov/patch

src/util/mathematical_types.cpp#L32

Added line #L32 was not covered by tests
{
return constant_exprt{ID_1, *this};

Check warning on line 34 in src/util/mathematical_types.cpp

View check run for this annotation

Codecov / codecov/patch

src/util/mathematical_types.cpp#L34

Added line #L34 was not covered by tests
}

constant_exprt natural_typet::zero_expr() const

Check warning on line 37 in src/util/mathematical_types.cpp

View check run for this annotation

Codecov / codecov/patch

src/util/mathematical_types.cpp#L37

Added line #L37 was not covered by tests
{
return constant_exprt{ID_0, *this};

Check warning on line 39 in src/util/mathematical_types.cpp

View check run for this annotation

Codecov / codecov/patch

src/util/mathematical_types.cpp#L39

Added line #L39 was not covered by tests
}

constant_exprt natural_typet::one_expr() const

Check warning on line 42 in src/util/mathematical_types.cpp

View check run for this annotation

Codecov / codecov/patch

src/util/mathematical_types.cpp#L42

Added line #L42 was not covered by tests
{
return constant_exprt{ID_1, *this};

Check warning on line 44 in src/util/mathematical_types.cpp

View check run for this annotation

Codecov / codecov/patch

src/util/mathematical_types.cpp#L44

Added line #L44 was not covered by tests
}

constant_exprt rational_typet::zero_expr() const

Check warning on line 47 in src/util/mathematical_types.cpp

View check run for this annotation

Codecov / codecov/patch

src/util/mathematical_types.cpp#L47

Added line #L47 was not covered by tests
{
return constant_exprt{ID_0, *this};

Check warning on line 49 in src/util/mathematical_types.cpp

View check run for this annotation

Codecov / codecov/patch

src/util/mathematical_types.cpp#L49

Added line #L49 was not covered by tests
}

constant_exprt rational_typet::one_expr() const

Check warning on line 52 in src/util/mathematical_types.cpp

View check run for this annotation

Codecov / codecov/patch

src/util/mathematical_types.cpp#L52

Added line #L52 was not covered by tests
{
return constant_exprt{ID_1, *this};

Check warning on line 54 in src/util/mathematical_types.cpp

View check run for this annotation

Codecov / codecov/patch

src/util/mathematical_types.cpp#L54

Added line #L54 was not covered by tests
}

constant_exprt real_typet::zero_expr() const

Check warning on line 57 in src/util/mathematical_types.cpp

View check run for this annotation

Codecov / codecov/patch

src/util/mathematical_types.cpp#L57

Added line #L57 was not covered by tests
{
return constant_exprt{ID_0, *this};

Check warning on line 59 in src/util/mathematical_types.cpp

View check run for this annotation

Codecov / codecov/patch

src/util/mathematical_types.cpp#L59

Added line #L59 was not covered by tests
}

constant_exprt real_typet::one_expr() const

Check warning on line 62 in src/util/mathematical_types.cpp

View check run for this annotation

Codecov / codecov/patch

src/util/mathematical_types.cpp#L62

Added line #L62 was not covered by tests
{
return constant_exprt{ID_1, *this};

Check warning on line 64 in src/util/mathematical_types.cpp

View check run for this annotation

Codecov / codecov/patch

src/util/mathematical_types.cpp#L64

Added line #L64 was not covered by tests
}
14 changes: 14 additions & 0 deletions src/util/mathematical_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,18 @@
#include "invariant.h"
#include "type.h"

class constant_exprt;

/// Unbounded, signed integers (mathematical integers, not bitvectors)
class integer_typet : public typet
{
public:
integer_typet() : typet(ID_integer)
{
}

constant_exprt zero_expr() const;
constant_exprt one_expr() const;
};

/// Natural numbers including zero (mathematical integers, not bitvectors)
Expand All @@ -33,6 +38,9 @@
natural_typet() : typet(ID_natural)
{
}

constant_exprt zero_expr() const;

Check warning on line 42 in src/util/mathematical_types.h

View check run for this annotation

Codecov / codecov/patch

src/util/mathematical_types.h#L42

Added line #L42 was not covered by tests
constant_exprt one_expr() const;
};

/// Unbounded, signed rational numbers
Expand All @@ -42,6 +50,9 @@
rational_typet() : typet(ID_rational)
{
}

constant_exprt zero_expr() const;
constant_exprt one_expr() const;
};

/// Unbounded, signed real numbers
Expand All @@ -51,6 +62,9 @@
real_typet() : typet(ID_real)
{
}

constant_exprt zero_expr() const;

Check warning on line 66 in src/util/mathematical_types.h

View check run for this annotation

Codecov / codecov/patch

src/util/mathematical_types.h#L66

Added line #L66 was not covered by tests
constant_exprt one_expr() const;
};

/// A type for mathematical functions (do not confuse with functions/methods
Expand Down
Loading