int16
Overview
Module with functions and types to work with int16_t values.
Types and Definitions
Generated
cInt16Slice
struct cInt16Slice { int64_t s; int16_t const* v; }; typedef struct cInt16Slice cInt16Slice;
Via the macros SLICE_DEF_C_ and SLICE_IMPL_C_ declared and implemented struct. The macros declare and implement also the following functions.
/* init */ cInt16Slice int16_slice_c( int64_t s, int16_t const* v ); cInt16Slice make_int16_slice_c( int16_t const* beg, int16_t const* end ); cInt16Slice empty_int16_slice_c( void ); /* sub */ cInt16Slice left_int16_slice_c( cInt16Slice slice, int64_t maxLen ); cInt16Slice mid_int16_slice_c( cInt16Slice slice, int64_t index ); cInt16Slice right_int16_slice_c( cInt16Slice slice, int64_t maxLen ); cInt16Slice sub_int16_slice_c( cInt16Slice slice, int64_t begIdx, int64_t endIdx );
cVarInt16Slice
struct cVarInt16Slice { int64_t s; int16_t* v; }; typedef struct cVarInt16Slice cVarInt16Slice;
Via the macros SLICE_DEF_C_ and SLICE_IMPL_C_ declared and implemented struct. The macros declare and implement also the following functions.
/* init */ cVarInt16Slice var_int16_slice_c( int64_t s, int16_t* v ); cVarInt16Slice make_var_int16_slice_c( int16_t* beg, int16_t* end ); cVarInt16Slice empty_var_int16_slice_c( void ); /* sub */ cVarInt16Slice left_var_int16_slice_c( cVarInt16Slice slice, int64_t maxLen ); cVarInt16Slice mid_var_int16_slice_c( cVarInt16Slice slice, int64_t index ); cVarInt16Slice right_var_int16_slice_c( cVarInt16Slice slice, int64_t maxLen ); cVarInt16Slice sub_var_int16_slice_c( cVarInt16Slice slice, int64_t begIdx, int64_t endIdx ); /* var slice */ cInt16Slice as_int16_slice_c( cVarInt16Slice slice ); cVarInt16Slice cast_int16_slice_c( cVarInt16Slice slice, cInt16Slice sub ); int64_t set_int16_slice_c( cVarInt16Slice dst, cInt16Slice src );
cInt16Chunk
struct cInt16Chunk { int64_t s; int16_t const* v; int64_t favSize; cInt16Slice slice; }; typedef struct cInt16Chunk cInt16Chunk;
Via the macros CHUNK_DEF_C_ and CHUNK_IMPL_C_ declared and implemented struct. The macros declare and implement also the following functions.
void init_back_int16_chunk_c( cInt16Chunk chunk[static 1], int64_t s, cInt16Slice slice ); void init_front_int16_chunk_c( cInt16Chunk chunk[static 1], int64_t s, cInt16Slice slice );
cVarInt16Chunk
struct cVarInt16Chunk { int64_t s; int16_t* v; int64_t favSize; cVarInt16Slice slice; }; typedef struct cVarInt16Chunk cVarInt16Chunk;
Via the macros CHUNK_DEF_C_ and CHUNK_IMPL_C_ declared and implemented struct. The macros declare and implement also the following functions.
void init_back_var_int16_chunk_c( cVarInt16Chunk chunk[static 1], int64_t s, cVarInt16Slice slice ); void init_front_var_int16_chunk_c( cVarInt16Chunk chunk[static 1], int64_t s, cVarInt16Slice slice );
cInt16Window
struct cInt16Window { int64_t s; int16_t const* v; cInt16Slice slice; }; typedef struct cInt16Window cInt16Window;
Via the macros WINDOW_DEF_C_ and WINDOW_IMPL_C_ declared and implemented struct. The macros declare and implement also the following functions.
void init_back_int16_window_c( cInt16Window window[static 1], int64_t s, cInt16Slice slice ); void init_front_int16_window_c( cInt16Window window[static 1], int64_t s, cInt16Slice slice );
cVarInt16Window
struct cVarInt16Window { int64_t s; int16_t* v; cVarInt16Slice slice; }; typedef struct cVarInt16Window cVarInt16Window;
Via the macros WINDOW_DEF_C_ and WINDOW_IMPL_C_ declared and implemented struct. The macros declare and implement also the following functions.
void init_back_var_int16_window_c( cVarInt16Window window[static 1], int64_t s, cVarInt16Slice slice ); void init_front_var_int16_window_c( cVarInt16Window window[static 1], int64_t s, cVarInt16Slice slice );
Functions
overall
cmp_int16_c
int cmp_int16_c( int16_t a, int16_t b );
Compares two int16_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/int16.h" int main() { init_tap_c_(); expect_lt_c_( cmp_int16_c( -32768, 0 ) ); expect_lt_c_( cmp_int16_c( -1, 0 ) ); expect_eq_c_( cmp_int16_c( 0, 0 ) ); expect_gt_c_( cmp_int16_c( 1, 0 ) ); expect_gt_c_( cmp_int16_c( 32767, 0 ) ); return finish_tap_c_(); }
int16_c_
#define int16_c_( Value )
Macro function that casts the Value as int16_t.
conv
int64_to_int16_c
bool int64_to_int16_c( int64_t src, int16_t dst[static 1] );
Via the macro CONV_C_ implemented function. Returns true if the int64_t value can be represented in a int16_t variable, otherwise false.
#include "clingo/lang/expect.h" #include "clingo/type/int16.h" int main( void ) { init_tap_c_(); int16_t i16 = 0; // ------------------------------------------------------------ max - int64_t int64_t i64 = 32767; // INT16_MAX expect_c_( int64_to_int16_c( i64, &i16 ) ); expect_c_( i16 == 32767 ); ++i64; // 32768 expect_c_( not int64_to_int16_c( i64, &i16 ) ); // ------------------------------------------------------------ min - int32_t int32_t i32 = -32768; // INT16_MIN expect_c_( int64_to_int16_c( i32, &i16 ) ); expect_c_( i16 == -32768 ); --i32; // -32769 expect_c_( not int64_to_int16_c( i32, &i16 ) ); return finish_tap_c_(); }
uint64_to_int16_c
bool uint64_to_int16_c( uint64_t src, int16_t dst[static 1] );
Via the macro CONV_C_ implemented function. Returns true if the uint64_t value can be represented in a int16_t variable, otherwise false.
#include "clingo/lang/expect.h" #include "clingo/type/int16.h" int main( void ) { init_tap_c_(); int16_t i16 = 0; // ----------------------------------------------------------------- uint64_t uint64_t u64 = 32767; // INT16_MAX expect_c_( uint64_to_int16_c( u64, &i16 ) ); expect_c_( i16 == 32767 ); ++u64; // 32768 expect_c_( not uint64_to_int16_c( u64, &i16 ) ); return finish_tap_c_(); }
swap
swap_int16_c
int16_t swap_int16_c( int16_t val );
Returns val with a changed byte order.
#include "clingo/lang/expect.h" #include "clingo/type/int16.h" int main( void ) { init_tap_c_(); // 0x0001 -> 0x0100 expect_c_( swap_int16_c( 1 ) == 256 ); // 0x2080 -> 0x8020 expect_c_( swap_int16_c( 0x2080 ) == -32736 ); return finish_tap_c_(); }
swap_int16_from_c
int16_t swap_int16_from_c( int16_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/int16.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; // 0x0001 -> 0x0100 expect_c_( swap_int16_from_c( 1, othOrder ) == 256); expect_c_( swap_int16_from_c( 1, sysOrder ) == 1 ); // 0x2080 -> 0x8020 expect_c_( swap_int16_from_c( 0x2080, sysOrder ) == 0x2080 ); expect_c_( swap_int16_from_c( 0x2080, othOrder ) == -32736 ); return finish_tap_c_(); }
swap_int16_to_c
int16_t swap_int16_to_c( int16_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/int16.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; // 0x0001 -> 0x0100 expect_c_( swap_int16_to_c( 1, othOrder ) == 256); expect_c_( swap_int16_to_c( 1, sysOrder ) == 1 ); // 0x2080 -> 0x8020 expect_c_( swap_int16_to_c( 0x2080, sysOrder ) == 0x2080 ); expect_c_( swap_int16_to_c( 0x2080, othOrder ) == -32736 ); return finish_tap_c_(); }
algo
cmp_int16_slice_c
int cmp_int16_slice_c( cInt16Slice a, cInt16Slice b );
Via the macro CMP_SLICE_C_ implemented function.
count_eq_int16_c
int64_t count_eq_int16_c( cInt16Slice slice, int16_t val );
Via the macro COUNT_EQ_C_ implemented function.
find_int16_c
int16_t const* find_int16_c( cInt16Slice slice, int16_t val );
Via the macro FIND_VAL_C_ implemented function.
max_int16_c
int16_t const* max_int16_c( cInt16Slice slice );
Via the macro FIND_MAX_C_ implemented function.
min_int16_c
int16_t const* min_int16_c( cInt16Slice slice );
Via the macro FIND_MIN_C_ implemented function.
prod_int16_c
bool prod_int16_c( cInt16Slice 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_int16_slice_c
void qsort_int16_slice_c( cVarInt16Slice slice );
Via the macro QSORT_C_ implemented function.
reverse_int16_slice_c
void reverse_int16_slice_c( cVarInt16Slice slice );
Via the macro REVERSE_C_ implemented function.
rotate_int16_slice_c
void rotate_int16_slice_c( cVarInt16Slice slice, int64_t distance );
Via the macro ROTATE_C_ implemented function.
sum_int16_c
bool sum_int16_c( cInt16Slice 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.