Integer comparison#
Preliminaries#
Let us load the mp++ runtime, include the integer.hpp
header and import the user-defined literals:
#pragma cling add_include_path("$CONDA_PREFIX/include")
#pragma cling add_library_path("$CONDA_PREFIX/lib")
#pragma cling load("mp++")
#include <mp++/integer.hpp>
using namespace mppp::literals;
Basic comparison#
Multiprecision integers support the basic comparison operators:
42_z1 == 42_z1
true
1_z1 != -1_z1
true
4_z1 > 3_z1
true
4_z1 >= 3_z1
true
-1_z1 < 1_z1
true
-1_z1 <= -1_z1
true
Mixed-mode comparisons with other types are supported too:
1_z1 == 4
false
3.5 != 1_z1
true
11ull > 6_z1
true
char(6) >= 6_z1
true
21_z1 < 2.5f
false
1_z1 <= 2.5l
true
Additional comparison functions#
Three-way comparison:
cmp(1_z1, 4_z1)
-1
cmp(1_z1, 1_z1)
0
cmp(4_z1, 1_z1)
1
Sign detection:
sgn(-4_z1)
-1
Parity detection:
even_p(6_z1)
true
odd_p(-5_z1)
true
Optimised primitives to detect special values:
is_zero(4_z1)
false
is_one(1_z1)
true
is_negative_one(-1_z1)
true