uint32

Overview

Module with functions and types to work with uint32_t values.

Types and Definitions

Generated

cUint32Slice

struct cUint32Slice
{
   int64_t s;
   uint32_t const* v;
};
typedef struct cUint32Slice cUint32Slice;

Via the macro SLICES_C_ generated struct.

cVarUint32Slice

struct cVarUint32Slice
{
   int64_t s;
   uint32_t* v;
};
typedef struct cVarUint32Slice cVarUint32Slice;

Via the macro SLICES_C_ generated struct.

Functions

overall

cmp_uint32_c

int cmp_uint32_c( uint32_t a, uint32_t b );

Compares two uint32_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 to b

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

int main( void )
{
   init_tap_c_();

   expect_lt_c_( cmp_uint32_c(          0, 2147483647 ) );
   expect_lt_c_( cmp_uint32_c( 2147483646, 2147483647 ) );
   expect_eq_c_( cmp_uint32_c( 2147483647, 2147483647 ) );
   expect_gt_c_( cmp_uint32_c( 2147483648, 2147483647 ) );
   expect_gt_c_( cmp_uint32_c( 4294967295, 2147483647 ) );

   return finish_tap_c_();
}

uint32_c_

#define uint32_c_( Value )

Macro function that casts the Value as uint32_t.

conv

int64_to_uint32_c

bool int64_to_uint32_c( int64_t src, uint32_t dst[static 1] );

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

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

int main( void )
{
   init_tap_c_();

   uint32_t u32 = 0;

   // ------------------------------------------------------------ max - int64_t
   int64_t i64 = 4294967295;  // UINT32_MAX
   expect_c_( int64_to_uint32_c( i64, &u32 ) );
   expect_c_( u32 == 4294967295 );

   ++i64;   // 4294967296
   expect_c_( not int64_to_uint32_c( i64, &u32 ) );

   // ------------------------------------------------------------ min - int32_t
   int32_t i32 = 0;
   expect_c_( int64_to_uint32_c( i32, &u32 ) );
   expect_c_( u32 == 0 );

   --i32;   // -1
   expect_c_( not int64_to_uint32_c( i32, &u32 ) );

   return finish_tap_c_();
}

uint64_to_uint32_c

bool uint64_to_uint32_c( uint64_t src, uint32_t dst[static 1] );

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

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

int main( void )
{
   init_tap_c_();

   uint32_t u32 = 0;

   // ----------------------------------------------------------------- uint64_t
   uint64_t u64 = 4294967295; // UINT32_MAX
   expect_c_( uint64_to_uint32_c( u64, &u32 ) );
   expect_c_( u64 == 4294967295 );

   ++u64;   // 4294967296
   expect_c_( not uint64_to_uint32_c( u64, &u32 ) );

   return finish_tap_c_();
}

swap

swap_uint32_c

uint32_t swap_uint32_c( uint32_t val );

Returns val with a changed byte order.

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

int main( void )
{
   init_tap_c_();

   expect_c_( swap_uint32_c( 0xb7af0000 ) ==
                             0x0000afb7 );

   return finish_tap_c_();
}

swap_uint32_from_c

uint32_t swap_uint32_from_c( uint32_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/uint32.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_uint32_from_c( 0xb7af0000, sysOrder ) ==
                                  0xb7af0000 );

   expect_c_( swap_uint32_from_c( 0xb7af0000, othOrder ) ==
                                  0x0000afb7 );

   return finish_tap_c_();
}

swap_uint32_to_c

uint32_t swap_uint32_to_c( uint32_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/uint32.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_uint32_to_c( 0xb7af0000, sysOrder ) ==
                                0xb7af0000 );

   expect_c_( swap_uint32_to_c( 0xb7af0000, othOrder ) ==
                                0x0000afb7 );

   return finish_tap_c_();
}

math

next_pow2_uint32_c

uint32_t next_pow2_uint32_c( uint32_t val );

Smallest power of 2 greater than val.

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

algo

cmp_uint32_slice_c

int cmp_uint32_slice_c( cUint32Slice a, cUint32Slice b );

Via the macro CMP_SLICE_C_ implemented function.

count_eq_uint32_c

int64_t count_eq_uint32_c( cUint32Slice slice, uint32_t val );

Via the macro COUNT_EQ_C_ implemented function.

find_uint32_c

uint32_t const* find_uint32_c( cUint32Slice slice, uint32_t val );

Via the macro FIND_VAL_C_ implemented function.

max_uint32_c

uint32_t const* max_uint32_c( cUint32Slice slice );

Via the macro FIND_MAX_C_ implemented function.

min_uint32_c

uint32_t const* min_uint32_c( cUint32Slice slice );

Via the macro FIND_MIN_C_ implemented function.

prod_uint32_c

bool prod_uint32_c( cUint32Slice 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_uint32_slice_c

void qsort_uint32_slice_c( cVarUint32Slice slice );

Via the macro QSORT_C_ implemented function.

reverse_uint32_slice_c

void reverse_uint32_slice_c( cVarUint32Slice slice );

Via the macro REVERSE_C_ implemented function.

rotate_uint32_slice_c

void rotate_uint32_slice_c( cVarUint32Slice slice, int64_t distance );

Via the macro ROTATE_C_ implemented function.

sum_uint32_c

bool sum_uint32_c( cUint32Slice 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.