int32
Overview
Module with functions and types to work with int32_t values.
Types and Definitions
Generated
cInt32Slice
struct cInt32Slice
{
int64_t s;
int32_t const* v;
};
typedef struct cInt32Slice cInt32Slice;
Via the macro SLICES_C_ generated struct.
cVarInt32Slice
struct cVarInt32Slice
{
int64_t s;
int32_t* v;
};
typedef struct cVarInt32Slice cVarInt32Slice;
Via the macro SLICES_C_ generated struct.
Functions
overall
cmp_int32_c
int cmp_int32_c( int32_t a, int32_t b );
Compares two int32_t values and returns the three possible results:
- <0
-
means that a is less compared to b
- 0
-
means that a and b are equal
- >0
-
means that a is greater compared to b
#include "clingo/lang/expect.h"
#include "clingo/type/int32.h"
int main( void )
{
init_tap_c_();
expect_lt_c_( cmp_int32_c( -2147483648, 0 ) );
expect_lt_c_( cmp_int32_c( -1, 0 ) );
expect_eq_c_( cmp_int32_c( 0, 0 ) );
expect_gt_c_( cmp_int32_c( 1, 0 ) );
expect_gt_c_( cmp_int32_c( 2147483647, 0 ) );
return finish_tap_c_();
}
int32_c_
#define int32_c_( Value )
Macro function that casts the Value as int32_t.
conv
int64_to_int32_c
bool int64_to_int32_c( int64_t src, int32_t dst[static 1] );
Via the macro CONV_C_ implemented function. Returns true if the int64_t value can be represented in a int32_t variable, otherwise false.
#include "clingo/lang/expect.h"
#include "clingo/type/int32.h"
int main( void )
{
init_tap_c_();
int32_t i32 = 0;
// ---------------------------------------------------------------------- max
int64_t i64 = 2147483647; // INT32_MAX
expect_c_( int64_to_int32_c( i64, &i32 ) );
expect_c_( i32 == 2147483647 );
++i64; // 2147483648
expect_c_( not int64_to_int32_c( i64, &i32 ) );
// ---------------------------------------------------------------------- min
i64 = -2147483648; // INT32_MIN
expect_c_( int64_to_int32_c( i64, &i32 ) );
expect_c_( i32 == -2147483648 );
--i64; // -2147483649
expect_c_( not int64_to_int32_c( i64, &i32 ) );
return finish_tap_c_();
}
uint64_to_int32_c
bool uint64_to_int32_c( uint64_t src, int32_t dst[static 1] );
Via the macro CONV_C_ implemented function. Returns true if the uint64_t value can be represented in a int32_t variable, otherwise false.
#include "clingo/lang/expect.h"
#include "clingo/type/int32.h"
int main( void )
{
init_tap_c_();
int32_t i32 = 0;
// ----------------------------------------------------------------- uint64_t
uint64_t u64 = 2147483647; // INT32_MAX
expect_c_( uint64_to_int32_c( u64, &i32 ) );
expect_c_( u64 == 2147483647 );
++u64; // 2147483648
expect_c_( not uint64_to_int32_c( u64, &i32 ) );
return finish_tap_c_();
}
swap
swap_int32_c
int32_t swap_int32_c( int32_t val );
Returns val with a changed byte order.
#include "clingo/lang/expect.h"
#include "clingo/type/int32.h"
int main( void )
{
init_tap_c_();
expect_c_( swap_int32_c( 0x7caf0000 ) == 0x0000af7c );
return finish_tap_c_();
}
swap_int32_from_c
int32_t swap_int32_from_c( int32_t val, c_ByteOrder order );
Changes the byte order of val from a known order to the system order if necessary.
#include "clingo/lang/expect.h"
#include "clingo/type/int32.h"
int main( void )
{
init_tap_c_();
c_ByteOrder sysOrder = system_order_c();
c_ByteOrder othOrder = system_order_is_c( c_BigEndian ) ? c_LittleEndian
: c_BigEndian;
expect_c_( swap_int32_from_c( 0x7caf0000, sysOrder ) == 0x7caf0000 );
expect_c_( swap_int32_from_c( 0x7caf0000, othOrder ) == 0x0000af7c );
return finish_tap_c_();
}
swap_int32_to_c
int32_t swap_int32_to_c( int32_t val, c_ByteOrder order );
Changes the byte order of val from the system order to a known order if necessary.
#include "clingo/lang/expect.h"
#include "clingo/type/int32.h"
int main( void )
{
init_tap_c_();
c_ByteOrder sysOrder = system_order_c();
c_ByteOrder othOrder = system_order_is_c( c_BigEndian ) ? c_LittleEndian
: c_BigEndian;
expect_c_( swap_int32_to_c( 0x7caf0000, sysOrder ) == 0x7caf0000 );
expect_c_( swap_int32_to_c( 0x7caf0000, othOrder ) == 0x0000af7c );
return finish_tap_c_();
}
algo
bsearch_int32_c
int32_t const* bsearch_int32_c( cInt32Slice slice, int32_t val );
Via the macro BSEARCH_C_ implemented function.
cmp_int32_slice_c
int cmp_int32_slice_c( cInt32Slice a, cInt32Slice b );
Via the macro CMP_SLICE_C_ implemented function.
count_eq_int32_c
int64_t count_eq_int32_c( cInt32Slice slice, int32_t val );
Via the macro COUNT_EQ_C_ implemented function.
find_int32_c
int32_t const* find_int32_c( cInt32Slice slice, int32_t val );
Via the macro FIND_VAL_C_ implemented function.
max_int32_c
int32_t const* max_int32_c( cInt32Slice slice );
Via the macro FIND_MAX_C_ implemented function.
min_int32_c
int32_t const* min_int32_c( cInt32Slice slice );
Via the macro FIND_MIN_C_ implemented function.
prod_int32_c
bool prod_int32_c( cInt32Slice slice, int64_t res[static 1] );
Builds the product all values in the slice and saves the result in res. Return false if a overflow occures, otherwise true.
qsort_int32_slice_c
void qsort_int32_slice_c( cVarInt32Slice slice );
Via the macro QSORT_C_ implemented function.
remove_int32_c
bool remove_int32_c( cVarInt32Slice slice[static 1], int64_t pos );
Via the macro REMOVE_C_ implemented function.
reverse_int32_slice_c
void reverse_int32_slice_c( cVarInt32Slice slice );
Via the macro REVERSE_C_ implemented function.
rotate_int32_slice_c
void rotate_int32_slice_c( cVarInt32Slice slice, int64_t distance );
Via the macro ROTATE_C_ implemented function.
sum_int32_c
bool sum_int32_c( cInt32Slice slice, int64_t res[static 1] );
Builds the sum of all values in the slice and saves the result in res. Returns false if a overflow occures, otherwise true.
take_int64_c
bool take_int32_c( cVarInt32Slice slice[static 1],
int64_t pos,
int32_t val[static 1] );
Via the macro TAKE_C_ implemented function.