/********************************************************************************************************* * ------------------------------------------------------------------------------------------------------ * file description * ------------------------------------------------------------------------------------------------------ * \file intl.h * \unit intl * \brief This is a simple large inter number calculate module for C language * \author Lamdonn * \version v1.0.0 * \license GPL-2.0 * \copyright Copyright (C) 2023 Lamdonn. ********************************************************************************************************/ #ifndef __intl_H #define __intl_H #include #include #include #include #include #include "intl_cfg.h" /* Version infomation */ #define INTL_V_MAJOR 1 #define INTL_V_MINOR 0 #define INTL_V_PATCH 0 /** * \brief A structure to represent a long bits integer. * * This structure uses a union to store the long bits integer in two different ways: * - An array of `INTL_U16_PARTS` uint16_t values, allowing for operations on individual 16-bit segments. * - An array of `INTL_U32_PARTS` uint32_t values, providing a way to work with 32-bit segments. * * The union allows for flexibility in how the data is accessed and manipulated, * depending on the needs of the operations being performed. */ typedef struct { union { uint16_t u16[INTL_U16_PARTS]; ///< Array of uint16_t values representing the long bit integer in 16-bit segments. uint32_t u32[INTL_U32_PARTS]; ///< Array of uint32_t values representing the long bit integer in 32-bit segments. }; } intl; /** * \brief intl large integer api declaration, support for basic addition, subtraction, multiplication, division, etc. */ intl intl_add(intl a, intl b); intl intl_sub(intl a, intl b); intl intl_mul(intl a, intl b); intl intl_div(intl a, intl b); intl intl_mod(intl a, intl b); intl intl_and(intl a, intl b); intl intl_xor(intl a, intl b); intl intl_or(intl a, intl b); intl intl_shl(intl a, uint32_t amount); intl intl_shr(intl a, uint32_t amount); intl intl_not(intl a); intl intl_abs(intl a); intl intl_inc(intl a); intl intl_dec(intl a); intl intl_neg(intl a); intl intl_from(const char *str); intl intl_from2(int value); const char* intl_sdec(intl a, char buffer[INTL_MAX_DEC]); const char* intl_shex(intl a, char buffer[INTL_MAX_HEX]); const char* intl_sbin(intl a, char buffer[INTL_MAX_BIN]); int intl_cmp(intl a, intl b); int intl_sign(intl a); /** * \brief Converts a integer to an intl number. * \param[in] value: The integer to convert. * \return The corresponding intl number initialized with the given value. */ #define intl(value) intl_from2(value) #endif