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 macro SLICES_C_ generated struct.

cVarInt16Slice

struct cVarInt16Slice
{
   int64_t s;
   int16_t* v;
};
typedef struct cVarInt16Slice cVarInt16Slice;

Via the macro SLICES_C_ generated struct.

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

Example
#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.

Example
#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.

Example
#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.

Example
#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.

Example
#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.

Example
#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.