int8

Overview

Module with functions and types to work with int8_t values.

Types and Definitions

Generated

cInt8Slice

struct cInt8Slice
{
   int64_t s;
   int8_t const* v;
};
typedef struct cInt8Slice cInt8Slice;

Via the macro SLICES_C_ generated struct.

cVarInt8Slice

struct cVarInt8Slice
{
   int64_t s;
   int8_t* v;
};
typedef struct cVarInt8Slice cVarInt8Slice;

Via the macro SLICES_C_ generated struct.

Functions

overall

cmp_int8_c

int cmp_int8_c( int8_t a, int8_t b );

Compares two int8_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/int8.h"

int main( void )
{
   init_tap_c_();

   expect_lt_c_( cmp_int8_c( -128, 0 ) );
   expect_lt_c_( cmp_int8_c(   -1, 0 ) );
   expect_eq_c_( cmp_int8_c(    0, 0 ) );
   expect_gt_c_( cmp_int8_c(    1, 0 ) );
   expect_gt_c_( cmp_int8_c(  127, 0 ) );

   return finish_tap_c_();
}

int8_c_

#define int8_c_( Value )

Macro function that casts the Value as int8_t.

conv

int64_to_int8_c

bool int64_to_int8_c( int64_t src, int8_t dst[static 1] );

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

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

int main( void )
{
   init_tap_c_();

   int8_t i8 = 0;

   // ------------------------------------------------------------ max - int64_t
   int64_t i64 = 127;   // INT8_MAX
   expect_c_( int64_to_int8_c( i64, &i8 ) );
   expect_c_( i8 == 127 );

   ++i64;   // 128
   expect_c_( not int64_to_int8_c( i64, &i8 ) );

   // ------------------------------------------------------------ min - int16_t
   int16_t i16 = -128;  // INT8_MIN
   expect_c_( int64_to_int8_c( i16, &i8 ) );
   expect_c_( i8 == -128 );

   --i16;   // -129
   expect_c_( not int64_to_int8_c( i16, &i8 ) );

   return finish_tap_c_();
}

uint64_to_int8_c

bool uint64_to_int8_c( uint64_t src, int8_t dst[static 1] );

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

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

int main( void )
{
   init_tap_c_();

   int8_t i8 = 0;

   // ----------------------------------------------------------------- uint64_t
   uint64_t u64 = 127;  // INT8_MAX
   expect_c_( uint64_to_int8_c( u64, &i8 ) );
   expect_c_( i8 == 127 );

   ++u64;   // 128
   expect_c_( not uint64_to_int8_c( u64, &i8 ) );

   return finish_tap_c_();
}

algo

cmp_int8_slice_c

int64_t cmp_int8_slice_c( cInt8Slice a, cInt8Slice b );

Via the macro CMP_SLICE_C_ implemented function.

count_eq_int8_c

int64_t count_eq_int8_c( cInt8Slice slice, int8_t val );

Via the macro COUNT_EQ_C_ implemented function.

find_int8_c

int8_t const* find_int8_c( cInt8Slice slice, int8_t val );

Via the macro FIND_VAL_C_ implemented function.

max_int8_c

int8_t const* max_int8_c( cInt8Slice slice );

Via the macro FIND_MAX_C_ implemented function.

min_int8_c

int8_t const* min_int8_c( cInt8Slice slice );

Via the macro FIND_MIN_C_ implemented function.

prod_int8_c

bool prod_int8_c( cInt8Slice 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_int8_slice_c

void qsort_int8_slice_c( cVarInt8Slice slice );

Via the macro QSORT_C_ implemented function.

reverse_int8_slice_c

void reverse_int8_slice_c( cVarInt8Slice slice );

Via the macro REVERSE_C_ implemented function.

rotate_int8_slice_c

void rotate_var_int8_slice_c( cVarInt8Slice slice, int64_t distance );

Via the macro ROTATE_C_ implemented function.

sum_int8_c

bool sum_int8_c( cInt8Slice 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.