uint8

Overview

Module with functions and types to work with uint8_t values.

Types and Definitions

Generated

cUint8Slice

struct cUint8Slice
{
   int64_t s;
   uint8_t const* v;
};
typedef struct cUint8Slice cUint8Slice;

Via the macro SLICES_C_ generated struct.

cVarUint8Slice

struct cVarUint8Slice
{
   int64_t s;
   uint8_t* v;
};
typedef struct cVarUint8Slice cVarUint8Slice;

Via the macro SLICES_C_ generated struct.

Functions

overall

cmp_uint8_c

int cmp_uint8_c( uint8_t a, uint8_t b );

Compares two uint8_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

Example
#include "clingo/lang/expect.h"
#include "clingo/type/uint8.h"

int main( void )
{
   init_tap_c_();

   expect_lt_c_( cmp_uint8_c(   0, 127 ) );
   expect_lt_c_( cmp_uint8_c( 126, 127 ) );
   expect_eq_c_( cmp_uint8_c( 127, 127 ) );
   expect_gt_c_( cmp_uint8_c( 128, 127 ) );
   expect_gt_c_( cmp_uint8_c( 255, 127 ) );

   return finish_tap_c_();
}

uint8_c_

#define uint8_c_( Value )

Macro function that casts the Value as uint8_t.

conv

int64_to_uint8_c

bool int64_to_uint8_c( int64_t src, uint8_t dst[static 1] );

Via the macro CONV_C_ implemented function. Returns true if the int64_t value can be represented in a uint8_t variable, ohterwise false.

Example
#include "clingo/lang/expect.h"
#include "clingo/type/uint8.h"

int main( void )
{
   init_tap_c_();

   uint8_t u8 = 0;

   // ------------------------------------------------------------ max - int32_t
   int32_t i32 = 255;   // UINT8_MAX
   expect_c_( int64_to_uint8_c( i32, &u8 ) );
   expect_c_( u8 == 255 );

   ++i32;   // 256
   expect_c_( not int64_to_uint8_c( i32, &u8 ) );

   // ------------------------------------------------------------- min - int8_t
   int8_t i8 = 0;
   expect_c_( int64_to_uint8_c( i8, &u8 ) );
   expect_c_( u8 == 0 );

   --i8; // -1
   expect_c_( not int64_to_uint8_c( i8, &u8 ) );

   return finish_tap_c_();
}

uint64_to_uint8_c

bool uint64_to_uint8_c( uint64_t src, uint8_t dst[static 1] );

Via the macro CONV_C_ implemented function. Returns true if the uint64_t value can be represented in a uint8_t variable, otherwise false.

Example
Unresolved directive in uint8.adoc - include::../../../test/clingo/type/uint8/uint64_to_int8.c[]

algo

cmp_uint8_slice_c

int cmp_uint8_slice_c( cUint8Slice a, cUint8Slice b );

Via the macro CMP_SLICE_C_ implemented function.

count_eq_uint8_c

int64_t count_eq_uint8_c( cUint8Slice slice, uint8_t val );

Via the macro COUNT_EQ_C_ implemented function.

find_uint8_c

uint8_t const* find_uint8_c( cUint8Slice slice, uint8_t val );

Via the macro FIND_VAL_C_ implemented function.

max_uint8_c

uint8_t const* max_uint8_c( cUint8Slice slice );

Via the macro FIND_MAX_C_ implemented function.

min_uint8_c

uint8_t const* min_uint8_c( cUint8Slice slice );

Via the macro FIND_MIN_C_ implemented function.

prod_uint8_c

bool prod_uint8_c( cUint8Slice 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_uint8_slice_c

void qsort_uint8_slice_c( cVarUint8Slice slice );

Via the macro QSORT_C_ implemented function.

reverse_uint8_slice_c

void reverse_uint8_slice_c( cVarUint8Slice slice );

Via the macro REVERSE_C_ implemented function.

rotate_uint8_slice_c

void rotate_uint8_slice_c( cVarUint8Slice slice, int64_t distance );

Via the macro ROTATE_C_ implemented function.

sum_uint8_c

bool sum_uint8_c( cUint8Slice 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.