Math Processor Unit Library

libmpu – library of arithmetic functions for integer, real, and complex numbers of increased digit capacity

16 Commits   0 Branches   2 Tags

#ifndef   __LIB_MPU_H
#define   __LIB_MPU_H

#ifdef  __cplusplus
extern "C" {
#endif

#define MPU_REAL_IO_LIMIT            @LIBMPU_REAL_IO_LIMIT@
#define MPU_MATH_FN_LIMIT            @LIBMPU_REAL_MATH_F_LIMIT@

#define MPU_BYTE_ORDER               @GCC_BYTE_ORDER@
#define MPU_BYTE_ORDER_BIG_ENDIAN    @GCC_BYTE_ORDER_BIG_ENDIAN@
#define MPU_BYTE_ORDER_LITTLE_ENDIAN @GCC_BYTE_ORDER_LITTLE_ENDIAN@

#define MPU_WORD_ORDER               @GCC_FLOAT_WORD_ORDER@
#define MPU_WORD_ORDER_BIG_ENDIAN    @GCC_FLOAT_WORD_ORDER_BIG_ENDIAN@
#define MPU_WORD_ORDER_LITTLE_ENDIAN @GCC_FLOAT_WORD_ORDER_LITTLE_ENDIAN@

#define BITS_PER_MACHINE_REGISTER    @MACHINE_REGISTER_WIDTH@

/******************************************
  Minimal addressible UNIT of information:
 */
typedef @GCC_UINT8_TYPE@  __mpu_UNIT_t; /* unsigned UNIT */
typedef @GCC_INT8_TYPE@  __mpu_SUNIT_t; /* signed UNIT */
#define BITS_PER_UNIT_T  @GCC_CHAR_WIDTH@

typedef @GCC_UINT8_TYPE@  __mpu_byte_t; /* unsigned byte */
typedef @GCC_INT8_TYPE@  __mpu_sbyte_t; /* signed byte */
#define BITS_PER_BYTE_T  @GCC_CHAR_WIDTH@

/**********
  ADDRESS:
 */
typedef @GCC_UINTPTR_TYPE@  __mpu_address_t; /* unsigned ADDRESS */
typedef @GCC_UINTPTR_TYPE@  __mpu_saddress_t; /* signed DIFFADDRESS */

/*******************************
  Signed DIFFerence of two PTR:
 */
typedef @GCC_PTRDIFF_TYPE@  __mpu_ptrdiff_t; /* signed PTRDIFF */

/*************
  SIZE types:
 */
typedef @GCC_SIZE_TYPE@  __mpu_size_t; /* unsigned SIZE */
typedef @GCC_INTMAX_TYPE@  __mpu_ssize_t; /* signed SIZE: is type of a byte count, or error. */

/*****************************
  COUNTER is always unsigned:
 */
typedef __mpu_size_t  __mpu_count_t;


/***************************
  ERRNO is always signed:
 */
typedef int __mpu_error_t;


/*******
  VOID:
 */
#define __mpu_void_t  void


#define __mpu_UINT32_C(c) c ## @LIBMPU_UINT32_CONST_SUFFIX@
#define __mpu_UINT64_C(c) c ## @LIBMPU_UINT64_CONST_SUFFIX@


/***************************************************************
  Тип данных, используемый для операций с выровненной памятью.
  Беззнаковый( 32 bits ).
 ***************************************************************/
#define __mem_op_t      @GCC_UINT32_TYPE@
#define MEM_OP_SIZE     (sizeof(__mem_op_t))
#define MEM_OP_BYTES    4
#define MEM_OP_BITS    32

/*********************************
  Base data types:
 */
typedef @GCC_INT8_TYPE@  __mpu_int8_t;
typedef @GCC_UINT8_TYPE@  __mpu_uint8_t;
typedef @GCC_INT16_TYPE@  __mpu_int16_t;
typedef @GCC_UINT16_TYPE@  __mpu_uint16_t;
typedef @GCC_INT32_TYPE@  __mpu_int32_t;
typedef @GCC_UINT32_TYPE@  __mpu_uint32_t;
typedef @GCC_INT64_TYPE@  __mpu_int64_t;
typedef @GCC_UINT64_TYPE@  __mpu_uint64_t;

/*******
  REAL:
 */
typedef float   __mpu_real32_t;
typedef double  __mpu_real64_t;

/*********************************
  CHAR types are always unsigned:
 */
typedef @GCC_UINT8_TYPE@  __mpu_char8_t;
typedef @GCC_UINT16_TYPE@  __mpu_char16_t;
typedef @GCC_UINT32_TYPE@  __mpu_char32_t;

/*********************************************************
  UTF-8, UCS2, UCS4 types. UTF-8 CHAR is always unsigned:
 */
typedef @GCC_UINT8_TYPE@  __mpu_utf8_t;
typedef @GCC_UINT16_TYPE@  __mpu_ucs2_t;
typedef @GCC_UINT32_TYPE@  __mpu_ucs4_t;

/*********************************************************
  Always signed with a size larger than any type of char:
 */
typedef @GCC_INT64_TYPE@  __mpu_int_c;


extern void __mpu_init( void );
extern void __mpu_free_context( void );

/********************************************************
  Error numbers:
 */
extern __mpu_error_t *__ptr_integer_error_no( void );
extern __mpu_error_t *__ptr_real_error_no   ( void );
extern __mpu_error_t *__ptr_complex_error_no( void );
extern __mpu_error_t *__ptr_math_error_no   ( void );
#define __mpu_integer_error_no  (*__ptr_integer_error_no())
#define __mpu_real_error_no     (*__ptr_real_error_no())
#define __mpu_complex_error_no  (*__ptr_complex_error_no())
#define __mpu_math_error_no     (*__ptr_math_error_no())

extern __mpu_error_t *__ptr_extra_warnings  ( void );
#define __mpu_extra_warnings    (*__ptr_extra_warnings())


extern void __mpu_clear_iflags( void );
extern void __mpu_clear_rflags( void );
extern void __mpu_clear_mflags( void );


/* Get integer flags: */
extern  int __mpu_gta( void );
extern  int __mpu_gtc( void );
extern  int __mpu_gto( void );
extern  int __mpu_gts( void );
extern  int __mpu_gtp( void );
extern  int __mpu_gtz( void );
extern  int __mpu_gtr( void );
extern  int __mpu_gtv( void );

/* Set integer flags: */
extern void __mpu_sta( void );
extern void __mpu_stc( void );
extern void __mpu_sto( void );
extern void __mpu_sts( void );
extern void __mpu_stp( void );
extern void __mpu_stz( void );
extern void __mpu_str( void );
extern void __mpu_stv( void );

/* Clear integer flags: */
extern void __mpu_cla( void );
extern void __mpu_clc( void );
extern void __mpu_clo( void );
extern void __mpu_cls( void );
extern void __mpu_clp( void );
extern void __mpu_clz( void );
extern void __mpu_clr( void );
extern void __mpu_clv( void );

/* Complement integer flags: */
extern void __mpu_cma( void );
extern void __mpu_cmc( void );
extern void __mpu_cmo( void );
extern void __mpu_cms( void );
extern void __mpu_cmp( void );
extern void __mpu_cmz( void );
extern void __mpu_cmr( void );
extern void __mpu_cmv( void );


/* Get real flags: */
extern  int __mpu_gtdom( void );
extern  int __mpu_gtsng( void );
extern  int __mpu_gtovf( void );
extern  int __mpu_gtudf( void );
extern  int __mpu_gttls( void );
extern  int __mpu_gtpls( void );
extern  int __mpu_gtind( void );
extern  int __mpu_gtinx( void );

/* Set real flags: */
extern void __mpu_stdom( void );
extern void __mpu_stsng( void );
extern void __mpu_stovf( void );
extern void __mpu_studf( void );
extern void __mpu_sttls( void );
extern void __mpu_stpls( void );
extern void __mpu_stind( void );
extern void __mpu_stinx( void );

/* Clear real flags: */
extern void __mpu_cldom( void );
extern void __mpu_clsng( void );
extern void __mpu_clovf( void );
extern void __mpu_cludf( void );
extern void __mpu_cltls( void );
extern void __mpu_clpls( void );
extern void __mpu_clind( void );
extern void __mpu_clinx( void );

/* Complement real flags: */
extern void __mpu_cmdom( void );
extern void __mpu_cmsng( void );
extern void __mpu_cmovf( void );
extern void __mpu_cmudf( void );
extern void __mpu_cmtls( void );
extern void __mpu_cmpls( void );
extern void __mpu_cmind( void );
extern void __mpu_cminx( void );


/********************************************************
  Math ERRNO declarations:
 */
#define MPU_MATH_ERROR_MSG_SIZE  4096

#define __EUNKNOWN__     0   /* unknown error type (for all sources) */

/**********************
  Integer error types:
 */
#define __I_ESIZE__      1   /* Invalid size of operand(s)  */
#define __I_ESHIFT__     2   /* Invalid number of shifts    */
#define __I_ENUMBER__    3   /* Invalid number              */
#define __I_ERADIX__     4   /* Invalid radix               */

#define __I_MAX_ERRNO    5

/*******************
  Real error types:
 */
#define __R_ESIZE__      1 /* Invalid size of operand(s)       */
#define __R_ETRUNC__     2 /* Invalid number of TRUNC bits(BZ) */

#define __R_MAX_ERRNO    3

/**********************
  Complex error types:
 */
#define __C_EDIVZEROBYZERO__   1 /* Complex attempted division by zero */
#define __C_ELOGOFZERO__       2 /* Complex attempted LOG of zero magnitude number */
#define __C_EPOWOFZERO__       3 /* Complex attempted POW of zero magnitude number */

#define __C_MAX_ERRNO    4

/*******************
  Math error types:
 */
#define __DOMAIN__       1   /* argument domain error       */
#define __SING__         2   /* argument singularity        */
#define __OVERFLOW__     3   /* overflow range error        */
#define __UNDERFLOW__    4   /* underflow range error       */
#define __TLOSS__        5   /* total loss of precision     */
#define __PLOSS__        6   /* partial loss of precision   */
#define __INVALID__      7   /* -InD - produsing operation  */
#define __INEXACT__      8   /* inexact result of operation */

#define __M_MAX_ERRNO    9


/*******************
  Struct Exception:
 */
/***
  __exception.who - источник ошибки.
 ************************************/
#define _UNKNOWN_   4
#define _COMPLEX_   3
#define _REAL_      2
#define _INTEGER_   1
#define _MATH_      0

/***
  __exception.msg_type - тип сообщения.
 ***************************************/
#define         _MSG_   2
#define   _ERROR_MSG_   1
#define _WARNING_MSG_   0

struct __exception
{
   int             who;      /* _COMPLEX_, _REAL_, _INTEGER_, _MATH_ */

   int             type;
   __mpu_char8_t  *name;
   __mpu_char8_t  *msg;
   int             msg_type; /* >= 1 - error, 0 - warning */

   int             nb_a1;    /* number of bytes in arg_1        */
   int             nb_a2;    /* number of bytes in arg_2        */
   int             nb_rv;    /* number of bytes in return_value */

   unsigned char  *arg_1;
   unsigned char  *arg_2;
   unsigned char  *return_value;
};

extern __mpu_utf8_t *
            __mpu_utf8mpu_error( int who, __mpu_error_t errnum );

extern int  __use_default_math_error;
extern int  __mpu_math_error( struct __exception *pexcept );

extern int  __use_default_mpu_warning;
extern void __mpu_warning( struct __exception *pexcept );


/***************************************************************
  Размер данных в байтах:
 ***************************************************************/
/********* integer ******
           =
 ************************/
#define NB_I8           1
#define NB_I16          2
#define NB_I32          4
#define NB_I64          8
#define NB_I128        16
#define NB_I256        32
#define NB_I512        64
#define NB_I1024      128
#define NB_I2048      256
#define NB_I4096      512
#define NB_I8192     1024
#define NB_I16384    2048
#define NB_I32768    4096
#define NB_I65536    8192
#define NB_I_MAX     8192

/********* real *********
           =
 ************************/
#define NB_R32          4
#define NB_R64          8
#define NB_R128        16
#define NB_R256        32
#define NB_R512        64
#define NB_R1024      128
#define NB_R2048      256
#define NB_R4096      512
#define NB_R8192     1024
#define NB_R16384    2048
#define NB_R32768    4096
#define NB_R65536    8192
#define NB_R_MAX     8192

/********* complex ******
           =
 ************************/
#define NB_C32          4
#define NB_C64          8
#define NB_C128        16
#define NB_C256        32
#define NB_C512        64
#define NB_C1024      128
#define NB_C2048      256
#define NB_C4096      512
#define NB_C8192     1024
#define NB_C16384    2048
#define NB_C32768    4096
#define NB_C65536    8192
#define NB_C_MAX     8192


typedef __mpu_byte_t  mpu_int;     /*    integer number */
typedef __mpu_byte_t  mpu_real;    /*       real number */
typedef __mpu_byte_t  mpu_complex; /*    complex number */
typedef __mpu_byte_t *mpu_p_num;   /* pointer to number */


/***************************************************************
  INTEGER DATA TYPES
 ***************************************************************/
typedef __mpu_byte_t  mpu_int8_t[1];
typedef __mpu_byte_t  mpu_int16_t[2];
typedef __mpu_byte_t  mpu_int32_t[4];
typedef __mpu_byte_t  mpu_int64_t[8];
typedef __mpu_byte_t  mpu_int128_t[16];
typedef __mpu_byte_t  mpu_int256_t[32];
typedef __mpu_byte_t  mpu_int512_t[64];
typedef __mpu_byte_t  mpu_int1024_t[128];
typedef __mpu_byte_t  mpu_int2048_t[256];
typedef __mpu_byte_t  mpu_int4096_t[512];
typedef __mpu_byte_t  mpu_int8192_t[1024];
typedef __mpu_byte_t  mpu_int16384_t[2048];
typedef __mpu_byte_t  mpu_int32768_t[4096];
typedef __mpu_byte_t  mpu_int65536_t[8192];
typedef __mpu_byte_t  mpu_wide_int_t[8192];


/***************************************************************
  REAL DATA TYPES
 ***************************************************************/
typedef __mpu_byte_t  mpu_real32_t[4];
typedef __mpu_byte_t  mpu_real64_t[8];
typedef __mpu_byte_t  mpu_real128_t[16];
typedef __mpu_byte_t  mpu_real256_t[32];
typedef __mpu_byte_t  mpu_real512_t[64];
typedef __mpu_byte_t  mpu_real1024_t[128];
typedef __mpu_byte_t  mpu_real2048_t[256];
typedef __mpu_byte_t  mpu_real4096_t[512];
typedef __mpu_byte_t  mpu_real8192_t[1024];
typedef __mpu_byte_t  mpu_real16384_t[2048];
typedef __mpu_byte_t  mpu_real32768_t[4096];
typedef __mpu_byte_t  mpu_real65536_t[8192];
typedef __mpu_byte_t  mpu_wide_real_t[8192];


/***************************************************************
  COMPLEX DATA TYPES

  NOTE:
        Следует помнить, что при вызове функций, работающих
        с комплексными числами надо задавать не фактический,
        а половинный размер комплексных операндов !
        SEE:
           following NB_C32, NB_C64, ..., NB_C1024 NB_C_MAX.
 ***************************************************************/
typedef __mpu_byte_t  mpu_complex32_t[8];
typedef __mpu_byte_t  mpu_complex64_t[16];
typedef __mpu_byte_t  mpu_complex128_t[32];
typedef __mpu_byte_t  mpu_complex256_t[64];
typedef __mpu_byte_t  mpu_complex512_t[128];
typedef __mpu_byte_t  mpu_complex1024_t[256];
typedef __mpu_byte_t  mpu_complex2048_t[512];
typedef __mpu_byte_t  mpu_complex4096_t[1024];
typedef __mpu_byte_t  mpu_complex8192_t[2048];
typedef __mpu_byte_t  mpu_complex16384_t[4096];
typedef __mpu_byte_t  mpu_complex32768_t[8192];
typedef __mpu_byte_t  mpu_complex65536_t[16384];
typedef __mpu_byte_t  mpu_wide_complex_t[16384];


/***************************************************************
                 INTEGER ARITHMETIC OPERATIONS
 ***************************************************************/

extern void iadd    ( mpu_int *c, mpu_int *a, mpu_int *b, int nb );
extern void iadc    ( mpu_int *c, mpu_int *a, mpu_int *b, int nb );
extern void isub    ( mpu_int *c, mpu_int *a, mpu_int *b, int nb );
extern void isbb    ( mpu_int *c, mpu_int *a, mpu_int *b, int nb );

extern void ishl    ( mpu_int *c, mpu_int *a, int nb );
extern void ishr    ( mpu_int *c, mpu_int *a, int nb );
extern void isal    ( mpu_int *c, mpu_int *a, int nb );
extern void isar    ( mpu_int *c, mpu_int *a, int nb );

extern void irol    ( mpu_int *c, mpu_int *a, int nb );
extern void iror    ( mpu_int *c, mpu_int *a, int nb );
extern void ircl    ( mpu_int *c, mpu_int *a, int nb );
extern void ircr    ( mpu_int *c, mpu_int *a, int nb );

extern void ishln   ( mpu_int *c, mpu_int *a, unsigned int ns, int nb );
extern void ishrn   ( mpu_int *c, mpu_int *a, unsigned int ns, int nb );
extern void isaln   ( mpu_int *c, mpu_int *a, unsigned int ns, int nb );
extern void isarn   ( mpu_int *c, mpu_int *a, unsigned int ns, int nb );

extern void iroln   ( mpu_int *c, mpu_int *a, unsigned int ns, int nb );
extern void irorn   ( mpu_int *c, mpu_int *a, unsigned int ns, int nb );
extern void ircln   ( mpu_int *c, mpu_int *a, unsigned int ns, int nb );
extern void ircrn   ( mpu_int *c, mpu_int *a, unsigned int ns, int nb );

extern void inot    ( mpu_int *c, mpu_int *a, int nb );
extern void ineg    ( mpu_int *c, mpu_int *a, int nb );

extern void iand    ( mpu_int *c, mpu_int *a, mpu_int *b, int nb );

extern void itest   ( mpu_int *a, mpu_int *b, int nb );
extern void icmp    ( mpu_int *a, mpu_int *b, int nb );

extern void ior     ( mpu_int *c, mpu_int *a, mpu_int *b, int nb );
extern void ixor    ( mpu_int *c, mpu_int *a, mpu_int *b, int nb );

extern void iinc    ( mpu_int *c, mpu_int *a, int nb );
extern void idec    ( mpu_int *c, mpu_int *a, int nb );

extern void ixchg   ( mpu_int *a, mpu_int *b, int nb );

extern void icpy    ( mpu_int *c, mpu_int *a, int nb_c, int nb_a );
extern void icvt    ( mpu_int *c, mpu_int *a, int nb_c, int nb_a );

extern void imul    ( mpu_int *prod, mpu_int *num, mpu_int *mul, int nb_prod, int nb_num );
extern void ismul   ( mpu_int *prod, mpu_int *num, mpu_int *mul, int nb_prod, int nb_num );

extern void idiv    ( mpu_int *quot, mpu_int *rem, mpu_int *num, mpu_int *den, int nb );
extern void isdiv   ( mpu_int *quot, mpu_int *rem, mpu_int *num, mpu_int *den, int nb );


/* for integer ...itoa() functions */
#define RADIX_BIN  2
#define RADIX_OCT  8
#define RADIX_DEC 10
#define RADIX_HEX 16

/* for integer ...itoa() functions and real ...rtoa() functions */
#define LOWERCASE  0
#define UPPERCASE  1


extern void iatoi   ( mpu_int *c, __mpu_char8_t *str, int nb );
extern void iatoui  ( mpu_int *c, __mpu_char8_t *str, int nb );

extern void iitoa   ( __mpu_char8_t *str, mpu_int *a, int radix, int uf, int nb );
extern void iuitoa  ( __mpu_char8_t *str, mpu_int *a, int radix, int uf, int nb );


/***************************************************************
                   REAL ARITHMETIC OPERATIONS
 ***************************************************************/

extern int  _sizeof_exp       ( int nb );
extern int  _real_mant_digs   ( int nb );
extern int  _real_digs        ( int nb );
extern int  _real_max_string  ( int nb );
extern void _real_epsilon     ( mpu_real *c, int nb );
extern void _real_max_10_exp  ( mpu_int *e, int nb_e, int nb_r );
extern void _real_min_10_exp  ( mpu_int *e, int nb_e, int nb_r );
extern void _real_max_max_exp ( mpu_int *e, int nb_e, int nb_r );
extern void _real_max_exp     ( mpu_int *e, int nb_e, int nb_r );
extern void _real_min_exp     ( mpu_int *e, int nb_e, int nb_r );

extern void _m_zero           ( mpu_real *c, int nb );
extern void _m_half           ( mpu_real *c, int nb );
extern void _m_one            ( mpu_real *c, int nb );
extern void _m_two            ( mpu_real *c, int nb );
extern void _m_ten            ( mpu_real *c, int nb );
extern void _m_mten           ( mpu_real *c, int nb );
extern void _m_32             ( mpu_real *c, int nb );
extern void _m_PI             ( mpu_real *c, int nb );
extern void _m_E              ( mpu_real *c, int nb );
extern void _m_1_ln2          ( mpu_real *c, int nb );
extern void _m_ln2            ( mpu_real *c, int nb );
extern void _m_1_ln10         ( mpu_real *c, int nb );
extern void _m_ln10           ( mpu_real *c, int nb );
extern void _m_1_lg2          ( mpu_real *c, int nb );
extern void _m_lg2            ( mpu_real *c, int nb );
extern void _m_PI_2           ( mpu_real *c, int nb );
extern void _m_PI_3           ( mpu_real *c, int nb );
extern void _m_PI_4           ( mpu_real *c, int nb );
extern void _m_PI_5           ( mpu_real *c, int nb );
extern void _m_PI_6           ( mpu_real *c, int nb );
extern void _m_1_PI           ( mpu_real *c, int nb );
extern void _m_2_PI           ( mpu_real *c, int nb );
extern void _m_3_PI           ( mpu_real *c, int nb );
extern void _m_4_PI           ( mpu_real *c, int nb );
extern void _m_5_PI           ( mpu_real *c, int nb );
extern void _m_2PI            ( mpu_real *c, int nb );
extern void _m_3PI            ( mpu_real *c, int nb );
extern void _m_1_2PI          ( mpu_real *c, int nb );
extern void _m_1_3PI          ( mpu_real *c, int nb );
extern void _m_1_4PI          ( mpu_real *c, int nb );
extern void _m_1_5PI          ( mpu_real *c, int nb );
extern void _m_1_6PI          ( mpu_real *c, int nb );
extern void _m_3PI_4          ( mpu_real *c, int nb );
extern void _m_SQRTPI         ( mpu_real *c, int nb );
extern void _m_1_SQRTPI       ( mpu_real *c, int nb );
extern void _m_2_SQRTPI       ( mpu_real *c, int nb );
extern void _m_SQRT2          ( mpu_real *c, int nb );
extern void _m_1_SQRT2        ( mpu_real *c, int nb );
extern void _m_SQRT3          ( mpu_real *c, int nb );
extern void _m_1_SQRT3        ( mpu_real *c, int nb );
extern void _m_DEGREE         ( mpu_real *c, int nb );
extern void _m_1_DEGREE       ( mpu_real *c, int nb );
extern void _m_GOLDENRATIO    ( mpu_real *c, int nb );
extern void _m_EULERGAMMA     ( mpu_real *c, int nb );
extern void _m_CATALAN        ( mpu_real *c, int nb );

extern void _ind              ( mpu_real *c, int nb );
extern int  _is_ind           ( mpu_real *c, int nb );
extern void _nan              ( mpu_real *c, unsigned int sign, int nb );
extern int  _is_nans          ( mpu_real *c, int nb );
extern void _nan_max          ( mpu_real *c, unsigned int sign, int nb );
extern int  _is_nan_max       ( mpu_real *c, int nb );
extern void _nan_min          ( mpu_real *c, unsigned int sign, int nb );
extern int  _is_nan_min       ( mpu_real *c, int nb );
extern void _inf              ( mpu_real *c, unsigned int sign, int nb );
extern int  _is_inf           ( mpu_real *c, int nb );
extern void _real_min         ( mpu_real *c, unsigned int sign, int nb );
extern void _real_max         ( mpu_real *c, unsigned int sign, int nb );
extern void _signull          ( mpu_real *c, unsigned int sign, int nb );
extern int  _is_signull       ( mpu_real *c, int nb );

extern void r_neg             ( mpu_real *c, int nb );
extern int  r_is_neg          ( mpu_real *c, int nb );
extern void r_abs             ( mpu_real *c, int nb );
extern int  r_sign            ( mpu_real *c, int nb );

extern int  r_cmp             ( mpu_real *a, mpu_real *b, int nb );
extern void r_cpy             ( mpu_real *a, mpu_real *b, int nb );
extern void r_cvt             ( mpu_real *a, mpu_real *b, int nb_a, int nb_b );

extern void r_add             ( mpu_real *c, mpu_real *a, mpu_real *b, int nb );
extern void r_sub             ( mpu_real *c, mpu_real *a, mpu_real *b, int nb );
extern void r_mul             ( mpu_real *c, mpu_real *a, mpu_real *b, int nb );
extern void r_div             ( mpu_real *c, mpu_real *a, mpu_real *b, int nb );

extern void ltor              ( mpu_real *r, mpu_int *l, int nb_r, int nb_l );
extern void ultor             ( mpu_real *r, mpu_int *l, int nb_r, int nb_l );
extern void rtol_frac         ( mpu_int *l, mpu_real *frac, mpu_real *r, int nb_l, int nb_r );
extern void rtoul_frac        ( mpu_int *l, mpu_real *frac, mpu_real *r, int nb_l, int nb_r );

extern void r_remain          ( mpu_real *r, mpu_real *a, mpu_real *b, int nb );

extern void r_floor           ( mpu_real *c, mpu_real *a, int nb );
extern void r_ceil            ( mpu_real *c, mpu_real *a, int nb );
extern void r_round           ( mpu_real *c, mpu_real *a, int nb );
extern void r_frexp           ( mpu_real *s, mpu_int *lexp, mpu_real *r, int nb_l, int nb_r );
extern void r_ldexp           ( mpu_real *c, mpu_real *r, mpu_int *lpwr2, int nb_r, int nb_l );
extern void r_logb            ( mpu_int *lbase2, mpu_real *r, int nb_l, int nb_r );
extern void r_modf            ( mpu_real *fract, mpu_real *integer, mpu_real *r, int nb );

extern void r_sqrt            ( mpu_real *c, mpu_real *a, int nb );

extern void r_sin             ( mpu_real *y, mpu_real *x, int nb );
extern void r_cos             ( mpu_real *y, mpu_real *x, int nb );
extern void r_tan             ( mpu_real *y, mpu_real *x, int nb );

extern void r_log1p           ( mpu_real *y, mpu_real *x, int nb );

extern void r_log             ( mpu_real *y, mpu_real *x, int nb );
extern void r_log10           ( mpu_real *y, mpu_real *x, int nb );
extern void r_log2            ( mpu_real *y, mpu_real *x, int nb );

extern void r_expm1           ( mpu_real *y, mpu_real *x, int nb );
extern void r_exp             ( mpu_real *y, mpu_real *x, int nb );

extern void r_atan2           ( mpu_real *c, mpu_real *y, mpu_real *x, int nb );

extern void r_sinh            ( mpu_real *y, mpu_real *x, int nb );
extern void r_cosh            ( mpu_real *y, mpu_real *x, int nb );
extern void r_tanh            ( mpu_real *y, mpu_real *x, int nb );

extern void r_asinh           ( mpu_real *y, mpu_real *x, int nb );
extern void r_acosh           ( mpu_real *y, mpu_real *x, int nb );
extern void r_atanh           ( mpu_real *y, mpu_real *x, int nb );

extern void r_asin            ( mpu_real *y, mpu_real *x, int nb );
extern void r_acos            ( mpu_real *y, mpu_real *x, int nb );
extern void r_atan            ( mpu_real *y, mpu_real *x, int nb );

extern void r_pow             ( mpu_real *c, mpu_real *x, mpu_real *y, int nb );

extern void r_hypot           ( mpu_real *c, mpu_real *x, mpu_real *y, int nb );


#define _ASCII_TO_REAL_ERROR  (-1) /* error */
#define _LONGHAND_REAL_NUMBER   0  /* прочитано простое число (типа 1e1) */
#define _REAL_PART_OF_COMPLEX   1  /* прочитана вещественная часть комплексного числа (типа 1r1) */
#define _IMAGINARY_OF_COMPLEX   2  /* прочитана мнимая часть комплексного числа (типа 1i1, 1j1) */

extern int  ascii_to_real     ( mpu_real *c, __mpu_char8_t *s, int nb );

extern void real_to_ascii     ( __mpu_char8_t *s, mpu_real *c,
                                int ndigs, int exp_delim, int exp_digs, int gen_plus, int nb );


extern void c_real_part       ( mpu_real *r, mpu_complex *c, int nb );
extern void c_imaginary       ( mpu_real *r, mpu_complex *c, int nb );

extern void c_real_to_complex ( mpu_complex *c, mpu_real *r, int nb );
extern void c_gen_complex     ( mpu_complex *c, mpu_real *r, mpu_real *j, int nb );
extern void c_polar           ( mpu_complex *c, mpu_real *rho, mpu_real *theta, int nb );

extern void c_conj            ( mpu_complex *c, mpu_complex *x, int nb );
extern void c_abs             ( mpu_real *r, mpu_complex *c, int nb );
extern void c_norm            ( mpu_real *r, mpu_complex *c, int nb );
extern void c_arg             ( mpu_real *r, mpu_complex *c, int nb );

extern int  c_is_equal        ( mpu_complex *a, mpu_complex *b, int nb );
extern int  c_is_nequal       ( mpu_complex *a, mpu_complex *b, int nb );

extern void c_cpy             ( mpu_complex *a, mpu_complex *b, int nb );
extern void c_cvt             ( mpu_complex *a, mpu_complex *b, int nb_a, int nb_b );

extern void c_add             ( mpu_complex *c, mpu_complex *a, mpu_complex *b, int nb );
extern void c_sub             ( mpu_complex *c, mpu_complex *a, mpu_complex *b, int nb );
extern void c_mul             ( mpu_complex *c, mpu_complex *a, mpu_complex *b, int nb );
extern void c_div             ( mpu_complex *c, mpu_complex *a, mpu_complex *b, int nb );

extern void c_exp             ( mpu_complex *y, mpu_complex *x, int nb );

extern void c_sin             ( mpu_complex *y, mpu_complex *x, int nb );
extern void c_cos             ( mpu_complex *y, mpu_complex *x, int nb );

extern void c_sinh            ( mpu_complex *y, mpu_complex *x, int nb );
extern void c_cosh            ( mpu_complex *y, mpu_complex *x, int nb );

extern void c_log             ( mpu_complex *y, mpu_complex *x, int nb );
extern void c_pow             ( mpu_complex *y, mpu_complex *x, mpu_complex *p, int nb );

extern void c_sqrt            ( mpu_complex *y, mpu_complex *x, int nb );



#ifdef  __cplusplus
}   /* ... extern "C" */
#endif

#endif /* __LIB_MPU_H */