uint16
Overview
Module with functions and types to work with uint16_t values.
Types and Definitions
Generated
cUint16Slice
struct cUint16Slice
{
int64_t s;
uint16_t const* v;
};
typedef struct cUint16Slice cUint16Slice;
Via the macro SLICES_C_ generated struct.
cVarUint16Slice
struct cVarUint16Slice
{
int64_t s;
uint16_t* v;
};
typedef struct cVarUint16Slice cVarUint16Slice;
Via the macro SLICES_C_ generated struct.
Functions
overall
cmp_uint16_c
int cmp_uint16_c( uint16_t a, uint16_t b );
Compares two uint16_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/uint16.h"
int main( void )
{
init_tap_c_();
expect_lt_c_( cmp_uint16_c( 0, 32767 ) );
expect_lt_c_( cmp_uint16_c( 32766, 32767 ) );
expect_eq_c_( cmp_uint16_c( 32767, 32767 ) );
expect_gt_c_( cmp_uint16_c( 32768, 32767 ) );
expect_gt_c_( cmp_uint16_c( 65535, 32767 ) );
return finish_tap_c_();
}
uint16_c_
#define uint16_c_( Value )
Macro function that casts the Value as uint16_t.
conv
int64_to_uint16_c
bool int64_to_uint16_c( int64_t src, uint16_t dst[static 1] );
Via the macro CONV_C_ implemented function. Returns true if the int64_t value can be represented in a uint16_t variable, otherwise false.
#include "clingo/lang/expect.h"
#include "clingo/type/uint16.h"
int main( void )
{
init_tap_c_();
uint16_t u16 = 0;
// ------------------------------------------------------------ max - int32_t
int32_t i32 = 65535; // UINT16_MAX
expect_c_( int64_to_uint16_c( i32, &u16 ) );
expect_c_( u16 == 65535 );
++i32; // 65536
expect_c_( not int64_to_uint16_c( i32, &u16 ) );
// ------------------------------------------------------------ min - int16_t
int16_t i16 = 0;
expect_c_( int64_to_uint16_c( i16, &u16 ) );
expect_c_( u16 == 0 );
--i16; // -1
expect_c_( not int64_to_uint16_c( i16, &u16 ) );
return finish_tap_c_();
}
uint64_to_uint16_c
bool uint64_to_uint16_c( uint64_t src, uint16_t dst[static 1] );
Via the macro CONV_C_ implemented function. Returns true if the uint16_t value can be represented in a uint16_t variable, otherwise false.
#include "clingo/lang/expect.h"
#include "clingo/type/uint16.h"
int main( void )
{
init_tap_c_();
uint16_t u16 = 0;
// ----------------------------------------------------------------- uint32_t
uint32_t u32 = 65535; // UINT16_MAX
expect_c_( uint64_to_uint16_c( u32, &u16 ) );
expect_c_( u16 == 65535 );
++u32; // 65536
expect_c_( not uint64_to_uint16_c( u32, &u16 ) );
return finish_tap_c_();
}
swap
swap_uint16_c
uint16_t swap_uint16_c( uint16_t val );
Returns val with a changed byte order.
#include "clingo/lang/expect.h"
#include "clingo/type/uint16.h"
int main( void )
{
init_tap_c_();
expect_c_( swap_uint16_c( 0x2080 ) ==
0x8020 );
return finish_tap_c_();
}
swap_uint16_from_c
uint16_t swap_uint16_from_c( uint16_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/uint16.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_uint16_from_c( 0x2080, sysOrder ) ==
0x2080 );
expect_c_( swap_uint16_from_c( 0x2080, othOrder ) ==
0x8020 );
return finish_tap_c_();
}
swap_uint16_to_c
uint16_t swap_uint16_to_c( uint16_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/uint16.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_uint16_to_c( 0x2080, sysOrder ) ==
0x2080 );
expect_c_( swap_uint16_to_c( 0x2080, othOrder ) ==
0x8020 );
return finish_tap_c_();
}
algo
cmp_uint16_slice_c
int cmp_uint16_slice_c( cUint16Slice a, cUint16Slice b );
Via the macro CMP_SLICE_C_ implemented function.
count_eq_uint16_c
int64_t count_eq_uint16_c( cUint16Slice slice, uint16_t val );
Via the macro COUNT_EQ_C_ implemented function.
find_uint16_c
uint16_t const* find_uint16_c( cUint16Slice slice, uint16_t val );
Via the macro FIND_VAL_C_ implemented function.
max_uint16_c
uint16_t const* max_uint16_c( cUint16Slice slice );
Via the macro FIND_MAX_C_ implemented function.
min_uint16_c
uint16_t const* min_uint16_c( cUint16Slice slice );
Via the macro FIND_MIN_C_ implemented function.
prod_uint16_c
bool prod_uint16_c( cUint16Slice slice, uint64_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_uint16_slice_c
void qsort_uint16_slice_c( cVarUint16Slice slice );
Via the macro QSORT_C_ implemented function.
reverse_uint16_slice_c
void reverse_uint16_slice_c( cVarUint16Slice slice );
Via the macro REVERSE_C_ implemented function.
rotate_uint16_slice_c
void rotate_uint16_slice_c( cVarUint16Slice slice, int64_t distance );
Via the macro ROTATE_C_ implemented function.
sum_uint16_c
bool sum_uint16_c( cUint16Slice slice, uint64_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.