int64

Overview

Modue with functions and types to work with int64_t values.

Types and Definitions

Generated

cInt64Slice

struct cInt64Slice
{
   int64_t s;
   int64_t const* v;
};
typedef struct cInt64Slice cInt64Slice;

Via the macro SLICES_C_ generated struct.

cVarInt64Slice

struct cVarInt64Slice
{
   int64_t s;
   int64_t* v;
};
typedef struct cVarInt64Slice cVarInt64Slice;

Via the macro SLICES_C_ generated struct.

Functions

overall

cmp_int64_c

int cmp_int64_c( int64_t a, int64_t b );

Compares two int64_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/int64.h"

int main( void )
{
   init_tap_c_();

   expect_lt_c_( cmp_int64_c( -9223372036854775807-1, 0 ) );
   expect_lt_c_( cmp_int64_c(                     -1, 0 ) );
   expect_eq_c_( cmp_int64_c(                      0, 0 ) );
   expect_gt_c_( cmp_int64_c(                      1, 0 ) );
   expect_gt_c_( cmp_int64_c(    9223372036854775807, 0 ) );

   return finish_tap_c_();
}

int64_c_

#define int64_c_( Value )

Macro function that casts the Value as int64_t.

conv

uint64_to_int64_c

bool uint64_to_int64_c( uint64_t src, int64_t dst[static 1] );

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

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

int main( void )
{
   init_tap_c_();

   int64_t i64 = 0;

   // ----------------------------------------------------------------- uint64_t
   uint64_t u64 = 9223372036854775807; // INT64_MAX
   expect_c_( uint64_to_int64_c( u64, &i64 ) );
   expect_c_( i64 == 9223372036854775807 );

   ++u64;   // 9223372036854775808
   expect_c_( not uint64_to_int64_c( u64, &i64 ) );

   return finish_tap_c_();
}

swap

swap_int64_c

int64_t swap_int64_c( int64_t val );

Returns val with a changed byte order.

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

int main( void )
{
   init_tap_c_();

   expect_c_( swap_int64_c( 0x0123456789abcdef ) ==
                            0xefcdab8967452301 );

   return finish_tap_c_();
}

swap_int64_from_c

int64_t swap_int64_from_c( int64_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/int64.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_int64_from_c( 0x0123456789abcdef, sysOrder ) ==
                                 0x0123456789abcdef );

   expect_c_( swap_int64_from_c( 0x0123456789abcdef, othOrder ) ==
                                 0xefcdab8967452301 );

   return finish_tap_c_();
}

swap_int64_to_c

int64_t swap_int64_to_c( int64_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/int64.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_int64_to_c( 0x0123456789abcdef, sysOrder ) ==
                               0x0123456789abcdef );

   expect_c_( swap_int64_to_c( 0x0123456789abcdef, othOrder ) ==
                               0xefcdab8967452301 );

   return finish_tap_c_();
}

math

hash_int64_c

uint64_t hash_int64_c( int64_t val );

Returns a hash value of the int64_t value.

next_pow2_int64_c

int64_t next_pow2_int64_c( int64_t val );

Returns the next power of two value.

algo

bsearch_int64_c

int64_t const* bsearch_int64_c( cInt64Slice slice, int64_t val );

Via the macro BSEARCH_C_ implemented function.

cmp_int64_slice_c

int cmp_int64_slice_c( cInt64Slice a, cInt64Slice b );

Via the macro CMP_SLICE_C_ implemented function.

count_eq_int64_c

int64_t count_eq_int64_c( cInt64Slice slice, int64_t val );

Via the macro COUNT_EQ_C_ implemented function.

find_int64_c

int64_t const* find_int64_c( cInt64Slice slice, int64_t val );

Via the macro FIND_VAL_C_ implemented function.

max_int64_c

int64_t const* max_int64_c( cInt64Slice slice );

Via the macro FIND_MAX_C_ implemented function.

min_int64_c

int64_t const* min_int64_c( cInt64Slice slice );

Via the macro FIND_MIN_C_ implemented function.

prod_int64_c

bool prod_int64_c( cInt64Slice 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_int64_slice_c

void qsort_int64_slice_c( cVarInt64Slice slice );

Via the macro QSORT_C_ implemented function.

remove_int64_c

bool remove_int64_c( cVarInt64Slice slice[static 1], int64_t pos);

Via the macro REMOVE_C_ implemented function.

reverse_int64_slice_c

void reverse_int64_slice_c( cVarInt64Slice slice );

Via the macro REVERSE_C_ implemented function.

rotate_int64_slice_c

void rotate_int64_slice_c( cVarInt64Slice slice, int64_t distance );

Via the macro ROTATE_C_ implemented function.

sum_int64_c

bool sum_int64_c( cInt64Slice 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.

take_int64_c

bool take_int64_c( cVarInt64Slice slice[static 1],
                   int64_t pos,
                   int64_t val[static 1] );

Via the macro TAKE_C_ implemented function.