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

/***************************************************************
  __MPU_TETRADE.C

     This file containt source code of of function
     for arithmetic & mathematic operations.

     PART OF : MPU - library .

     USAGE   : Internal only .

     NOTE    : NONE .

     Copyright (C) 2000 - 2024  by Andrew V.Kosteltsev.
     All Rights Reserved.
 ***************************************************************/

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <errno.h>   /* errno(3)  */
#include <string.h>  /* strcpy(3) */
#include <strings.h> /* bzero(3)  */
#include <stdlib.h>

#include <libmpu.h>
#include <mpu-context.h>

#include <mpu-emutype.h>
#include <mpu-integer.h>
#include <mpu-real.h>
#include <mpu-floatp.h>
#include <mpu-ioreal.h>
#include <mpu-m-const.h>
#include <mpu-math.h>

#include <mpu-char.h>
#include <mpu-symbols.h>

#include <mpu-math-errno.h>
#include <mpu-strerror.h>
#include <mpu-mtherr.h>


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


/***************************************************************
  Операции ложения и вычитания [ c = a + b; c = a - b; ]
  Воздействуют на флаги: AF, CF, OF, PF, SF, ZF.
 ***************************************************************/
void iadd( mpu_int *c, mpu_int *a, mpu_int *b, int nb )
/* сложение знаковое и беззнаковое целых всех размеров */
/*
  c = a + b;
 *****************************/
{
  __integer_error_no = 0;

  switch( nb ) /* NB is number of bytes in mpu_int's. */
  {
    case 1:
      iadd_8( (__mpu_uint8_t *)c,
              (__mpu_uint8_t *)a,
              (__mpu_uint8_t *)b );
      break;

    case 2:
      iadd_16( (__mpu_uint16_t *)c,
               (__mpu_uint16_t *)a,
               (__mpu_uint16_t *)b );
      break;

    case 4:
      iadd_32( (__mpu_uint32_t *)c,
               (__mpu_uint32_t *)a,
               (__mpu_uint32_t *)b );
      break;

    default:
      iadd_np( (EMUSHORT *)c,
               (EMUSHORT *)a,
               (EMUSHORT *)b,nb/SIZE_OF_EMUSHORT );
      break;

  } /* End of switch( nb ) */

} /* End iadd() */


void iadc( mpu_int *c, mpu_int *a, mpu_int *b, int nb )
/* сложение знаковое и беззнаковое целых всех размеров с переносом */
/*
  c = a + b with carry;
 *****************************/
{
  __integer_error_no = 0;

  switch( nb ) /* NB is number of bytes in mpu_int's. */
  {
    case 1:
      iadc_8( (__mpu_uint8_t *)c,
              (__mpu_uint8_t *)a,
              (__mpu_uint8_t *)b );
      break;

    case 2:
      iadc_16( (__mpu_uint16_t *)c,
               (__mpu_uint16_t *)a,
               (__mpu_uint16_t *)b );
      break;

    case 4:
      iadc_32( (__mpu_uint32_t *)c,
               (__mpu_uint32_t *)a,
               (__mpu_uint32_t *)b );
      break;

    default:
      iadc_np( (EMUSHORT *)c,
               (EMUSHORT *)a,
               (EMUSHORT *)b, nb/SIZE_OF_EMUSHORT );
      break;

  } /* End of switch( nb ) */

} /* End iadc() */


void isub( mpu_int *c, mpu_int *a, mpu_int *b, int nb )
/* вычитание знаковое и беззнаковое целых всех размеров */
/*
  c = a - b;
 *****************************/
{
  __integer_error_no = 0;

  switch( nb ) /* NB is number of bytes in mpu_int's. */
  {
    case 1:
      isub_8( (__mpu_uint8_t *)c,
              (__mpu_uint8_t *)a,
              (__mpu_uint8_t *)b );
      break;

    case 2:
      isub_16( (__mpu_uint16_t *)c,
               (__mpu_uint16_t *)a,
               (__mpu_uint16_t *)b );
      break;

    case 4:
      isub_32( (__mpu_uint32_t *)c,
               (__mpu_uint32_t *)a,
               (__mpu_uint32_t *)b );
      break;

    default:
      isub_np( (EMUSHORT *)c,
               (EMUSHORT *)a,
               (EMUSHORT *)b, nb/SIZE_OF_EMUSHORT );
      break;

  } /* End of switch( nb ) */

} /* End isub() */


void isbb( mpu_int *c, mpu_int *a, mpu_int *b, int nb )
/* вычитание знаковое и беззнаковое целых всех размеров с переносом */
/*
  c = a - b with carry;
 *****************************/
{
  __integer_error_no = 0;

  switch( nb ) /* NB is number of bytes in mpu_int's. */
  {
    case 1:
      isbb_8( (__mpu_uint8_t *)c,
              (__mpu_uint8_t *)a,
              (__mpu_uint8_t *)b );
      break;

    case 2:
      isbb_16( (__mpu_uint16_t *)c,
               (__mpu_uint16_t *)a,
               (__mpu_uint16_t *)b );
      break;

    case 4:
      isbb_32( (__mpu_uint32_t *)c,
               (__mpu_uint32_t *)a,
               (__mpu_uint32_t *)b );
      break;

    default:
      isbb_np( (EMUSHORT *)c,
               (EMUSHORT *)a,
               (EMUSHORT *)b, nb/SIZE_OF_EMUSHORT );
      break;

  } /* End of switch( nb ) */

} /* End isbb() */


/***************************************************************
  Операции сдвига на 1 бит [c = <<a; c = >>a;]
  Воздействуют на флаги: AF=0, CF, OF, PF, SF, ZF.
 ***************************************************************/
void ishl( mpu_int *c, mpu_int *a, int nb )
/* Логический беззнаковый сдвиг влево на один бит */
/*
  c = <<a;
 *****************************/
{
  __integer_error_no = 0;

  switch( nb ) /* NB is number of bytes in mpu_int's. */
  {
    case 1:
      ishl_8( (__mpu_uint8_t *)c,
              (__mpu_uint8_t *)a );
      break;

    case 2:
      ishl_16( (__mpu_uint16_t *)c,
               (__mpu_uint16_t *)a );
      break;

    case 4:
      ishl_32( (__mpu_uint32_t *)c,
               (__mpu_uint32_t *)a );
      break;

    default:
      ishl_np( (EMUSHORT *)c,
               (EMUSHORT *)a, nb/SIZE_OF_EMUSHORT );
      break;

  } /* End of switch( nb ) */

} /* End ishl() */


void ishr( mpu_int *c, mpu_int *a, int nb )
/* Логический беззнаковый сдвиг вправо на один бит */
/*
  c = >>a;
 *****************************/
{
  __integer_error_no = 0;

  switch( nb ) /* NB is number of bytes in mpu_int's. */
  {
    case 1:
      ishr_8( (__mpu_uint8_t *)c,
              (__mpu_uint8_t *)a );
      break;

    case 2:
      ishr_16( (__mpu_uint16_t *)c,
               (__mpu_uint16_t *)a );
      break;

    case 4:
      ishr_32( (__mpu_uint32_t *)c,
               (__mpu_uint32_t *)a );
      break;

    default:
      ishr_np( (EMUSHORT *)c,
               (EMUSHORT *)a, nb/SIZE_OF_EMUSHORT );
      break;

  } /* End of switch( nb ) */

} /* End ishr() */


void isal( mpu_int *c, mpu_int *a, int nb )
/* Арифметический сдвиг влево на один бит */
/*
  c = <<a;
 *****************************/
{
  __integer_error_no = 0;

  switch( nb ) /* NB is number of bytes in mpu_int's. */
  {
    case 1:
      isal_8( (__mpu_uint8_t *)c,
              (__mpu_uint8_t *)a );
      break;

    case 2:
      isal_16( (__mpu_uint16_t *)c,
               (__mpu_uint16_t *)a );
      break;

    case 4:
      isal_32( (__mpu_uint32_t *)c,
               (__mpu_uint32_t *)a );
      break;

    default:
      isal_np( (EMUSHORT *)c,
               (EMUSHORT *)a, nb/SIZE_OF_EMUSHORT );
      break;

  } /* End of switch( nb ) */

} /* End isal() */


void isar( mpu_int *c, mpu_int *a, int nb )
/* Арифметический сдвиг вправо на один бит */
/*
  c = >>a;
 *****************************/
{
  __integer_error_no = 0;

  switch( nb ) /* NB is number of bytes in mpu_int's. */
  {
    case 1:
      isar_8( (__mpu_uint8_t *)c,
              (__mpu_uint8_t *)a );
      break;

    case 2:
      isar_16( (__mpu_uint16_t *)c,
               (__mpu_uint16_t *)a );
      break;

    case 4:
      isar_32( (__mpu_uint32_t *)c,
               (__mpu_uint32_t *)a );
      break;

    default:
      isar_np( (EMUSHORT *)c,
               (EMUSHORT *)a, nb/SIZE_OF_EMUSHORT );
      break;

  } /* End of switch( nb ) */

} /* End isar() */


/***************************************************************
  Операции иклических сдвигов на 1 бит
  Воздействуют на флаги: AF=0, CF, OF, PF, SF, ZF.
 ***************************************************************/
void irol( mpu_int *c, mpu_int *a, int nb )
/* Циклический сдвиг влево на один бит */
/*
  c = >>a;
 *****************************/
{
  __integer_error_no = 0;

  switch( nb ) /* NB is number of bytes in mpu_int's. */
  {
    case 1:
      irol_8( (__mpu_uint8_t *)c,
              (__mpu_uint8_t *)a );
      break;

    case 2:
      irol_16( (__mpu_uint16_t *)c,
               (__mpu_uint16_t *)a );
      break;

    case 4:
      irol_32( (__mpu_uint32_t *)c,
               (__mpu_uint32_t *)a );
      break;

    default:
      irol_np( (EMUSHORT *)c,
               (EMUSHORT *)a, nb/SIZE_OF_EMUSHORT );
      break;

  } /* End of switch( nb ) */

} /* End irol() */


void iror( mpu_int *c, mpu_int *a, int nb )
/* Циклический сдвиг вправо на один бит */
/*
  c = >>a;
 *****************************/
{
  __integer_error_no = 0;

  switch( nb ) /* NB is number of bytes in mpu_int's. */
  {
    case 1:
      iror_8( (__mpu_uint8_t *)c,
              (__mpu_uint8_t *)a );
      break;

    case 2:
      iror_16( (__mpu_uint16_t *)c,
               (__mpu_uint16_t *)a );
      break;

    case 4:
      iror_32( (__mpu_uint32_t *)c,
                      (__mpu_uint32_t *)a );
      break;

    default:
      iror_np( (EMUSHORT *)c,
               (EMUSHORT *)a, nb/SIZE_OF_EMUSHORT );
      break;

  } /* End of switch( nb ) */

} /* End iror() */


void ircl( mpu_int *c, mpu_int *a, int nb )
/* Циклический сдвиг влево на один бит с переносом */
/*
  c = <<a;
 *****************************/
{
  __integer_error_no = 0;

  switch( nb ) /* NB is number of bytes in mpu_int's. */
  {
    case 1:
      ircl_8( (__mpu_uint8_t *)c,
              (__mpu_uint8_t *)a );
      break;

    case 2:
      ircl_16( (__mpu_uint16_t *)c,
               (__mpu_uint16_t *)a );
      break;

    case 4:
      ircl_32( (__mpu_uint32_t *)c,
               (__mpu_uint32_t *)a );
      break;

    default:
      ircl_np( (EMUSHORT *)c,
               (EMUSHORT *)a, nb/SIZE_OF_EMUSHORT );
      break;

  } /* End of switch( nb ) */

} /* End ircl() */


void ircr( mpu_int *c, mpu_int *a, int nb )
/* Циклический сдвиг вправо на один бит с переносом */
/*
  c = >>a;
 *****************************/
{
  __integer_error_no = 0;

  switch( nb ) /* NB is number of bytes in mpu_int's. */
  {
    case 1:
      ircr_8( (__mpu_uint8_t *)c,
              (__mpu_uint8_t *)a );
      break;

    case 2:
      ircr_16( (__mpu_uint16_t *)c,
               (__mpu_uint16_t *)a );
      break;

    case 4:
      ircr_32( (__mpu_uint32_t *)c,
               (__mpu_uint32_t *)a );
      break;

    default:
      ircr_np( (EMUSHORT *)c,
               (EMUSHORT *)a, nb/SIZE_OF_EMUSHORT );
      break;

  } /* End of switch( nb ) */

} /* End ircr() */


/***************************************************************
  Операции сдвига на (ns) бит
  Воздействует на флаги: AF=0, CF, OF, PF, SF, ZF.
 ***************************************************************/
void ishln( mpu_int *c, mpu_int *a, unsigned int ns, int nb )
/* Логический сдвиг влево на (ns) бит */
/*
  c = <<a;
 *****************************/
{
  __integer_error_no = 0;

  switch( nb ) /* NB is number of bytes in mpu_int's. */
  {
    case 1:
      ishln_8( (__mpu_uint8_t *)c,
               (__mpu_uint8_t *)a, ns );
      break;

    case 2:
      ishln_16( (__mpu_uint16_t *)c,
                (__mpu_uint16_t *)a, ns );
      break;

    case 4:
      ishln_32( (__mpu_uint32_t *)c,
                (__mpu_uint32_t *)a, ns );
      break;

    default:
      ishln_np( (EMUSHORT *)c,
                (EMUSHORT *)a, ns, nb/SIZE_OF_EMUSHORT );
      break;

  } /* End of switch( nb ) */

} /* End ishln() */


void ishrn( mpu_int *c, mpu_int *a, unsigned int ns, int nb )
/* Логический сдвиг вправо на (ns) бит */
/*
  c = >>a;
 *****************************/
{
  __integer_error_no = 0;

  switch( nb ) /* NB is number of bytes in mpu_int's. */
  {
    case 1:
      ishrn_8( (__mpu_uint8_t *)c,
               (__mpu_uint8_t *)a, ns );
      break;

    case 2:
      ishrn_16( (__mpu_uint16_t *)c,
                (__mpu_uint16_t *)a, ns );
      break;

    case 4:
      ishrn_32( (__mpu_uint32_t *)c,
                (__mpu_uint32_t *)a, ns );
      break;

    default:
      ishrn_np( (EMUSHORT *)c,
                (EMUSHORT *)a, ns, nb/SIZE_OF_EMUSHORT );
      break;

  } /* End of switch( nb ) */

} /* End ishrn() */


void isaln( mpu_int *c, mpu_int *a, unsigned int ns, int nb )
/* Арифметический сдвиг влево на (ns) бит */
/*
  c = <<a;
 *****************************/
{
  __integer_error_no = 0;

  switch( nb ) /* NB is number of bytes in mpu_int's. */
  {
    case 1:
      isaln_8( (__mpu_uint8_t *)c,
               (__mpu_uint8_t *)a, ns );
      break;

    case 2:
      isaln_16( (__mpu_uint16_t *)c,
                (__mpu_uint16_t *)a, ns );
      break;

    case 4:
      isaln_32( (__mpu_uint32_t *)c,
                (__mpu_uint32_t *)a, ns );
      break;

    default:
      isaln_np( (EMUSHORT *)c,
                (EMUSHORT *)a, ns, nb/SIZE_OF_EMUSHORT );
      break;

  } /* End of switch( nb ) */

} /* End isaln() */


void isarn( mpu_int *c, mpu_int *a, unsigned int ns, int nb )
/* Арифметический сдвиг вправо на (ns) бит */
/*
  c = >>a;
 *****************************/
{
  __integer_error_no = 0;

  switch( nb ) /* NB is number of bytes in mpu_int's. */
  {
    case 1:
      isarn_8( (__mpu_uint8_t *)c,
               (__mpu_uint8_t *)a, ns );
      break;

    case 2:
      isarn_16( (__mpu_uint16_t *)c,
                (__mpu_uint16_t *)a, ns );
      break;

    case 4:
      isarn_32( (__mpu_uint32_t *)c,
                (__mpu_uint32_t *)a, ns );
      break;

    default:
      isarn_np( (EMUSHORT *)c,
                (EMUSHORT *)a, ns, nb/SIZE_OF_EMUSHORT );
      break;

  } /* End of switch( nb ) */

} /* End isarn() */


/***************************************************************
  Операции иклических сдвигов на (ns) бит.
  Воздействует на флаги: AF=0, CF, OF, PF, SF, ZF.
 ***************************************************************/
void iroln( mpu_int *c, mpu_int *a, unsigned int ns, int nb )
/* Циклический сдвиг влево на (ns) бит */
/*
  c = <<a;
 *****************************/
{
  __integer_error_no = 0;

  switch( nb ) /* NB is number of bytes in mpu_int's. */
  {
    case 1:
      iroln_8( (__mpu_uint8_t *)c,
               (__mpu_uint8_t *)a, ns );
      break;

    case 2:
      iroln_16( (__mpu_uint16_t *)c,
                (__mpu_uint16_t *)a, ns );
      break;

    case 4:
      iroln_32( (__mpu_uint32_t *)c,
                (__mpu_uint32_t *)a, ns );
      break;

    default:
      iroln_np( (EMUSHORT *)c,
                (EMUSHORT *)a, ns, nb/SIZE_OF_EMUSHORT );
      break;

  } /* End of switch( nb ) */

} /* End iroln() */


void irorn( mpu_int *c, mpu_int *a, unsigned int ns, int nb )
/* Циклический сдвиг вправо на (ns) бит */
/*
  c = >>a;
 *****************************/
{
  __integer_error_no = 0;

  switch( nb ) /* NB is number of bytes in mpu_int's. */
  {
    case 1:
      irorn_8( (__mpu_uint8_t *)c,
               (__mpu_uint8_t *)a, ns );
      break;

    case 2:
      irorn_16( (__mpu_uint16_t *)c,
                (__mpu_uint16_t *)a, ns );
      break;

    case 4:
      irorn_32( (__mpu_uint32_t *)c,
                (__mpu_uint32_t *)a, ns );
      break;

    default:
      irorn_np( (EMUSHORT *)c,
                (EMUSHORT *)a, ns, nb/SIZE_OF_EMUSHORT );
      break;

  } /* End of switch( nb ) */

} /* End irorn() */


void ircln( mpu_int *c, mpu_int *a, unsigned int ns, int nb )
/* Циклический сдвиг влево на (ns) бит с переносом */
/*
  c = <<a;
 *****************************/
{
  __integer_error_no = 0;

  switch( nb ) /* NB is number of bytes in mpu_int's. */
  {
    case 1:
      ircln_8( (__mpu_uint8_t *)c,
               (__mpu_uint8_t *)a, ns );
      break;

    case 2:
      ircln_16( (__mpu_uint16_t *)c,
                (__mpu_uint16_t *)a, ns );
      break;

    case 4:
      ircln_32( (__mpu_uint32_t *)c,
                (__mpu_uint32_t *)a, ns );
      break;

    default:
      ircln_np( (EMUSHORT *)c,
                (EMUSHORT *)a, ns, nb/SIZE_OF_EMUSHORT );
      break;

  } /* End of switch( nb ) */

} /* End ircln() */


void ircrn( mpu_int *c, mpu_int *a, unsigned int ns, int nb )
/* Циклический сдвиг вправо на (ns) бит с переносом */
/*
  c = >>a;
 *****************************/
{
  __integer_error_no = 0;

  switch( nb ) /* NB is number of bytes in mpu_int's. */
  {
    case 1:
      ircrn_8( (__mpu_uint8_t *)c,
               (__mpu_uint8_t *)a, ns );
      break;

    case 2:
      ircrn_16( (__mpu_uint16_t *)c,
                (__mpu_uint16_t *)a, ns );
      break;

    case 4:
      ircrn_32( (__mpu_uint32_t *)c,
                (__mpu_uint32_t *)a, ns );
      break;

    default:
      ircrn_np( (EMUSHORT *)c,
                (EMUSHORT *)a, ns, nb/SIZE_OF_EMUSHORT );
      break;

  } /* End of switch( nb ) */

} /* End ircrn() */


/***************************************************************
  Операция NOT [c = (инверсия всех разрядов)a].
  На флаги не воздействует.
 ***************************************************************/
void inot( mpu_int *c, mpu_int *a, int nb )
/* поразрядное логическое НЕ */
/*
  c = ~a;
 *****************************/
{
  __integer_error_no = 0;

  switch( nb ) /* NB is number of bytes in mpu_int's. */
  {
    case 1:
      inot_8( (__mpu_uint8_t *)c,
              (__mpu_uint8_t *)a );
      break;

    case 2:
      inot_16( (__mpu_uint16_t *)c,
               (__mpu_uint16_t *)a );
      break;

    case 4:
      inot_32( (__mpu_uint32_t *)c,
               (__mpu_uint32_t *)a );
      break;

    default:
      inot_np( (EMUSHORT *)c,
               (EMUSHORT *)a, nb/SIZE_OF_EMUSHORT );
      break;

  } /* End of switch( nb ) */

} /* End inot() */


/***************************************************************
  Операция NEG [c = - a].
  Воздействует на флаги: AF, CF, OF, PF, SF, ZF.
 ***************************************************************/
void ineg( mpu_int *c, mpu_int *a, int nb )
/*
  c = -a;
 *****************************/
{
  __integer_error_no = 0;

  switch( nb ) /* NB is number of bytes in mpu_int's. */
  {
    case 1:
      ineg_8( (__mpu_uint8_t *)c,
              (__mpu_uint8_t *)a );
      break;

    case 2:
      ineg_16( (__mpu_uint16_t *)c,
               (__mpu_uint16_t *)a );
      break;

    case 4:
      ineg_32( (__mpu_uint32_t *)c,
               (__mpu_uint32_t *)a );
      break;

    default:
      ineg_np( (EMUSHORT *)c,
               (EMUSHORT *)a, nb/SIZE_OF_EMUSHORT );
      break;

  } /* End of switch( nb ) */

} /* End ineg() */


/***************************************************************
  Операция AND [c = a <AND> b].
  Воздействует на флаги: AF=(undefined),
                     CF=0, OF=0, PF, SF, ZF.
 ***************************************************************/
void iand( mpu_int *c, mpu_int *a, mpu_int *b, int nb )
/* поразрядное логическое И */
/*
  c = a & b;
 *****************************/
{
  __integer_error_no = 0;

  switch( nb ) /* NB is number of bytes in mpu_int's. */
  {
    case 1:
      iand_8( (__mpu_uint8_t *)c,
              (__mpu_uint8_t *)a,
              (__mpu_uint8_t *)b );
      break;

    case 2:
      iand_16( (__mpu_uint16_t *)c,
               (__mpu_uint16_t *)a,
               (__mpu_uint16_t *)b );
      break;

    case 4:
      iand_32( (__mpu_uint32_t *)c,
               (__mpu_uint32_t *)a,
               (__mpu_uint32_t *)b );
      break;

    default:
      iand_np( (EMUSHORT *)c,
               (EMUSHORT *)a,
               (EMUSHORT *)b, nb/SIZE_OF_EMUSHORT );
      break;

  } /* End of switch( nb ) */

} /* End iand() */



/***************************************************************
  Операция TEST [a <TEST> b]. Не изменяет значения операндов.
  Воздействует на флаги: AF=(undefined),
                     CF=0, OF=0, PF, SF, ZF.
 ***************************************************************/
void itest( mpu_int *a, mpu_int *b, int nb )
/* поразрядное логическое И */
/*
  a & b;
 *****************************/
{
  __integer_error_no = 0;

  switch( nb ) /* NB is number of bytes in mpu_int's. */
  {
    case 1:
      itest_8( (__mpu_uint8_t *)a,
               (__mpu_uint8_t *)b );
      break;

    case 2:
      itest_16( (__mpu_uint16_t *)a,
                (__mpu_uint16_t *)b );
      break;

    case 4:
      itest_32( (__mpu_uint32_t *)a,
                (__mpu_uint32_t *)b );
      break;

    default:
      itest_np( (EMUSHORT *)a,
                (EMUSHORT *)b, nb/SIZE_OF_EMUSHORT );
      break;

  } /* End of switch( nb ) */

} /* End itest() */


/***************************************************************
  Операция сравнения CMP [<a - b>].
  Не изменяет значения операндов.
  Выставляет флаги: AF, CF, OF, SF, PF, ZF.
 ***************************************************************/
void icmp( mpu_int *a, mpu_int *b, int nb )
/*
  a - b;
 *****************************/
{
  __integer_error_no = 0;

  switch( nb ) /* NB is number of bytes in mpu_int's. */
  {
    case 1:
      icmp_8( (__mpu_uint8_t *)a,
              (__mpu_uint8_t *)b );
      break;

    case 2:
      icmp_16( (__mpu_uint16_t *)a,
               (__mpu_uint16_t *)b );
      break;

    case 4:
      icmp_32( (__mpu_uint32_t *)a,
               (__mpu_uint32_t *)b );
      break;

    default:
      icmp_np( (EMUSHORT *)a,
               (EMUSHORT *)b, nb/SIZE_OF_EMUSHORT );
      break;

  } /* End of switch( nb ) */

} /* End icmp() */


/***************************************************************
  Операция OR [c = a <OR> b].
  Воздействует на флаги: AF=(undefined),
  CF=0, OF=0, PF, SF, ZF.
 ***************************************************************/
void ior( mpu_int *c, mpu_int *a, mpu_int *b, int nb )
/* поразрядное логическое ИЛИ */
/*
  c = a | b;
 *****************************/
{
  __integer_error_no = 0;

  switch( nb ) /* NB is number of bytes in mpu_int's. */
  {
    case 1:
      ior_8( (__mpu_uint8_t *)c,
             (__mpu_uint8_t *)a,
             (__mpu_uint8_t *)b );
      break;

    case 2:
      ior_16( (__mpu_uint16_t *)c,
              (__mpu_uint16_t *)a,
              (__mpu_uint16_t *)b );
      break;

    case 4:
      ior_32( (__mpu_uint32_t *)c,
              (__mpu_uint32_t *)a,
              (__mpu_uint32_t *)b );
      break;

    default:
      ior_np( (EMUSHORT *)c,
              (EMUSHORT *)a,
              (EMUSHORT *)b, nb/SIZE_OF_EMUSHORT );
      break;

  } /* End of switch( nb ) */

} /* End ior() */


/***************************************************************
  Операция XOR [c = a <XOR> b].
  Воздействует на флаги: AF=(undefined),
  CF=0, OF=0, PF, SF, ZF.
 ***************************************************************/
void ixor( mpu_int *c, mpu_int *a, mpu_int *b, int nb )
/* поразрядное логическое исключающее ИЛИ */
/*
  c = a ^ b;
 *****************************/
{
  __integer_error_no = 0;

  switch( nb ) /* NB is number of bytes in mpu_int's. */
  {
    case 1:
      ixor_8( (__mpu_uint8_t *)c,
              (__mpu_uint8_t *)a,
              (__mpu_uint8_t *)b );
      break;

    case 2:
      ixor_16( (__mpu_uint16_t *)c,
               (__mpu_uint16_t *)a,
               (__mpu_uint16_t *)b );
      break;

    case 4:
      ixor_32( (__mpu_uint32_t *)c,
               (__mpu_uint32_t *)a,
               (__mpu_uint32_t *)b );
      break;

    default:
      ixor_np( (EMUSHORT *)c,
               (EMUSHORT *)a,
               (EMUSHORT *)b, nb/SIZE_OF_EMUSHORT );
      break;

  } /* End of switch( nb ) */

} /* End ixor() */


/***************************************************************
  Операция INC (инкремент) [c = a + 1].
  Воздействует на флаги: AF, OF, PF, SF, ZF.
  Флаг CF не изменяется.
 ***************************************************************/
void iinc( mpu_int *c, mpu_int *a, int nb )
/*
  c = a + 1;
 *****************************/
{
  __integer_error_no = 0;

  switch( nb ) /* NB is number of bytes in mpu_int's. */
  {
    case 1:
      iinc_8( (__mpu_uint8_t *)c,
              (__mpu_uint8_t *)a );
      break;

    case 2:
      iinc_16( (__mpu_uint16_t *)c,
               (__mpu_uint16_t *)a );
      break;

    case 4:
      iinc_32( (__mpu_uint32_t *)c,
               (__mpu_uint32_t *)a );
      break;

    default:
      iinc_np( (EMUSHORT *)c,
               (EMUSHORT *)a, nb/SIZE_OF_EMUSHORT );
      break;

  } /* End of switch( nb ) */

} /* End iinc() */


/***************************************************************
  Операция DEC (декремент) [c = a - 1].
  Воздействует на флаги: AF, OF, PF, SF, ZF.
  Флаг CF не изменяется.
 ***************************************************************/
void idec(  mpu_int *c, mpu_int *a, int nb )
/*
  c = a - 1;
 *****************************/
{
  __integer_error_no = 0;

  switch( nb ) /* NB is number of bytes in mpu_int's. */
  {
    case 1:
      idec_8( (__mpu_uint8_t *)c,
              (__mpu_uint8_t *)a );
      break;

    case 2:
      idec_16( (__mpu_uint16_t *)c,
               (__mpu_uint16_t *)a );
      break;

    case 4:
      idec_32( (__mpu_uint32_t *)c,
               (__mpu_uint32_t *)a );
      break;

    default:
      idec_np( (EMUSHORT *)c,
               (EMUSHORT *)a, nb/SIZE_OF_EMUSHORT );
      break;

  } /* End of switch( nb ) */

} /* End idec() */


/***************************************************************
  Операция XCHG (замена) [a <==> b].
  Не изменяет флаги.
 ***************************************************************/
void ixchg( mpu_int *a, mpu_int *b, int nb )
/*
  a <==> b;
 *****************************/
{
  __integer_error_no = 0;

  switch( nb ) /* NB is number of bytes in mpu_int's. */
  {
    case 1:
      ixchg_8( (__mpu_uint8_t *)a,
               (__mpu_uint8_t *)b );
      break;

    case 2:
      ixchg_16( (__mpu_uint16_t *)a,
                (__mpu_uint16_t *)b );
      break;

    case 4:
      ixchg_32( (__mpu_uint32_t *)a,
                (__mpu_uint32_t *)b );
      break;

    default:
      ixchg_np( (EMUSHORT *)a,
                (EMUSHORT *)b, nb/SIZE_OF_EMUSHORT );
      break;

  } /* End of switch( nb ) */

} /* End ixchg() */


/***************************************************************
  Операция копирования данных CPY.
  Воздействует на флаги: OF, PF, SF, ZF.
  Флаги CF, AF не изменяются.
 ***************************************************************/
void icpy( mpu_int *c, mpu_int *a, int nb_c, int nb_a )
/*
  c <-- a;
 **********/
{
  int np_c, np_a;

  __integer_error_no = 0;

  np_c = nb_c / SIZE_OF_EMUSHORT;
  np_a = nb_a / SIZE_OF_EMUSHORT;

  if( nb_c == nb_a ) /* копирование равных */
  {
    switch( nb_a )
    {
      case 1:
        icpy_8( (__mpu_uint8_t *)c,
                (__mpu_uint8_t *)a );
        break;

      case 2:
        icpy_16( (__mpu_uint16_t *)c,
                 (__mpu_uint16_t *)a );
        break;

      case 4:
        icpy_32( (__mpu_uint32_t *)c,
                 (__mpu_uint32_t *)a );
        break;

      default:
        icpy_np( (EMUSHORT *)c,
                 (EMUSHORT *)a, np_c, np_a );
        break;

    } /* End of switch( nd_c == nb_a ) */

  } /* End if( nb_c == nb_a ) */
  else if( nb_c > nb_a ) /* копирование меньших в большие */
  {
    switch( nb_a )
    {
      case 1: /* копирование байта */
        switch( nb_c )
        {
           case 2: /* в два байта */
              icpy_s2l_8to16( (__mpu_uint16_t *)c,
                               (__mpu_uint8_t *)a );
              break;

           case 4: /* в четыре байта */
              icpy_s2l_8to32( (__mpu_uint32_t *)c,
                               (__mpu_uint8_t *)a );
              break;

           default:
              icpy_s2l_8to_np( (EMUSHORT *)c,
                              (__mpu_uint8_t *)a, np_c );
              break;
        }
        break;

      case 2: /* копирование двух байт */
        switch( nb_c )
        {
           case 4: /* в четыре байта */
              icpy_s2l_16to32( (__mpu_uint32_t *)c,
                               (__mpu_uint16_t *)a );
              break;

           default:
              icpy_s2l_16to_np( (EMUSHORT *)c,
                                (__mpu_uint16_t *)a, np_c );
              break;
        }
        break;

#if BITS_PER_EMUSHORT > 32
      case 4: /* копирование четырех байт */
        icpy_s2l_32to_np( (EMUSHORT *)c,
                          (__mpu_uint32_t *)a, np_c );
        break;
#endif /* BITS_PER_EMUSHORT > 32 */

      default:
        icpy_np( (EMUSHORT *)c,
                 (EMUSHORT *)a, np_c, np_a );
        break;

    } /* End of switch( nb_a ) */

  } /* End if( nb_c >  nb_a ) */
  else /* копирование больших в меньшие */
  {
    switch( nb_c )
    {
      case 1: /* копирование в байт */
        switch( nb_a )
        {
           case 2: /* двух байт */
              icpy_l2s_16to8( (__mpu_uint8_t *)c,
                              (__mpu_uint16_t *)a );
              break;

           case 4: /* четырх байт */
              icpy_l2s_32to8( (__mpu_uint8_t *)c,
                              (__mpu_uint32_t *)a );
              break;

           default:
              icpy_l2s_np_to8( (__mpu_uint8_t *)c,
                               (EMUSHORT *)a, np_a );
              break;
        }
        break;

      case 2: /* копирование в два байта */
        switch( nb_a )
        {
           case 4: /* четырех байт */
              icpy_l2s_32to16( (__mpu_uint16_t *)c,
                               (__mpu_uint32_t *)a );
              break;

           default:
              icpy_l2s_np_to16( (__mpu_uint16_t *)c,
                                (EMUSHORT *)a, np_a );
              break;
        }
        break;

#if BITS_PER_EMUSHORT > 32
      case 4: /* копирование в четыре байта */
        icpy_l2s_np_to32( (__mpu_uint32_t *)c,
                          (EMUSHORT *)a, np_a );
        break;
#endif /* BITS_PER_EMUSHORT > 32 */

      default:
        icpy_np( (EMUSHORT *)c,
                 (EMUSHORT *)a, np_c, np_a );
        break;

    } /* End of switch( nb_c ) */

  } /* End ( nb_c <  nb_a ) */

} /* End of icpy() */


/***************************************************************
  Операция преобразования (convert) данных CVT.
  Воздействует на флаги: OF, PF, SF, ZF.
  Флаги CF, AF не изменяются.
 ***************************************************************/
void icvt( mpu_int *c, mpu_int *a, int nb_c, int nb_a )
/*
  c <-- a;
 **********/
{
  int np_c, np_a;

  __integer_error_no = 0;

  np_c = nb_c / SIZE_OF_EMUSHORT;
  np_a = nb_a / SIZE_OF_EMUSHORT;

  if( nb_c == nb_a ) /* конвертирование равных */
  {
    switch( nb_a )
    {
      case 1:
        icpy_8( (__mpu_uint8_t *)c,
                (__mpu_uint8_t *)a );
        break;

      case 2:
        icpy_16( (__mpu_uint16_t *)c,
                 (__mpu_uint16_t *)a );
        break;

      case 4:
        icpy_32( (__mpu_uint32_t *)c,
                 (__mpu_uint32_t *)a );
        break;

      default:
        icpy_np( (EMUSHORT *)c,
                 (EMUSHORT *)a, np_c, np_a );
        break;

    } /* End of switch( nd_c == nb_a ) */

  } /* End if( nb_c == nb_a ) */
  else if( nb_c > nb_a ) /* конвертирование меньших в большие */
  {
    switch( nb_a )
    {
      case 1: /* конвертирование байта */
        switch( nb_c )
        {
          case 2: /* в два байта */
            icvt_s2l_8to16( (__mpu_uint16_t *)c,
                            (__mpu_uint8_t *)a );
            break;

          case 4: /* в четыре байта */
            icvt_s2l_8to32( (__mpu_uint32_t *)c,
                            (__mpu_uint8_t *)a );
            break;

          default:
            icvt_s2l_8to_np( (EMUSHORT *)c,
                             (__mpu_uint8_t *)a, np_c );
            break;
        }
        break;

      case 2: /* конвертирование двух байт */
        switch( nb_c )
        {
          case 4: /* в четыре байта */
            icvt_s2l_16to32( (__mpu_uint32_t *)c,
                             (__mpu_uint16_t *)a );
            break;

          default:
            icvt_s2l_16to_np( (EMUSHORT *)c,
                              (__mpu_uint16_t *)a, np_c );
            break;
        }
        break;

#if BITS_PER_EMUSHORT > 32
      case 4: /* конвертирование четырех байт */
        icvt_s2l_32to_np( (EMUSHORT *)c,
                          (__mpu_uint32_t *)a, np_c );
        break;
#endif /* BITS_PER_EMUSHORT > 32 */

      default:
        icvt_np( (EMUSHORT *)c,
                 (EMUSHORT *)a, np_c, np_a );
        break;

    } /* End of switch( nb_a ) */

  } /* End if( nb_c >  nb_a ) */
  else /* конвертирование больших в меньшие */
  {
    switch( nb_c )
    {
      case 1: /* конвертирование в байт */
        switch( nb_a )
        {
          case 2: /* двух байт */
            icvt_l2s_16to8( (__mpu_uint8_t *)c,
                            (__mpu_uint16_t *)a );
            break;

          case 4: /* четырх байт */
            icvt_l2s_32to8( (__mpu_uint8_t *)c,
                            (__mpu_uint32_t *)a );
            break;

          default:
            icvt_l2s_np_to8( (__mpu_uint8_t *)c,
                             (EMUSHORT *)a, np_a );
            break;
        }
        break;

      case 2: /* конвертирование в два байта */
        switch( nb_a )
        {
          case 4: /* четырех байт */
            icvt_l2s_32to16( (__mpu_uint16_t *)c,
                             (__mpu_uint32_t *)a );
            break;

          default:
            icvt_l2s_np_to16( (__mpu_uint16_t *)c,
                              (EMUSHORT *)a, np_a );
            break;
        }
        break;

#if BITS_PER_EMUSHORT > 32
      case 4: /* конвертирование в четыре байта */
        icvt_l2s_np_to32( (__mpu_uint32_t *)c,
                          (EMUSHORT *)a, np_a );
        break;
#endif /* BITS_PER_EMUSHORT > 32 */

      default:
        icvt_np( (EMUSHORT *)c,
                 (EMUSHORT *)a, np_c, np_a );
        break;

    } /* End of switch( nb_c ) */

  } /* End ( nb_c <  nb_a ) */

} /* End of icvt() */


/***************************************************************
  Операции беззнакового и знакового умножения.
  [ prod = num * mul; ]
  Изменяет флаги: CF, AF=0, PF, ZF, SF, OF, RF.
 ***************************************************************/
void imul( mpu_int *prod, mpu_int *num, mpu_int *mul, int nb_prod, int nb_num )
/* prod    - произведение               */
/* num     - множимое                   */
/* mul     - множитель                  */
/* nb_prod - размер произведения        */
/* nb_num  - размер множимого           */
/* Операция беззнакового умножения MUL  */
/*
  prod = num * mul; nb_prod == 2*nb_num;
 ****************************************/
{
  __integer_error_no = 0;

  if( nb_prod < 2*nb_num )
  {
    /* error: Invalid size of operand(s) */
    __integer_invalid_size( (__mpu_char8_t *)"imul" );
    return;
  }

  switch( nb_num ) /* NB is number of bytes in mpu_int's. */
  {
    case 1:
      imul_8( (__mpu_uint16_t *)prod,
              (__mpu_uint8_t *)num,
              (__mpu_uint8_t *)mul );
      break;

    case 2:
      imul_16( (__mpu_uint32_t *)prod,
               (__mpu_uint16_t *)num,
               (__mpu_uint16_t *)mul );
      break;

#if BITS_PER_EMUSHORT > 32
    case 4:
      imul_32( (__mpu_uint64_t *)prod,
               (__mpu_uint32_t *)num,
               (__mpu_uint32_t *)mul );
      break;
#endif /* BITS_PER_EMUSHORT > 32 */

    default:
      imul_np( (EMUSHORT *)prod,
               (EMUSHORT *)num,
               (EMUSHORT *)mul, nb_prod/SIZE_OF_EMUSHORT,
                                nb_num/SIZE_OF_EMUSHORT );
      break;

  } /* End of switch( nb ) */

} /* End imul() */


void ismul( mpu_int *prod, mpu_int *num, mpu_int *mul, int nb_prod, int nb_num )
/* prod    - произведение               */
/* num     - множимое                   */
/* mul     - множитель                  */
/* nb_prod - размер произведения        */
/* nb_num  - размер множимого           */
/* Операция знакового умножения SMUL    */
/*
  prod = num * mul; nb_prod == 2*nb_num;
 ****************************************/
{
  __integer_error_no = 0;

  if( nb_prod < 2*nb_num )
  {
    /* error: Invalid size of operand(s) */
    __integer_invalid_size( (__mpu_char8_t *)"ismul" );
    return;
  }

  switch( nb_num ) /* NB is number of bytes in mpu_int's. */
  {
    case 1:
      ismul_8( (__mpu_uint16_t *)prod,
               (__mpu_uint8_t *)num,
               (__mpu_uint8_t *)mul );
      break;

    case 2:
      ismul_16( (__mpu_uint32_t *)prod,
                (__mpu_uint16_t *)num,
                (__mpu_uint16_t *)mul );
      break;

#if BITS_PER_EMUSHORT > 32
    case 4:
      ismul_32( (__mpu_uint64_t *)prod,
                (__mpu_uint32_t *)num,
                (__mpu_uint32_t *)mul );
      break;
#endif /* BITS_PER_EMUSHORT > 32 */

    default:
      ismul_np( (EMUSHORT *)prod,
                (EMUSHORT *)num,
                (EMUSHORT *)mul, nb_prod/SIZE_OF_EMUSHORT,
                                 nb_num/SIZE_OF_EMUSHORT );
      break;

  } /* End of switch( nb ) */

} /* End ismul() */


/***************************************************************
  Операции беззнакового и знакового деления.
  Изменяет флаги: CF, AF=0, PF, ZF, SF, OF, RF.
 ***************************************************************/
void idiv( mpu_int *quot, mpu_int *rem, mpu_int *num, mpu_int *den, int nb )
/* quot - частное                    */
/* rem  - остаток                    */
/* num  - делимое                    */
/* den  - делитель                   */
/* nb   - размер в байтах            */
/* Операция беззнакового деления DIV */
/*
  quot = num / den; rem = remainder;
 *************************************/
{
  __integer_error_no = 0;

  switch( nb ) /* NB is number of bytes in mpu_int's. */
  {
    case 1:
      idiv_8( (__mpu_uint8_t *)quot,
              (__mpu_uint8_t *)rem,
              (__mpu_uint8_t *)num,
              (__mpu_uint8_t *)den );
      break;

    case 2:
      idiv_16( (__mpu_uint16_t *)quot,
               (__mpu_uint16_t *)rem,
               (__mpu_uint16_t *)num,
               (__mpu_uint16_t *)den );
      break;

#if BITS_PER_EMUSHORT > 32
    case 4:
      idiv_32( (__mpu_uint32_t *)quot,
               (__mpu_uint32_t *)rem,
               (__mpu_uint32_t *)num,
               (__mpu_uint32_t *)den );
      break;
#endif /* BITS_PER_EMUSHORT > 32 */

    default:
      idiv_np( (EMUSHORT *)quot,
               (EMUSHORT *)rem,
               (EMUSHORT *)num,
               (EMUSHORT *)den, nb/SIZE_OF_EMUSHORT );
      break;

  } /* End of switch( nb ) */

} /* End idiv() */


void isdiv( mpu_int *quot, mpu_int *rem, mpu_int *num, mpu_int *den, int nb )
/* quot - частное                   */
/* rem  - остаток                   */
/* num  - делимое                   */
/* den  - делитель                  */
/* nb   - размер в байтах           */
/* Операция знакового деления SDIV  */
/*
  quot = num / den; rem = remainder;
 ************************************/
{
  __integer_error_no = 0;

  switch( nb ) /* NB is number of bytes in mpu_int's. */
  {
    case 1:
      isdiv_8( (__mpu_uint8_t *)quot,
               (__mpu_uint8_t *)rem,
               (__mpu_uint8_t *)num,
               (__mpu_uint8_t *)den );
      break;

    case 2:
      isdiv_16( (__mpu_uint16_t *)quot,
                (__mpu_uint16_t *)rem,
                (__mpu_uint16_t *)num,
                (__mpu_uint16_t *)den );
      break;

#if BITS_PER_EMUSHORT > 32
    case 4:
      isdiv_32( (__mpu_uint32_t *)quot,
                (__mpu_uint32_t *)rem,
                (__mpu_uint32_t *)num,
                (__mpu_uint32_t *)den );
      break;
#endif /* BITS_PER_EMUSHORT > 32 */

    default:
      isdiv_np( (EMUSHORT *)quot,
                (EMUSHORT *)rem,
                (EMUSHORT *)num,
                (EMUSHORT *)den, nb/SIZE_OF_EMUSHORT );
      break;

  } /* End of switch( nb ) */

} /* End isdiv() */


/***************************************************************
  Операции преобразования символьных строк в целые числа.
  Изменяет флаги: CF=0, AF=0, PF, ZF, SF, OF.  Не изменяет: RF.
 ***************************************************************/
/*
  signed
 ********/
void iatoi( mpu_int *c, __mpu_char8_t *str, int nb )
{
  __integer_error_no = 0;

  switch( nb ) /* NB is number of bytes in mpu_int's. */
  {
    case 1:
      iatoi_8( (__mpu_uint8_t *)c, str );
      break;

    case 2:
      iatoi_16( (__mpu_uint16_t *)c, str );
      break;

#if BITS_PER_EMUSHORT > 32
    case 4:
      iatoi_32( (__mpu_uint32_t *)c, str );
      break;
#endif /* BITS_PER_EMUSHORT > 32 */

    default:
      iatoi_np( (EMUSHORT *)c, str, nb/SIZE_OF_EMUSHORT );
      break;

  } /* End of switch( nb ) */

} /* End iatoi() */

/*
  unsigned
 **********/
void iatoui( mpu_int *c, __mpu_char8_t *str, int nb )
{
  __integer_error_no = 0;

  switch( nb ) /* NB is number of bytes in mpu_int's. */
  {
    case 1:
      iatoui_8( (__mpu_uint8_t *)c, str );
      break;

    case 2:
      iatoui_16( (__mpu_uint16_t *)c, str );
      break;

#if BITS_PER_EMUSHORT > 32
    case 4:
      iatoui_32( (__mpu_uint32_t *)c, str );
      break;
#endif /* BITS_PER_EMUSHORT > 32 */

    default:
      iatoui_np( (EMUSHORT *)c, str, nb/SIZE_OF_EMUSHORT );
      break;

  } /* End of switch( nb ) */

} /* End iatoui() */


/***************************************************************
  Операции преобразования  целых чисел в символьные строки.
  Не изменяет флаги: CF, AF, PF, ZF, SF, OF, RF.
 ***************************************************************/
/* radix = 2(bin), 8(oct), 10(dec), or 16(hex). */
/* uf    = 0(lowercase letter) or
           1(uppercase letter) in prefix and hex-digits. */
/* sign  = 0(' '), or 1('-'). */
/* see tetrade.h */
/*
  signed
 ********/
void iitoa( __mpu_char8_t *str, mpu_int *a, int radix, int uf, int nb )
{
  __integer_error_no = 0;

  switch( nb ) /* NB is number of bytes in mpu_int's. */
  {
    case 1:
      iitoa_8( str, (__mpu_uint8_t *)a, radix, uf );
      return;
      break;

    case 2:
      iitoa_16( str, (__mpu_uint16_t *)a, radix, uf );
      break;

#if BITS_PER_EMUSHORT > 32
    case 4:
      iitoa_32( str, (__mpu_uint32_t *)a, radix, uf );
      break;
#endif /* BITS_PER_EMUSHORT > 32 */

    default:
      iitoa_np( str,
                (EMUSHORT *)a,
                radix,
                uf,
                nb/SIZE_OF_EMUSHORT );
      break;

  } /* End of switch( nb ) */

} /* End iitoa() */

/*
  unsigned
 **********/
void iuitoa( __mpu_char8_t *str, mpu_int *a, int radix, int uf, int nb )
{
  __integer_error_no = 0;

  switch( nb ) /* NB is number of bytes in mpu_int's. */
  {
    case 1:
      iuitoa_8( str, (__mpu_uint8_t *)a, radix, uf );
      break;

    case 2:
      iuitoa_16( str, (__mpu_uint16_t *)a, radix, uf );
      break;

#if BITS_PER_EMUSHORT > 32
    case 4:
      iuitoa_32( str, (__mpu_uint32_t *)a, radix, uf );
      break;
#endif /* BITS_PER_EMUSHORT > 32 */

    default:
      iuitoa_np( str,
                 (EMUSHORT *)a,
                 radix,
                 uf,
                 nb/SIZE_OF_EMUSHORT );
      break;

  } /* End of switch( nb ) */

} /* End iuitoa() */


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

/***************************************************************
  BEGIN: mpu-floatp.h
 */

int _sizeof_exp( int nb )
/***************************************************************
  возвращает количество байт целого числа, в которое может
  уместится Exponent вещественного числа размером NB байт.
  (See: NB_R32, NB_R64, ... , NB_R_MAX in __TX_TETRADE.H).
 ***************************************************************/
{
  int rc = 0;

  __real_error_no = 0;

  switch( nb )
  {
    case NB_R32:
      rc = 1;
      break;
    case NB_R64:
      rc = 2;
      break;

    case NB_R128:
    case NB_R256:
      rc = 4;
      break;

    case NB_R512:
    case NB_R1024:
      rc = 8;
      break;

    case NB_R2048:
    case NB_R4096:
      rc =16;
      break;

    case NB_R8192:
    case NB_R16384:
      rc =32;
      break;

    case NB_R32768:
    case NB_R65536:
      rc =64;
      break;

    default:
      {
        /* error: Invalid size of operand(s) */
        __real_invalid_size( (__mpu_char8_t *)"_sizeof_exp" );
        rc = -1;
      }
      break;

  } /* End of switch( nb ) */

  return( rc );

} /* End of _sizeof_exp() */


int _real_mant_digs( int nb )
/***************************************************************
  RETURNS: # of bits in mantissa.
 ***************************************************************/
{
  int rc = 0;

  __real_error_no = 0;

  switch( nb )
  {
    case NB_R32:
      rc = 24;
      break;
    case NB_R64:
      rc = 53;
      break;

    case NB_R128: /* NOTE: +1 sign bit. */
      rc = 97;
      break;
    case NB_R256:
      rc = 225;
      break;

    case NB_R512:
      rc = 449;
      break;
    case NB_R1024:
      rc = 961;
      break;

    case NB_R2048:
      rc = 1921;
      break;
    case NB_R4096:
      rc = 3969;
      break;

    case NB_R8192:
      rc = 7937;
      break;
    case NB_R16384:
      rc = 16129;
      break;

    case NB_R32768:
      rc = 32257;
      break;
    case NB_R65536:
      rc = 65025;
      break;

    default:
      {
        /* error: Invalid size of operand(s) */
        __real_invalid_size( (__mpu_char8_t *)"_real_mant_digs" );
        rc =-1;
      }
      break;

  } /* End of switch( nb ) */

  return( rc );

} /* End of _real_mant_digs() */


int _real_digs( int nb )
/*
  RETURNS: # of decimal digits of precision
 *******************************************/
{
  int  ret;
  int  n_bits;

  __real_error_no = 0;

  __CLEAR_RFLAGS;

  n_bits = nb * BITS_PER_BYTE;

  ret = _get_ndec( n_bits );

  return( ret );

} /* End of _real_digs() */


int _real_max_string( int nb )
/*
  RETURNS: # of symbols for convert real number to string
 *********************************************************/
{
  int  ret;
  int  n_bits;

  __real_error_no = 0;

  __CLEAR_RFLAGS;

  n_bits = nb * BITS_PER_BYTE;

  ret = _get_max_string( n_bits );

  return( ret );

} /* End of _real_max_string() */


void _real_epsilon( mpu_real *c, int nb )
/*
  smallest such that 1.0+REAL_EPSILON != 1.0
 ********************************************/
{
  EMUSHORT *eic = NULL;
  int       n_bits;
  int       np;

  errno           = 0;
  __real_error_no = 0;

  __CLEAR_RFLAGS;

  n_bits = nb * BITS_PER_BYTE;

  np = internal_np( n_bits );

  /*** Allocate memory for eic . ******************************/
  eic = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eic )
  {
    /* fatal error */
    return;
  }
  /************************************************************/

  ei_copy( eic, _get_epsilon_ptr( n_bits ), n_bits );

  pack( (EMUSHORT *)c, eic, n_bits );

  /* FREE eic ***************/
  __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) );
  /**************************/

} /* End of _real_epsilon() */


void _real_max_10_exp( mpu_int *e, int nb_e, int nb_r )
/*
  max decimal exponent
 **********************/
{
  EMUSHORT *exp = NULL;
  int       ne, n_bits, n_bytes;
  int       l;

  errno           = 0;
  __real_error_no = 0;

  __CLEAR_RFLAGS;

  l = _sizeof_exp( nb_r );

  if( l <= 0 )
  {
    /* error: Invalid size of operand(s) */
    __real_invalid_size( (__mpu_char8_t *)"_real_max_10_exp" );
    return;
  }

  if( nb_e < l )
  {
    /* error: Invalid size of operand(s) */
    __real_invalid_size( (__mpu_char8_t *)"_real_max_10_exp" );
    return;
  }

  n_bits  = nb_r * BITS_PER_BYTE;
  ne      = internal_ne( n_bits ) + 1;
  n_bytes = ne * SIZE_OF_EMUSHORT;

  /*** Allocate memory for exp . ******************************/
  exp = (EMUSHORT *)__mpu_sbrk( (int)(ne*SIZE_OF_EMUSHORT) );
  if( !exp )
  {
    /* fatal error */
    return;
  }
  /************************************************************/

  ei_cpye( exp, _get_max_10_exp_ptr( n_bits ), ne, ne );

  /*
    Операция преобразования (convert) данных CVT.
    Воздействует на флаги: OF, PF, SF, ZF.
    Флаги CF, AF не изменяются.
   ***********************************************/
  icvt( e, (mpu_int *)exp, nb_e, n_bytes );

  /* FREE exp ***************/
  __mpu_sbrk( -(int)(ne*SIZE_OF_EMUSHORT) );
  /**************************/

} /* End of _real_max_10_exp() */


void _real_min_10_exp( mpu_int *e, int nb_e, int nb_r )
/*
  min decimal exponent
 **********************/
{
  EMUSHORT  *exp = NULL;
  int        ne, n_bits, n_bytes;
  int        l;

  errno           = 0;
  __real_error_no = 0;

  __CLEAR_RFLAGS;

  l = _sizeof_exp( nb_r );

  if( l <= 0 )
  {
    /* error: Invalid size of operand(s) */
    __real_invalid_size( (__mpu_char8_t *)"_real_min_10_exp" );
    return;
  }

  if( nb_e < l )
  {
    /* error: Invalid size of operand(s) */
    __real_invalid_size( (__mpu_char8_t *)"_real_min_10_exp" );
    return;
  }

  n_bits  = nb_r * BITS_PER_BYTE;
  ne      = internal_ne( n_bits ) + 1;
  n_bytes = ne * SIZE_OF_EMUSHORT;

  /*** Allocate memory for exp . ******************************/
  exp = (EMUSHORT *)__mpu_sbrk( (int)(ne*SIZE_OF_EMUSHORT) );
  if( !exp )
  {
    /* fatal error */
    return;
  }
  /************************************************************/

  ei_cpye( exp, _get_min_10_exp_ptr( n_bits ), ne, ne );

  /*
    Операция преобразования (convert) данных CVT.
    Воздействует на флаги: OF, PF, SF, ZF.
    Флаги CF, AF не изменяются.
   ***********************************************/
  icvt( e, (mpu_int *)exp, nb_e, n_bytes );

  /* FREE exp ***************/
  __mpu_sbrk( -(int)(ne*SIZE_OF_EMUSHORT) );
  /**************************/

} /* End of _real_min_10_exp() */


void _real_max_max_exp( mpu_int *e, int nb_e, int nb_r )
/*
  max max binary exponent
 *************************/
{
  EMUSHORT *exp = NULL;
  int       ne, n_bits, n_bytes;
  int       l;

  errno           = 0;
  __real_error_no = 0;

  __CLEAR_RFLAGS;

  l = _sizeof_exp( nb_r );

  if( l <= 0 )
  {
    /* error: Invalid size of operand(s) */
    __real_invalid_size( (__mpu_char8_t *)"_real_max_max_exp" );
    return;
  }

  if( nb_e < l )
  {
    /* error: Invalid size of operand(s) */
    __real_invalid_size( (__mpu_char8_t *)"_real_max_max_exp" );
    return;
  }

  n_bits  = nb_r * BITS_PER_BYTE;
  ne      = internal_ne( n_bits ) + 1;
  n_bytes = ne * SIZE_OF_EMUSHORT;

  /*** Allocate memory for exp . ******************************/
  exp = (EMUSHORT *)__mpu_sbrk( (int)(ne*SIZE_OF_EMUSHORT) );
  if( !exp )
  {
    /* fatal error */
    return;
  }
  /************************************************************/

  ei_cpye( exp, _get_max_max_2_exp_ptr( n_bits ), ne, ne );

  /*
    Операция преобразования (convert) данных CVT.
    Воздействует на флаги: OF, PF, SF, ZF.
    Флаги CF, AF не изменяются.
   ***********************************************/
  icvt( e, (mpu_int *)exp, nb_e, n_bytes );

  /* FREE exp ***************/
  __mpu_sbrk( -(int)(ne*SIZE_OF_EMUSHORT) );
  /**************************/

} /* End of _real_max_max_exp() */


void _real_max_exp( mpu_int *e, int nb_e, int nb_r )
/*
  max binary exponent ( EXONE )
 *******************************/
{
  EMUSHORT *exp = NULL;
  int       ne, n_bits, n_bytes;
  int       l;

  errno           = 0;
  __real_error_no = 0;

  __CLEAR_RFLAGS;

  l = _sizeof_exp( nb_r );

  if( l <= 0 )
  {
    /* error: Invalid size of operand(s) */
    __real_invalid_size( (__mpu_char8_t *)"_real_max_exp" );
    return;
  }

  if( nb_e < l )
  {
    /* error: Invalid size of operand(s) */
    __real_invalid_size( (__mpu_char8_t *)"_real_max_exp" );
    return;
  }

  n_bits  = nb_r * BITS_PER_BYTE;
  ne      = internal_ne( n_bits ) + 1;
  n_bytes = ne * SIZE_OF_EMUSHORT;

  /*** Allocate memory for exp . ******************************/
  exp = (EMUSHORT *)__mpu_sbrk( (int)(ne*SIZE_OF_EMUSHORT) );
  if( !exp )
  {
    /* fatal error */
    return;
  }
  /************************************************************/

  ei_cpye( exp, _get_max_2_exp_ptr( n_bits ), ne, ne );

  /*
    Операция преобразования (convert) данных CVT.
    Воздействует на флаги: OF, PF, SF, ZF.
    Флаги CF, AF не изменяются.
   ***********************************************/
  icvt( e, (mpu_int *)exp, nb_e, n_bytes );

  /* FREE exp ***************/
  __mpu_sbrk( -(int)(ne*SIZE_OF_EMUSHORT) );
  /**************************/

} /* End of _real_max_exp() */


void _real_min_exp( mpu_int *e, int nb_e, int nb_r )
/*
  min binary exponent
 *********************/
{
  EMUSHORT *exp = NULL;
  int       ne, n_bits, n_bytes;
  int       l;

  errno           = 0;
  __real_error_no = 0;

  __CLEAR_RFLAGS;

  l = _sizeof_exp( nb_r );

  if( l <= 0 )
  {
    /* error: Invalid size of operand(s) */
    __real_invalid_size( (__mpu_char8_t *)"_real_min_exp" );
    return;
  }

  if( nb_e < l )
  {
    /* error: Invalid size of operand(s) */
    __real_invalid_size( (__mpu_char8_t *)"_real_min_exp" );
    return;
  }

  n_bits  = nb_r * BITS_PER_BYTE;
  ne      = internal_ne( n_bits ) + 1;
  n_bytes = ne * SIZE_OF_EMUSHORT;

  /*** Allocate memory for exp . ******************************/
  exp = (EMUSHORT *)__mpu_sbrk( (int)(ne*SIZE_OF_EMUSHORT) );
  if( !exp )
  {
    /* fatal error */
    return;
  }
  /************************************************************/

  ei_cpye( exp, _get_min_2_exp_ptr( n_bits ), ne, ne );

  /*
    Операция преобразования (convert) данных CVT.
    Воздействует на флаги: OF, PF, SF, ZF.
    Флаги CF, AF не изменяются.
   ***********************************************/
  icvt( e, (mpu_int *)exp, nb_e, n_bytes );

  /* FREE exp ***************/
  __mpu_sbrk( -(int)(ne*SIZE_OF_EMUSHORT) );
  /**************************/

} /* End of _real_min_exp() */

/*
  END: mpu-floatp.h
 ***************************************************************/


/***************************************************************
  ARITHMETIC & MATHEMATIC CONSTANTS.
 **/
void _m_zero( mpu_real *c, int nb )
{
  EMUSHORT *eic = NULL;
  int       n_bits;
  int       np;

  errno           = 0;
  __real_error_no = 0;

  __CLEAR_RFLAGS;

  n_bits = nb * BITS_PER_BYTE;

  np = internal_np( n_bits );

  /*** Allocate memory for eic . ******************************/
  eic = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eic )
  {
    /* fatal error */
    return;
  }
  /************************************************************/

  _gen_zero( eic, n_bits );

  pack( (EMUSHORT *)c, eic, n_bits );

  /* FREE eic ***************/
  __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) );
  /**************************/

} /* End of _m_zero() */


void _m_half( mpu_real *c, int nb )
{
  EMUSHORT *eic = NULL;
  int       n_bits;
  int       np;

  errno           = 0;
  __real_error_no = 0;

  __CLEAR_RFLAGS;

  n_bits = nb * BITS_PER_BYTE;

  np = internal_np( n_bits );

  /*** Allocate memory for eic . ******************************/
  eic = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eic )
  {
    /* fatal error */
    return;
  }
  /************************************************************/

  _gen_half( eic, n_bits );

  pack( (EMUSHORT *)c, eic, n_bits );

  /* FREE eic ***************/
  __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) );
  /**************************/

} /* End of _m_half() */


void _m_one( mpu_real *c, int nb )
{
  EMUSHORT *eic = NULL;
  int       n_bits;
  int       np;

  errno           = 0;
  __real_error_no = 0;

  __CLEAR_RFLAGS;

  n_bits = nb * BITS_PER_BYTE;

  np = internal_np( n_bits );

  /*** Allocate memory for eic . ******************************/
  eic = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eic )
  {
    /* fatal error */
    return;
  }
  /************************************************************/

  _gen_one( eic, n_bits );

  pack( (EMUSHORT *)c, eic, n_bits );

  /* FREE eic ***************/
  __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) );
  /**************************/

} /* End of _m_one() */


void _m_two( mpu_real *c, int nb )
{
  EMUSHORT *eic = NULL;
  int       n_bits;
  int       np;

  errno           = 0;
  __real_error_no = 0;

  __CLEAR_RFLAGS;

  n_bits = nb * BITS_PER_BYTE;

  np = internal_np( n_bits );

  /*** Allocate memory for eic . ******************************/
  eic = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eic )
  {
    /* fatal error */
    return;
  }
  /************************************************************/

  _gen_two( eic, n_bits );

  pack( (EMUSHORT *)c, eic, n_bits );

  /* FREE eic ***************/
  __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) );
  /**************************/

} /* End of _m_two() */


void _m_ten( mpu_real *c, int nb )
{
  EMUSHORT *eic = NULL;
  int       n_bits;
  int       np;

  errno           = 0;
  __real_error_no = 0;

  __CLEAR_RFLAGS;

  n_bits = nb * BITS_PER_BYTE;

  np = internal_np( n_bits );

  /*** Allocate memory for eic . ******************************/
  eic = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eic )
  {
    /* fatal error */
    return;
  }
  /************************************************************/

  _gen_ten( eic, n_bits );

  pack( (EMUSHORT *)c, eic, n_bits );

  /* FREE eic ***************/
  __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) );
  /**************************/

} /* End of _m_ten() */


void _m_mten( mpu_real *c, int nb )
{
  EMUSHORT *eic = NULL;
  int       n_bits;
  int       np;

  errno           = 0;
  __real_error_no = 0;

  __CLEAR_RFLAGS;

  n_bits = nb * BITS_PER_BYTE;

  np = internal_np( n_bits );

  /*** Allocate memory for eic . ******************************/
  eic = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eic )
  {
    /* fatal error */
    return;
  }
  /************************************************************/

  _gen_mten( eic, n_bits );

  pack( (EMUSHORT *)c, eic, n_bits );

  /* FREE eic ***************/
  __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) );
  /**************************/

} /* End of _m_mten() */


void _m_32( mpu_real *c, int nb )
{
  EMUSHORT *eic = NULL;
  int       n_bits;
  int       np;

  errno           = 0;
  __real_error_no = 0;

  __CLEAR_RFLAGS;

  n_bits = nb * BITS_PER_BYTE;

  np = internal_np( n_bits );

  /*** Allocate memory for eic . ******************************/
  eic = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eic )
  {
    /* fatal error */
    return;
  }
  /************************************************************/

  _gen_32( eic, n_bits );

  pack( (EMUSHORT *)c, eic, n_bits );

  /* FREE eic ***************/
  __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) );
  /**************************/

} /* End of _m_32() */

void _m_PI( mpu_real *c, int nb )
{
  EMUSHORT *eic = NULL;
  int       n_bits;
  int       np;

  errno           = 0;
  __real_error_no = 0;

  __CLEAR_RFLAGS;

  n_bits = nb * BITS_PER_BYTE;

  np = internal_np( n_bits );

  /*** Allocate memory for eic . ******************************/
  eic = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eic )
  {
    /* fatal error */
    return;
  }
  /************************************************************/

  ei_copy( eic, _get_m_pi_ptr( n_bits ), n_bits );

  pack( (EMUSHORT *)c, eic, n_bits );

  /* FREE eic ***************/
  __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) );
  /**************************/

} /* End of _m_PI() */


void _m_E( mpu_real *c, int nb )
{
  EMUSHORT *eic = NULL;
  int       n_bits;
  int       np;

  errno           = 0;
  __real_error_no = 0;

  __CLEAR_RFLAGS;

  n_bits = nb * BITS_PER_BYTE;

  np = internal_np( n_bits );

  /*** Allocate memory for eic . ******************************/
  eic = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eic )
  {
    /* fatal error */
    return;
  }
  /************************************************************/

  ei_copy( eic, _get_m_e_ptr( n_bits ), n_bits );

  pack( (EMUSHORT *)c, eic, n_bits );

  /* FREE eic ***************/
  __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) );
  /**************************/

} /* End of _m_E() */


void _m_1_ln2( mpu_real *c, int nb )
{
  EMUSHORT *eic = NULL;
  int       n_bits;
  int       np;

  errno           = 0;
  __real_error_no = 0;

  __CLEAR_RFLAGS;

  n_bits = nb * BITS_PER_BYTE;

  np = internal_np( n_bits );

  /*** Allocate memory for eic . ******************************/
  eic = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eic )
  {
    /* fatal error */
    return;
  }
  /************************************************************/

  ei_copy( eic, _get_m_1_ln2_ptr( n_bits ), n_bits );

  pack( (EMUSHORT *)c, eic, n_bits );

  /* FREE eic ***************/
  __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) );
  /**************************/

} /* End of _m_1_ln2() */


void _m_ln2( mpu_real *c, int nb )
{
  EMUSHORT *eic = NULL;
  int       n_bits;
  int       np;

  errno           = 0;
  __real_error_no = 0;

  __CLEAR_RFLAGS;

  n_bits = nb * BITS_PER_BYTE;

  np = internal_np( n_bits );

  /*** Allocate memory for eic . ******************************/
  eic = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eic )
  {
    /* fatal error */
    return;
  }
  /************************************************************/

  ei_copy( eic, _get_m_ln2_ptr( n_bits ), n_bits );

  pack( (EMUSHORT *)c, eic, n_bits );

  /* FREE eic ***************/
  __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) );
  /**************************/

} /* End of _m_ln2() */


void _m_1_ln10( mpu_real *c, int nb )
{
  EMUSHORT *eic = NULL;
  int       n_bits;
  int       np;

  errno           = 0;
  __real_error_no = 0;

  __CLEAR_RFLAGS;

  n_bits = nb * BITS_PER_BYTE;

  np = internal_np( n_bits );

  /*** Allocate memory for eic . ******************************/
  eic = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eic )
  {
    /* fatal error */
    return;
  }
  /************************************************************/

  ei_copy( eic, _get_m_1_ln10_ptr( n_bits ), n_bits );

  pack( (EMUSHORT *)c, eic, n_bits );

  /* FREE eic ***************/
  __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) );
  /**************************/

} /* End of _m_1_ln10() */


void _m_ln10( mpu_real *c, int nb )
{
  EMUSHORT *eic = NULL;
  int       n_bits;
  int       np;

  errno           = 0;
  __real_error_no = 0;

  __CLEAR_RFLAGS;

  n_bits = nb * BITS_PER_BYTE;

  np = internal_np( n_bits );

  /*** Allocate memory for eic . ******************************/
  eic = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eic )
  {
    /* fatal error */
    return;
  }
  /************************************************************/

  ei_copy( eic, _get_m_ln10_ptr( n_bits ), n_bits );

  pack( (EMUSHORT *)c, eic, n_bits );

  /* FREE eic ***************/
  __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) );
  /**************************/

} /* End of _m_ln10() */


void _m_1_lg2( mpu_real *c, int nb )
{
  EMUSHORT *eic = NULL;
  int       n_bits;
  int       np;

  errno           = 0;
  __real_error_no = 0;

  __CLEAR_RFLAGS;

  n_bits = nb * BITS_PER_BYTE;

  np = internal_np( n_bits );

  /*** Allocate memory for eic . ******************************/
  eic = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eic )
  {
    /* fatal error */
    return;
  }
  /************************************************************/

  ei_copy( eic, _get_m_1_lg2_ptr( n_bits ), n_bits );

  pack( (EMUSHORT *)c, eic, n_bits );

  /* FREE eic ***************/
  __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) );
  /**************************/

} /* End of _m_1_lg2() */


void _m_lg2( mpu_real *c, int nb )
{
  EMUSHORT *eic = NULL;
  int       n_bits;
  int       np;

  errno           = 0;
  __real_error_no = 0;

  __CLEAR_RFLAGS;

  n_bits = nb * BITS_PER_BYTE;

  np = internal_np( n_bits );

  /*** Allocate memory for eic . ******************************/
  eic = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eic )
  {
    /* fatal error */
    return;
  }
  /************************************************************/

  ei_copy( eic, _get_m_lg2_ptr( n_bits ), n_bits );

  pack( (EMUSHORT *)c, eic, n_bits );

  /* FREE eic ***************/
  __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) );
  /**************************/

} /* End of _m_lg2() */


void _m_PI_2( mpu_real *c, int nb )
{
  EMUSHORT *eic = NULL;
  int       n_bits;
  int       np;

  errno           = 0;
  __real_error_no = 0;

  __CLEAR_RFLAGS;

  n_bits = nb * BITS_PER_BYTE;

  np = internal_np( n_bits );

  /*** Allocate memory for eic . ******************************/
  eic = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eic )
  {
    /* fatal error */
    return;
  }
  /************************************************************/

  ei_copy( eic, _get_m_pi_2_ptr( n_bits ), n_bits );

  pack( (EMUSHORT *)c, eic, n_bits );

  /* FREE eic ***************/
  __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) );
  /**************************/

} /* End of _m_PI_2() */


void _m_PI_3( mpu_real *c, int nb )
{
  EMUSHORT *eic = NULL;
  int       n_bits;
  int       np;

  errno           = 0;
  __real_error_no = 0;

  __CLEAR_RFLAGS;

  n_bits = nb * BITS_PER_BYTE;

  np = internal_np( n_bits );

  /*** Allocate memory for eic . ******************************/
  eic = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eic )
  {
    /* fatal error */
    return;
  }
  /************************************************************/

  ei_copy( eic, _get_m_pi_3_ptr( n_bits ), n_bits );

  pack( (EMUSHORT *)c, eic, n_bits );

  /* FREE eic ***************/
  __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) );
  /**************************/

} /* End of _m_PI_3() */


void _m_PI_4( mpu_real *c, int nb )
{
  EMUSHORT *eic = NULL;
  int       n_bits;
  int       np;

  errno           = 0;
  __real_error_no = 0;

  __CLEAR_RFLAGS;

  n_bits = nb * BITS_PER_BYTE;

  np = internal_np( n_bits );

  /*** Allocate memory for eic . ******************************/
  eic = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eic )
  {
    /* fatal error */
    return;
  }
  /************************************************************/

  ei_copy( eic, _get_m_pi_4_ptr( n_bits ), n_bits );

  pack( (EMUSHORT *)c, eic, n_bits );

  /* FREE eic ***************/
  __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) );
  /**************************/

} /* End of _m_PI_4() */


void _m_PI_5( mpu_real *c, int nb )
{
  EMUSHORT *eic = NULL;
  int       n_bits;
  int       np;

  errno           = 0;
  __real_error_no = 0;

  __CLEAR_RFLAGS;

  n_bits = nb * BITS_PER_BYTE;

  np = internal_np( n_bits );

  /*** Allocate memory for eic . ******************************/
  eic = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eic )
  {
    /* fatal error */
    return;
  }
  /************************************************************/

  ei_copy( eic, _get_m_pi_5_ptr( n_bits ), n_bits );

  pack( (EMUSHORT *)c, eic, n_bits );

  /* FREE eic ***************/
  __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) );
  /**************************/

} /* End of _m_PI_5() */


void _m_PI_6( mpu_real *c, int nb )
{
  EMUSHORT *eic = NULL;
  int       n_bits;
  int       np;

  errno           = 0;
  __real_error_no = 0;

  __CLEAR_RFLAGS;

  n_bits = nb * BITS_PER_BYTE;

  np = internal_np( n_bits );

  /*** Allocate memory for eic . ******************************/
  eic = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eic )
  {
    /* fatal error */
    return;
  }
  /************************************************************/

  ei_copy( eic, _get_m_pi_6_ptr( n_bits ), n_bits );

  pack( (EMUSHORT *)c, eic, n_bits );

  /* FREE eic ***************/
  __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) );
  /**************************/

} /* End of _m_PI_6() */


void _m_1_PI( mpu_real *c, int nb )
{
  EMUSHORT *eic = NULL;
  int       n_bits;
  int       np;

  errno           = 0;
  __real_error_no = 0;

  __CLEAR_RFLAGS;

  n_bits = nb * BITS_PER_BYTE;

  np = internal_np( n_bits );

  /*** Allocate memory for eic . ******************************/
  eic = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eic )
  {
    /* fatal error */
    return;
  }
  /************************************************************/

  ei_copy( eic, _get_m_1_pi_ptr( n_bits ), n_bits );

  pack( (EMUSHORT *)c, eic, n_bits );

  /* FREE eic ***************/
  __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) );
  /**************************/

} /* End of _m_1_PI() */


void _m_2_PI( mpu_real *c, int nb )
{
  EMUSHORT *eic = NULL;
  int       n_bits;
  int       np;

  errno           = 0;
  __real_error_no = 0;

  __CLEAR_RFLAGS;

  n_bits = nb * BITS_PER_BYTE;

  np = internal_np( n_bits );

  /*** Allocate memory for eic . ******************************/
  eic = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eic )
  {
    /* fatal error */
    return;
  }
  /************************************************************/

  ei_copy( eic, _get_m_2_pi_ptr( n_bits ), n_bits );

  pack( (EMUSHORT *)c, eic, n_bits );

  /* FREE eic ***************/
  __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) );
  /**************************/

} /* End of _m_2_PI() */


void _m_3_PI( mpu_real *c, int nb )
{
  EMUSHORT *eic = NULL;
  int       n_bits;
  int       np;

  errno           = 0;
  __real_error_no = 0;

  __CLEAR_RFLAGS;

  n_bits = nb * BITS_PER_BYTE;

  np = internal_np( n_bits );

  /*** Allocate memory for eic . ******************************/
  eic = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eic )
  {
    /* fatal error */
    return;
  }
  /************************************************************/

  ei_copy( eic, _get_m_3_pi_ptr( n_bits ), n_bits );

  pack( (EMUSHORT *)c, eic, n_bits );

  /* FREE eic ***************/
  __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) );
  /**************************/

} /* End of _m_3_PI() */


void _m_4_PI( mpu_real *c, int nb )
{
  EMUSHORT *eic = NULL;
  int       n_bits;
  int       np;

  errno           = 0;
  __real_error_no = 0;

  __CLEAR_RFLAGS;

  n_bits = nb * BITS_PER_BYTE;

  np = internal_np( n_bits );

  /*** Allocate memory for eic . ******************************/
  eic = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eic )
  {
    /* fatal error */
    return;
  }
  /************************************************************/

  ei_copy( eic, _get_m_4_pi_ptr( n_bits ), n_bits );

  pack( (EMUSHORT *)c, eic, n_bits );

  /* FREE eic ***************/
  __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) );
  /**************************/

} /* End of _m_4_PI() */


void _m_5_PI( mpu_real *c, int nb )
{
  EMUSHORT *eic = NULL;
  int       n_bits;
  int       np;

  errno           = 0;
  __real_error_no = 0;

  __CLEAR_RFLAGS;

  n_bits = nb * BITS_PER_BYTE;

  np = internal_np( n_bits );

  /*** Allocate memory for eic . ******************************/
  eic = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eic )
  {
    /* fatal error */
    return;
  }
  /************************************************************/

  ei_copy( eic, _get_m_5_pi_ptr( n_bits ), n_bits );

  pack( (EMUSHORT *)c, eic, n_bits );

  /* FREE eic ***************/
  __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) );
  /**************************/

} /* End of _m_5_PI() */


void _m_2PI( mpu_real *c, int nb )
{
  EMUSHORT *eic = NULL;
  int       n_bits;
  int       np;

  errno           = 0;
  __real_error_no = 0;

  __CLEAR_RFLAGS;

  n_bits = nb * BITS_PER_BYTE;

  np = internal_np( n_bits );

  /*** Allocate memory for eic . ******************************/
  eic = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eic )
  {
    /* fatal error */
    return;
  }
  /************************************************************/

  ei_copy( eic, _get_m_2pi_ptr( n_bits ), n_bits );

  pack( (EMUSHORT *)c, eic, n_bits );

  /* FREE eic ***************/
  __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) );
  /**************************/

} /* End of _m_2PI() */


void _m_3PI( mpu_real *c, int nb )
{
  EMUSHORT *eic = NULL;
  int       n_bits;
  int       np;

  errno           = 0;
  __real_error_no = 0;

  __CLEAR_RFLAGS;

  n_bits = nb * BITS_PER_BYTE;

  np = internal_np( n_bits );

  /*** Allocate memory for eic . ******************************/
  eic = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eic )
  {
    /* fatal error */
    return;
  }
  /************************************************************/

  ei_copy( eic, _get_m_3pi_ptr( n_bits ), n_bits );

  pack( (EMUSHORT *)c, eic, n_bits );

  /* FREE eic ***************/
  __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) );
  /**************************/

} /* End of _m_3PI() */


void _m_1_2PI( mpu_real *c, int nb )
{
  EMUSHORT *eic = NULL;
  int       n_bits;
  int       np;

  errno           = 0;
  __real_error_no = 0;

  __CLEAR_RFLAGS;

  n_bits = nb * BITS_PER_BYTE;

  np = internal_np( n_bits );

  /*** Allocate memory for eic . ******************************/
  eic = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eic )
  {
    /* fatal error */
    return;
  }
  /************************************************************/

  ei_copy( eic, _get_m_1_2pi_ptr( n_bits ), n_bits );

  pack( (EMUSHORT *)c, eic, n_bits );

  /* FREE eic ***************/
  __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) );
  /**************************/

} /* End of _m_1_2PI() */


void _m_1_3PI( mpu_real *c, int nb )
{
  EMUSHORT *eic = NULL;
  int       n_bits;
  int       np;

  errno           = 0;
  __real_error_no = 0;

  __CLEAR_RFLAGS;

  n_bits = nb * BITS_PER_BYTE;

  np = internal_np( n_bits );

  /*** Allocate memory for eic . ******************************/
  eic = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eic )
  {
    /* fatal error */
    return;
  }
  /************************************************************/

  ei_copy( eic, _get_m_1_3pi_ptr( n_bits ), n_bits );

  pack( (EMUSHORT *)c, eic, n_bits );

  /* FREE eic ***************/
  __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) );
  /**************************/

} /* End of _m_1_3PI() */


void _m_1_4PI( mpu_real *c, int nb )
{
  EMUSHORT *eic = NULL;
  int       n_bits;
  int       np;

  errno           = 0;
  __real_error_no = 0;

  __CLEAR_RFLAGS;

  n_bits = nb * BITS_PER_BYTE;

  np = internal_np( n_bits );

  /*** Allocate memory for eic . ******************************/
  eic = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eic )
  {
    /* fatal error */
    return;
  }
  /************************************************************/

  ei_copy( eic, _get_m_1_4pi_ptr( n_bits ), n_bits );

  pack( (EMUSHORT *)c, eic, n_bits );

  /* FREE eic ***************/
  __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) );
  /**************************/

} /* End of _m_1_4PI() */


void _m_1_5PI( mpu_real *c, int nb )
{
  EMUSHORT *eic = NULL;
  int       n_bits;
  int       np;

  errno           = 0;
  __real_error_no = 0;

  __CLEAR_RFLAGS;

  n_bits = nb * BITS_PER_BYTE;

  np = internal_np( n_bits );

  /*** Allocate memory for eic . ******************************/
  eic = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eic )
  {
    /* fatal error */
    return;
  }
  /************************************************************/

  ei_copy( eic, _get_m_1_5pi_ptr( n_bits ), n_bits );

  pack( (EMUSHORT *)c, eic, n_bits );

  /* FREE eic ***************/
  __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) );
  /**************************/

} /* End of _m_1_5PI() */


void _m_1_6PI( mpu_real *c, int nb )
{
  EMUSHORT *eic = NULL;
  int       n_bits;
  int       np;

  errno           = 0;
  __real_error_no = 0;

  __CLEAR_RFLAGS;

  n_bits = nb * BITS_PER_BYTE;

  np = internal_np( n_bits );

  /*** Allocate memory for eic . ******************************/
  eic = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eic )
  {
    /* fatal error */
    return;
  }
  /************************************************************/

  ei_copy( eic, _get_m_1_6pi_ptr( n_bits ), n_bits );

  pack( (EMUSHORT *)c, eic, n_bits );

  /* FREE eic ***************/
  __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) );
  /**************************/

} /* End of _m_1_6PI() */


void _m_3PI_4( mpu_real *c, int nb )
{
  EMUSHORT *eic = NULL;
  int       n_bits;
  int       np;

  errno           = 0;
  __real_error_no = 0;

  __CLEAR_RFLAGS;

  n_bits = nb * BITS_PER_BYTE;

  np = internal_np( n_bits );

  /*** Allocate memory for eic . ******************************/
  eic = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eic )
  {
    /* fatal error */
    return;
  }
  /************************************************************/

  ei_copy( eic, _get_m_3pi_4_ptr( n_bits ), n_bits );

  pack( (EMUSHORT *)c, eic, n_bits );

  /* FREE eic ***************/
  __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) );
  /**************************/

} /* End of _m_3PI_4() */


void _m_SQRTPI( mpu_real *c, int nb )
{
  EMUSHORT *eic = NULL;
  int       n_bits;
  int       np;

  errno           = 0;
  __real_error_no = 0;

  __CLEAR_RFLAGS;

  n_bits = nb * BITS_PER_BYTE;

  np = internal_np( n_bits );

  /*** Allocate memory for eic . ******************************/
  eic = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eic )
  {
    /* fatal error */
    return;
  }
  /************************************************************/

  ei_copy( eic, _get_m_sqrtpi_ptr( n_bits ), n_bits );

  pack( (EMUSHORT *)c, eic, n_bits );

  /* FREE eic ***************/
  __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) );
  /**************************/

} /* End of _m_SQRTPI() */


void _m_1_SQRTPI( mpu_real *c, int nb )
{
  EMUSHORT *eic = NULL;
  int       n_bits;
  int       np;

  errno           = 0;
  __real_error_no = 0;

  __CLEAR_RFLAGS;

  n_bits = nb * BITS_PER_BYTE;

  np = internal_np( n_bits );

  /*** Allocate memory for eic . ******************************/
  eic = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eic )
  {
    /* fatal error */
    return;
  }
  /************************************************************/

  ei_copy( eic, _get_m_1_sqrtpi_ptr( n_bits ), n_bits );

  pack( (EMUSHORT *)c, eic, n_bits );

  /* FREE eic ***************/
  __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) );
  /**************************/

} /* End of _m_1_SQRTPI() */


void _m_2_SQRTPI( mpu_real *c, int nb )
{
  EMUSHORT *eic = NULL;
  int       n_bits;
  int       np;

  errno           = 0;
  __real_error_no = 0;

  __CLEAR_RFLAGS;

  n_bits = nb * BITS_PER_BYTE;

  np = internal_np( n_bits );

  /*** Allocate memory for eic . ******************************/
  eic = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eic )
  {
    /* fatal error */
    return;
  }
  /************************************************************/

  ei_copy( eic, _get_m_2_sqrtpi_ptr( n_bits ), n_bits );

  pack( (EMUSHORT *)c, eic, n_bits );

  /* FREE eic ***************/
  __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) );
  /**************************/

} /* End of _m_2_SQRTPI() */


void _m_SQRT2( mpu_real *c, int nb )
{
  EMUSHORT *eic = NULL;
  int       n_bits;
  int       np;

  errno           = 0;
  __real_error_no = 0;

  __CLEAR_RFLAGS;

  n_bits = nb * BITS_PER_BYTE;

  np = internal_np( n_bits );

  /*** Allocate memory for eic . ******************************/
  eic = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eic )
  {
    /* fatal error */
    return;
  }
  /************************************************************/

  ei_copy( eic, _get_m_sqrt2_ptr( n_bits ), n_bits );

  pack( (EMUSHORT *)c, eic, n_bits );

  /* FREE eic ***************/
  __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) );
  /**************************/

} /* End of _m_SQRT2() */


void _m_1_SQRT2( mpu_real *c, int nb )
{
  EMUSHORT *eic = NULL;
  int       n_bits;
  int       np;

  errno           = 0;
  __real_error_no = 0;

  __CLEAR_RFLAGS;

  n_bits = nb * BITS_PER_BYTE;

  np = internal_np( n_bits );

  /*** Allocate memory for eic . ******************************/
  eic = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eic )
  {
    /* fatal error */
    return;
  }
  /************************************************************/

  ei_copy( eic, _get_m_1_sqrt2_ptr( n_bits ), n_bits );

  pack( (EMUSHORT *)c, eic, n_bits );

  /* FREE eic ***************/
  __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) );
  /**************************/

} /* End of _m_1_SQRT2() */


void _m_SQRT3( mpu_real *c, int nb )
{
  EMUSHORT *eic = NULL;
  int       n_bits;
  int       np;

  errno           = 0;
  __real_error_no = 0;

  __CLEAR_RFLAGS;

  n_bits = nb * BITS_PER_BYTE;

  np = internal_np( n_bits );

  /*** Allocate memory for eic . ******************************/
  eic = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eic )
  {
    /* fatal error */
    return;
  }
  /************************************************************/

  ei_copy( eic, _get_m_sqrt3_ptr( n_bits ), n_bits );

  pack( (EMUSHORT *)c, eic, n_bits );

  /* FREE eic ***************/
  __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) );
  /**************************/

} /* End of _m_SQRT3() */


void _m_1_SQRT3( mpu_real *c, int nb )
{
  EMUSHORT *eic = NULL;
  int       n_bits;
  int       np;

  errno           = 0;
  __real_error_no = 0;

  __CLEAR_RFLAGS;

  n_bits = nb * BITS_PER_BYTE;

  np = internal_np( n_bits );

  /*** Allocate memory for eic . ******************************/
  eic = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eic )
  {
    /* fatal error */
    return;
  }
  /************************************************************/

  ei_copy( eic, _get_m_1_sqrt3_ptr( n_bits ), n_bits );

  pack( (EMUSHORT *)c, eic, n_bits );

  /* FREE eic ***************/
  __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) );
  /**************************/

} /* End of _m_1_SQRT3() */


void _m_DEGREE( mpu_real *c, int nb )
{
  EMUSHORT *eic = NULL;
  int       n_bits;
  int       np;

  errno           = 0;
  __real_error_no = 0;

  __CLEAR_RFLAGS;

  n_bits = nb * BITS_PER_BYTE;

  np = internal_np( n_bits );

  /*** Allocate memory for eic . ******************************/
  eic = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eic )
  {
    /* fatal error */
    return;
  }
  /************************************************************/

  ei_copy( eic, _get_m_degree_ptr( n_bits ), n_bits );

  pack( (EMUSHORT *)c, eic, n_bits );

  /* FREE eic ***************/
  __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) );
  /**************************/

} /* End of _m_DEGREE() */


void _m_1_DEGREE( mpu_real *c, int nb )
{
  EMUSHORT *eic = NULL;
  int       n_bits;
  int       np;

  errno           = 0;
  __real_error_no = 0;

  __CLEAR_RFLAGS;

  n_bits = nb * BITS_PER_BYTE;

  np = internal_np( n_bits );

  /*** Allocate memory for eic . ******************************/
  eic = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eic )
  {
    /* fatal error */
    return;
  }
  /************************************************************/

  ei_copy( eic, _get_m_1_degree_ptr( n_bits ), n_bits );

  pack( (EMUSHORT *)c, eic, n_bits );

  /* FREE eic ***************/
  __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) );
  /**************************/

} /* End of _m_1_DEGREE() */


void _m_GOLDENRATIO( mpu_real *c, int nb )
{
  EMUSHORT *eic = NULL;
  int       n_bits;
  int       np;

  errno           = 0;
  __real_error_no = 0;

  __CLEAR_RFLAGS;

  n_bits = nb * BITS_PER_BYTE;

  np = internal_np( n_bits );

  /*** Allocate memory for eic . ******************************/
  eic = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eic )
  {
    /* fatal error */
    return;
  }
  /************************************************************/

  ei_copy( eic, _get_m_goldenratio_ptr( n_bits ), n_bits );

  pack( (EMUSHORT *)c, eic, n_bits );

  /* FREE eic ***************/
  __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) );
  /**************************/

} /* End of _m_GOLDENRATIO() */


void _m_EULERGAMMA( mpu_real *c, int nb )
{
  EMUSHORT *eic = NULL;
  int       n_bits;
  int       np;

  errno           = 0;
  __real_error_no = 0;

  __CLEAR_RFLAGS;

  n_bits = nb * BITS_PER_BYTE;

  np = internal_np( n_bits );

  /*** Allocate memory for eic . ******************************/
  eic = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eic )
  {
    /* fatal error */
    return;
  }
  /************************************************************/

  ei_copy( eic, _get_m_eulergamma_ptr( n_bits ), n_bits );

  pack( (EMUSHORT *)c, eic, n_bits );

  /* FREE eic ***************/
  __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) );
  /**************************/

} /* End of _m_EULERGAMMA() */


void _m_CATALAN( mpu_real *c, int nb )
{
  EMUSHORT *eic = NULL;
  int       n_bits;
  int       np;

  errno           = 0;
  __real_error_no = 0;

  __CLEAR_RFLAGS;

  n_bits = nb * BITS_PER_BYTE;

  np = internal_np( n_bits );

  /*** Allocate memory for eic . ******************************/
  eic = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eic )
  {
    /* fatal error */
    return;
  }
  /************************************************************/

  ei_copy( eic, _get_m_catalan_ptr( n_bits ), n_bits );

  pack( (EMUSHORT *)c, eic, n_bits );

  /* FREE eic ***************/
  __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) );
  /**************************/

} /* End of _m_CATALAN() */

/**
  END OF ARITHMETIC & MATHEMATIC CONSTANTS.
 ***************************************************************/


void _ind( mpu_real *c, int nb )
/*
  формирует `неопределенность' (- 1.IND)
 ****************************************/
{
  int  n_bits;

  __real_error_no = 0;

  __CLEAR_RFLAGS;

  n_bits = nb * BITS_PER_BYTE;

  e_ind( (EMUSHORT *)c, n_bits );

} /* End of rind() */


int _is_ind( mpu_real *c, int nb )
/*
  проверка на `неопределенность' (- 1.IND)
 ******************************************/
{
  int  ret;
  int  n_bits;

  __real_error_no = 0;

  __CLEAR_RFLAGS;

  n_bits = nb * BITS_PER_BYTE;

  ret = e_isind( (EMUSHORT *)c, n_bits );

  return( ret );

} /* End of _is_ind() */


void _nan( mpu_real *c, unsigned int sign, int nb )
/*
  формирует `не число' (+/- 1.NAN)
  которое не равно nan_max, nan_min и ind.
 ******************************************/
{
  int  n_bits;

  __real_error_no = 0;

  __CLEAR_RFLAGS;

  n_bits = nb * BITS_PER_BYTE;

  e_nan( (EMUSHORT *)c, sign, n_bits );

} /* End of _nan() */


int _is_nans( mpu_real *c, int nb )
/*
  проверка на `не число' (+/- 1.NAN)
  которое не равно              InD.
 ******************************************/
{
  int  ret;
  int  n_bits;

  __real_error_no = 0;

  __CLEAR_RFLAGS;

  n_bits = nb * BITS_PER_BYTE;

  ret = e_isnans( (EMUSHORT *)c, n_bits );

  return( ret );

} /* End of _is_nans() */


void _nan_max( mpu_real *c, unsigned int sign, int nb )
/*
  формирует максимальное `не число' (+/- 1.NAN)
  которое не равно nan_min и ind.
 ***********************************************/
{
  int  n_bits;

  __real_error_no = 0;

  __CLEAR_RFLAGS;

  n_bits = nb * BITS_PER_BYTE;

  e_nanmax( (EMUSHORT *)c, sign, n_bits );

} /* End of _nan_max() */


int _is_nan_max( mpu_real *c, int nb )
/*
  проверка на максимальное `не число' (+/- 1.NAN)
  которое не равно nan_min и ind.
 *************************************************/
{
  int  ret;
  int  n_bits;

  __real_error_no = 0;

  __CLEAR_RFLAGS;

  n_bits = nb * BITS_PER_BYTE;

  ret = e_isnanmax( (EMUSHORT *)c, n_bits );

  return( ret );

} /* End of _is_nan_max() */


void _nan_min( mpu_real *c, unsigned int sign, int nb )
/*
  формирует минимальное `не число' (+/- 1.NAN)
  которое не равно nan_max и ind.
 **********************************************/
{
  int  n_bits;

  __real_error_no = 0;

  __CLEAR_RFLAGS;

  n_bits = nb * BITS_PER_BYTE;

  e_nanmin( (EMUSHORT *)c, sign, n_bits );

} /* End of _nan_min() */


int _is_nan_min( mpu_real *c, int nb )
/*
  проверка на минимальное `не число' (+/- 1.NAN)
  которое не равно nan_max и ind.
 ************************************************/
{
  int  ret;
  int  n_bits;

  __real_error_no = 0;

  __CLEAR_RFLAGS;

  n_bits = nb * BITS_PER_BYTE;

  ret = e_isnanmin( (EMUSHORT *)c, n_bits );

  return( ret );

} /* End of _is_nan_min() */


void _inf( mpu_real *c, unsigned int sign, int nb )
/*
  формирует `бесконечность' (+/- 1.INF)
 ***************************************/
{
  int  n_bits;

  __real_error_no = 0;

  __CLEAR_RFLAGS;

  n_bits = nb * BITS_PER_BYTE;

  e_infin( (EMUSHORT *)c, sign, n_bits );

} /* End of _inf() */


int _is_inf( mpu_real *c, int nb )
/*
  проверка на `бесконечность' (+/- 1.INF)
 *****************************************/
{
  int  ret;
  int  n_bits;

  __real_error_no = 0;

  __CLEAR_RFLAGS;

  n_bits = nb * BITS_PER_BYTE;

  ret = e_isinfin( (EMUSHORT *)c, n_bits );

  return( ret );

} /* End of _is_inf() */


void _real_min( mpu_real *c, unsigned int sign, int nb )
/*
  формирует `минимальное число'.
 ********************************/
{
  int  n_bits;

  __real_error_no = 0;

  __CLEAR_RFLAGS;

  n_bits = nb * BITS_PER_BYTE;

  e_realmin( (EMUSHORT *)c, sign, n_bits );

} /* End of _real_min() */


void _real_max( mpu_real *c, unsigned int sign, int nb )
/*
  формирует `максимальное число'.
 *********************************/
{
  int  n_bits;

  __real_error_no = 0;

  __CLEAR_RFLAGS;

  n_bits = nb * BITS_PER_BYTE;

  e_realmax( (EMUSHORT *)c, sign, n_bits );

} /* End of _real_max() */


void _signull( mpu_real *c, unsigned int sign, int nb )
/*
  формирует `знаковый нуль'.
 ****************************/
{
  int  n_bits;

  __real_error_no = 0;

  __CLEAR_RFLAGS;

  n_bits = nb * BITS_PER_BYTE;

  e_signull( (EMUSHORT *)c, sign, n_bits );

} /* End of _signull() */


int _is_signull( mpu_real *c, int nb )
/*
  проверка на `знаковый нуль'.
 ******************************/
{
  int  ret;
  int  n_bits;

  __real_error_no = 0;

  __CLEAR_RFLAGS;

  n_bits = nb * BITS_PER_BYTE;

  ret = e_issignull( (EMUSHORT *)c, n_bits );

  return( ret );

} /* End of _is_signull() */


void r_neg( mpu_real *c, int nb )
/*
  negate real number.
 *********************/
{
  int  n_bits;

  __real_error_no = 0;

  __CLEAR_RFLAGS;

  n_bits = nb * BITS_PER_BYTE;

  e_neg( (EMUSHORT *)c, n_bits );

} /* End of r_neg() */


int r_is_neg( mpu_real *c, int nb )
/*
  проверка на отрицательное число
  (-0.0 здесь отрицательное число).
 **********************************/
{
  int  ret;
  int  n_bits;

  __real_error_no = 0;

  __CLEAR_RFLAGS;

  n_bits = nb * BITS_PER_BYTE;

  ret = e_isneg( (EMUSHORT *)c, n_bits );

  return( ret );

} /* End of r_is_neg() */


void r_abs( mpu_real *c, int nb )
/*
  сбрасывает знак числа.
 ************************/
{
  int  n_bits;

  __real_error_no = 0;

  __CLEAR_RFLAGS;

  n_bits = nb * BITS_PER_BYTE;

  e_abs( (EMUSHORT *)c, n_bits );

} /* End of r_abs() */


int r_sign( mpu_real *c, int nb )
/*
  if( c  >   0.0 ) return +1;
  if( c  <   0.0 ) return -1;
  if( c == +-0.0 ) return  0;

  if( c == NaNs || c == InD )    return -2;
 ********************************************/
{
  EMUSHORT  *eic = NULL,
           *zero = NULL;

  int       n_bits;
  int       np;
  int       ret = -3;

  errno           = 0;
  __real_error_no = 0;

  __CLEAR_RFLAGS;

  n_bits = nb * BITS_PER_BYTE;

  np = internal_np( n_bits );

  /*** Allocate memory for eic, zero . ************************/
  eic = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eic )
  {
    /* fatal error */
    return( ret );
  }

  zero = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !zero )
  {
    /* fatal error */

    /* FREE eic ***************/
    __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) );
    /**************************/

    return( ret );
  }
  /************************************************************/

  unpack( eic, (EMUSHORT *)c, n_bits );
  _gen_zero( zero, n_bits );

  ret = ei_cmp( eic, zero, n_bits );

  /* FREE eic ***************/
  /* FREE zero **************/
  __mpu_sbrk( -(int)(2*np*SIZE_OF_EMUSHORT) );
  /**************************/

  return( ret );

} /* End of r_sign() */


int r_cmp( mpu_real *a, mpu_real *b, int nb )
/*
  if( a  > b ) return +1;
  if( a  < b ) return -1;
  if( a == b ) return  0;

  if( (a || b) is NaNs || InD )  return -2;
 ********************************************/
{
  EMUSHORT *eia = NULL,
           *eib = NULL;

  int       n_bits;
  int       np;
  int       ret = -3;

  errno           = 0;
  __real_error_no = 0;

  __CLEAR_RFLAGS;

  n_bits = nb * BITS_PER_BYTE;

  np = internal_np( n_bits );

  /*** Allocate memory for eia, eib . *************************/
  eia = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eia )
  {
    /* fatal error */
    return( ret );
  }

  eib = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eib )
  {
    /* fatal error */

    /* FREE eia ***************/
    __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) );
    /**************************/

    return( ret );
  }
  /************************************************************/


  unpack( eia, (EMUSHORT *)a, n_bits );
  unpack( eib, (EMUSHORT *)b, n_bits );

  ret = ei_cmp( eia, eib, n_bits );

  /* FREE eia ***************/
  /* FREE eib ***************/
  __mpu_sbrk( -(int)(2*np*SIZE_OF_EMUSHORT) );
  /**************************/

  return( ret );

} /* End of r_cmp() */


void r_cpy( mpu_real *a, mpu_real *b, int nb )
{
  int  i;

  for( i = 0; i < nb; i++ ) *a++ = *b++;

} /* End of r_cpy() */


void r_cvt( mpu_real *a, mpu_real *b, int nb_a, int nb_b )
/*
  Convert (size type) of real number B to A.
 ********************************************/
{
  EMUSHORT *eia = NULL,
           *eib = NULL;
  int       n_bits_a, n_bits_b;
  int       np_a, np_b;

  errno           = 0;
  __real_error_no = 0;

  __CLEAR_RFLAGS;

  n_bits_a = nb_a * BITS_PER_BYTE;
  n_bits_b = nb_b * BITS_PER_BYTE;

  np_a = internal_np( n_bits_a );
  np_b = internal_np( n_bits_b );

  /*** Allocate memory for eia, eib . *************************/
  eia = (EMUSHORT *)__mpu_sbrk( (int)(np_a*SIZE_OF_EMUSHORT) );
  if( !eia )
  {
    /* fatal error */
    return;
  }

  eib = (EMUSHORT *)__mpu_sbrk( (int)(np_b*SIZE_OF_EMUSHORT) );
  if( !eib )
  {
    /* fatal error */

    /* FREE eia ***************/
    __mpu_sbrk( -(int)(np_a*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }
  /************************************************************/

  unpack( eib, (EMUSHORT *)b, n_bits_b );

  ei_convert( (EMUSHORT *)eia, (EMUSHORT *)eib, n_bits_a, n_bits_b );

  pack( (EMUSHORT *)a, eia, n_bits_a );

  /* FREE eib ***************/
  __mpu_sbrk( -(int)(np_b*SIZE_OF_EMUSHORT) );
  /**************************/
  /* FREE eia ***************/
  __mpu_sbrk( -(int)(np_a*SIZE_OF_EMUSHORT) );
  /**************************/

} /* End of r_cvt() */


void r_add( mpu_real *c, mpu_real *a, mpu_real *b, int nb )
{
  EMUSHORT *eic = NULL,
           *eia = NULL,
           *eib = NULL;
  int       n_bits;
  int       np;

  errno           = 0;
  __real_error_no = 0;

  __CLEAR_RFLAGS;

  n_bits = nb * BITS_PER_BYTE;

  np = internal_np( n_bits );

  /*** Allocate memory for eic, eia, eib . ********************/
  eic = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eic )
  {
    /* fatal error */
    return;
  }

  eia = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eia )
  {
    /* fatal error */

    /* FREE eic ***************/
    __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }

  eib = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eib )
  {
    /* fatal error */

    /* FREE eic ***************/
    /* FREE eia ***************/
    __mpu_sbrk( -(int)(2*np*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }
  /************************************************************/

  unpack( eia, (EMUSHORT *)a, n_bits );
  unpack( eib, (EMUSHORT *)b, n_bits );

  ei_add( eic, eia, eib, n_bits );

  pack( (EMUSHORT *)c, eic, n_bits );

  /* FREE eic ***************/
  /* FREE eia ***************/
  /* FREE eib ***************/
  __mpu_sbrk( -(int)(3*np*SIZE_OF_EMUSHORT) );
  /**************************/

} /* End of r_add() */


void r_sub( mpu_real *c, mpu_real *a, mpu_real *b, int nb )
{
  EMUSHORT *eic = NULL,
           *eia = NULL,
           *eib = NULL;
  int       n_bits;
  int       np;

  errno           = 0;
  __real_error_no = 0;

  __CLEAR_RFLAGS;

  n_bits = nb * BITS_PER_BYTE;

  np = internal_np( n_bits );

  /*** Allocate memory for eic, eia, eib . ********************/
  eic = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eic )
  {
    /* fatal error */
    return;
  }

  eia = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eia )
  {
    /* fatal error */

    /* FREE eic ***************/
    __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }

  eib = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eib )
  {
    /* fatal error */

    /* FREE eic ***************/
    /* FREE eia ***************/
    __mpu_sbrk( -(int)(2*np*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }
  /************************************************************/

  unpack( eia, (EMUSHORT *)a, n_bits );
  unpack( eib, (EMUSHORT *)b, n_bits );

  ei_sub( eic, eia, eib, n_bits );

  pack( (EMUSHORT *)c, eic, n_bits );

  /* FREE eic ***************/
  /* FREE eia ***************/
  /* FREE eib ***************/
  __mpu_sbrk( -(int)(3*np*SIZE_OF_EMUSHORT) );
  /**************************/

} /* End of r_sub() */


void r_mul( mpu_real *c, mpu_real *a, mpu_real *b, int nb )
{
  EMUSHORT *eic = NULL,
           *eia = NULL,
           *eib = NULL;
  int       n_bits;
  int       np;

  errno           = 0;
  __real_error_no = 0;

  __CLEAR_RFLAGS;

  n_bits = nb * BITS_PER_BYTE;

  np = internal_np( n_bits );

  /*** Allocate memory for eic, eia, eib . ********************/
  eic = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eic )
  {
    /* fatal error */
    return;
  }

  eia = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eia )
  {
    /* fatal error */

    /* FREE eic ***************/
    __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }

  eib = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eib )
  {
    /* fatal error */

    /* FREE eic ***************/
    /* FREE eia ***************/
    __mpu_sbrk( -(int)(2*np*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }
  /************************************************************/

  unpack( eia, (EMUSHORT *)a, n_bits );
  unpack( eib, (EMUSHORT *)b, n_bits );

  ei_mul( eic, eia, eib, n_bits );

  pack( (EMUSHORT *)c, eic, n_bits );

  /* FREE eic ***************/
  /* FREE eia ***************/
  /* FREE eib ***************/
  __mpu_sbrk( -(int)(3*np*SIZE_OF_EMUSHORT) );
  /**************************/

} /* End of r_mul() */


void r_div( mpu_real *c, mpu_real *a, mpu_real *b, int nb )
{
  EMUSHORT *eic = NULL,
           *eia = NULL,
           *eib = NULL;
  int       n_bits;
  int       np;

  errno           = 0;
  __real_error_no = 0;

  __CLEAR_RFLAGS;

  n_bits = nb * BITS_PER_BYTE;

  np = internal_np( n_bits );

  /*** Allocate memory for eic, eia, eib . ********************/
  eic = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eic )
  {
    /* fatal error */
    return;
  }

  eia = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eia )
  {
    /* fatal error */

    /* FREE eic ***************/
    __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }

  eib = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eib )
  {
    /* fatal error */

    /* FREE eic ***************/
    /* FREE eia ***************/
    __mpu_sbrk( -(int)(2*np*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }
  /************************************************************/


  unpack( eia, (EMUSHORT *)a, n_bits );
  unpack( eib, (EMUSHORT *)b, n_bits );

  ei_div( eic, eia, eib, n_bits );

  pack( (EMUSHORT *)c, eic, n_bits );

  /* FREE eic ***************/
  /* FREE eia ***************/
  /* FREE eib ***************/
  __mpu_sbrk( -(int)(3*np*SIZE_OF_EMUSHORT) );
  /**************************/

} /* End of r_div() */


void ltor( mpu_real *r, mpu_int *l, int nb_r, int nb_l )
/*
  Convert long integer number L to real number R.
 *************************************************************/
{
  EMUSHORT *eir = NULL,
           *p_l = NULL; /* save *l */
  int       n_bits, n_parts, bytes_in_emushort;
  int       n_bits_target;
  int       np;


  errno           = 0;
  __real_error_no = 0;

  __CLEAR_RFLAGS;

  bytes_in_emushort = (SIZE_OF_EMUSHORT);
  n_parts           = nb_l / bytes_in_emushort + 1;
  n_bits_target     = nb_r * BITS_PER_BYTE;
  /******************************************************
    Берем размер в 2 раза больший, так как для ei_ltor()
    необходимо, чтобы размер целого был меньше мантиссы
    вещественного.
   ******************************************************/
  if( nb_r == nb_l ) 
    n_bits = nb_r * BITS_PER_BYTE * 2;
  else if( nb_r < nb_l )
    n_bits = nb_l * BITS_PER_BYTE * 2;
  else
    n_bits = n_bits_target;

  np = internal_np( n_bits );

  /*** Allocate memory for eir, p_l . *************************/
  eir = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eir )
  {
    /* fatal error */
    return;
  }

  p_l = (EMUSHORT *)__mpu_sbrk( (int)(n_parts*SIZE_OF_EMUSHORT) );
  if( !p_l )
  {
    /* fatal error */

    /* FREE eir ***************/
    __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }
  /************************************************************/

  /***********************************************
    Операция преобразования (convert) данных CVT.
    Воздействует на флаги: OF, PF, SF, ZF.
    Флаги CF, AF не изменяются.
   ***********************************************/
  icvt( (mpu_int *)p_l, l, n_parts*bytes_in_emushort, nb_l );

  ei_ltor( eir, p_l, n_bits, n_parts );

  /******************************************************
    Возвращаем оригинальный размер цели
   ******************************************************/
  if( n_bits != n_bits_target )
    ei_convert( eir, eir, n_bits_target, n_bits );

  pack( (EMUSHORT *)r, eir, n_bits_target );

  /* FREE p_l ***************/
  __mpu_sbrk( -(int)(n_parts*SIZE_OF_EMUSHORT) );
  /**************************/
  /* FREE eir ***************/
  __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) );
  /**************************/

} /* End of ltor() */


void ultor( mpu_real *r, mpu_int *l, int nb_r, int nb_l )
/*
  Convert long integer number L to real number R.
 ***************************************************************/
{
  EMUSHORT *eir = NULL,
           *p_l = NULL; /* save *l */
  int       n_bits, n_parts, bytes_in_emushort;
  int       n_bits_target;
  int       np;

  errno           = 0;
  __real_error_no = 0;

  __CLEAR_RFLAGS;

  bytes_in_emushort = (SIZE_OF_EMUSHORT);
  n_parts           = nb_l / bytes_in_emushort + 1;
  n_bits_target     = nb_r * BITS_PER_BYTE;
  /******************************************************
    Берем размер в 2 раза больший, так как для ei_ltor()
    необходимо, чтобы размер целого был меньше мантиссы
    вещественного.
   ******************************************************/
  if( nb_r == nb_l ) 
    n_bits = nb_r * BITS_PER_BYTE * 2;
  else if( nb_r < nb_l )
    n_bits = nb_l * BITS_PER_BYTE * 2;
  else
    n_bits = n_bits_target;

  np = internal_np( n_bits );

  /*** Allocate memory for eir, p_l . *************************/
  eir = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eir )
  {
    /* fatal error */
    return;
  }

  p_l = (EMUSHORT *)__mpu_sbrk( (int)(n_parts*SIZE_OF_EMUSHORT) );
  if( !p_l )
  {
    /* fatal error */

    /* FREE eir ***************/
    __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }
  /************************************************************/

  /***********************************************
    Операция преобразования (convert) данных CVT.
    Воздействует на флаги: OF, PF, SF, ZF.
    Флаги CF, AF не изменяются.
   ***********************************************/
  icvt( (mpu_int *)p_l, l, n_parts*bytes_in_emushort, nb_l );

  ei_ultor( eir, p_l, n_bits, n_parts );

  /******************************************************
    Возвращаем оригинальный размер цели
   ******************************************************/
  if( n_bits != n_bits_target )
    ei_convert( eir, eir, n_bits_target, n_bits );

  pack( (EMUSHORT *)r, eir, n_bits_target );

  /* FREE p_l ***************/
  __mpu_sbrk( -(int)(n_parts*SIZE_OF_EMUSHORT) );
  /**************************/
  /* FREE eir ***************/
  __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) );
  /**************************/

} /* End of ultor() */



void rtol_frac( mpu_int *l, mpu_real *frac, mpu_real *r, int nb_l, int nb_r )
/*
  Convert real number R to long integer number L
  and find floating point fractional part *FRAC.
  FRAC my be NULL.
 ************************************************/
{
  EMUSHORT *eir = NULL,
           *p_f = NULL,
           *p_l = NULL; /* save *l */
  int       n_bits, n_parts, bytes_in_emushort;
  int       np;

  errno           = 0;
  __real_error_no = 0;

  __CLEAR_RFLAGS;

  bytes_in_emushort = (SIZE_OF_EMUSHORT);
  n_parts           = nb_l / bytes_in_emushort + 1;
  n_bits            = nb_r * BITS_PER_BYTE;

  np = internal_np( n_bits );

  /*** Allocate memory for eir, p_f, p_l . ********************/
  eir = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eir )
  {
    /* fatal error */
    return;
  }

  p_f = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !p_f )
  {
    /* fatal error */

    /* FREE eir ***************/
    __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }

  p_l = (EMUSHORT *)__mpu_sbrk( (int)(n_parts*SIZE_OF_EMUSHORT) );
  if( !p_l )
  {
    /* fatal error */

    /* FREE eir ***************/
    /* FREE p_f ***************/
    __mpu_sbrk( -(int)(2*np*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }
  /************************************************************/

  unpack( eir, (EMUSHORT *)r, n_bits );

  if( frac )
    ei_rtol_frac( p_l, p_f, eir, n_parts, n_bits );
  else
    ei_rtol_frac( p_l, (EMUSHORT *)0, eir, n_parts, n_bits );

  /***************************************************************
    Операция преобразования (convert) данных CVT.
    Воздействует на флаги: OF, PF, SF, ZF.  Флаги CF, AF не изменяются.
   ***************************************************************/
  icvt( l, (mpu_int *)p_l, nb_l, n_parts*bytes_in_emushort );

  if( frac ) pack( (EMUSHORT *)frac, p_f, n_bits );

  /* FREE p_l ***************/
  __mpu_sbrk( -(int)(n_parts*SIZE_OF_EMUSHORT) );
  /**************************/

  /* FREE eir ***************/
  /* FREE p_f ***************/
  __mpu_sbrk( -(int)(2*np*SIZE_OF_EMUSHORT) );
  /**************************/

} /* End of rtol_frac() */


void rtoul_frac( mpu_int *l, mpu_real *frac, mpu_real *r, int nb_l, int nb_r )
/*
  Convert real number R to UNSIGNED long integer number L
  and find floating point fractional part *FRAC.
  FRAC my be NULL.
 *********************************************************/
{
  EMUSHORT *eir = NULL,
           *p_f = NULL,
           *p_l = NULL; /* save *l */
  int       n_bits, n_parts, bytes_in_emushort;
  int       np;

  errno           = 0;
  __real_error_no = 0;

  __CLEAR_RFLAGS;

  bytes_in_emushort = (SIZE_OF_EMUSHORT);
  n_parts           = nb_l / bytes_in_emushort + 1;
  n_bits            = nb_r * BITS_PER_BYTE;

  np = internal_np( n_bits );

  /*** Allocate memory for eir, p_f, p_l . ********************/
  eir = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eir )
  {
    /* fatal error */
    return;
  }

  p_f = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !p_f )
  {
    /* fatal error */

    /* FREE eir ***************/
    __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }

  p_l = (EMUSHORT *)__mpu_sbrk( (int)(n_parts*SIZE_OF_EMUSHORT) );
  if( !p_l )
  {
    /* fatal error */

    /* FREE eir ***************/
    /* FREE p_f ***************/
    __mpu_sbrk( -(int)(2*np*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }
  /************************************************************/

  unpack( eir, (EMUSHORT *)r, n_bits );

  if( frac )
    ei_rtoul_frac( p_l, p_f, eir, n_parts, n_bits );
  else
    ei_rtoul_frac( p_l, (EMUSHORT *)0, eir, n_parts, n_bits );

  /***************************************************************
    Операция преобразования (convert) данных CVT.
    Воздействует на флаги: OF, PF, SF, ZF.  Флаги CF, AF не изменяются.
   ***************************************************************/
  icvt( l, (mpu_int *)p_l, nb_l, n_parts*bytes_in_emushort );

  if( frac ) pack( (EMUSHORT *)frac, p_f, n_bits );

  /* FREE p_l ***************/
  __mpu_sbrk( -(int)(n_parts*SIZE_OF_EMUSHORT) );
  /**************************/

  /* FREE eir ***************/
  /* FREE p_f ***************/
  __mpu_sbrk( -(int)(2*np*SIZE_OF_EMUSHORT) );
  /**************************/

} /* End of rtoul_frac() */


void r_remain( mpu_real *r, mpu_real *a, mpu_real *b, int nb )
/*
  R = remainder after dividing A by B.
  Sign of remainder == Sign of quotient.
 *****************************************/
{
  EMUSHORT *eir = NULL,
           *eia = NULL,
           *eib = NULL;
  int       n_bits;
  int       np;

  errno           = 0;
  __real_error_no = 0;

  __CLEAR_RFLAGS;

  n_bits = nb * BITS_PER_BYTE;

  np = internal_np( n_bits );

  /*** Allocate memory for eir, eia, eib . ********************/
  eir = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eir )
  {
    /* fatal error */
    return;
  }

  eia = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eia )
  {
    /* fatal error */

    /* FREE eir ***************/
    __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }

  eib = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eib )
  {
    /* fatal error */

    /* FREE eir ***************/
    /* FREE eia ***************/
    __mpu_sbrk( -(int)(2*np*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }
  /************************************************************/

  unpack( eia, (EMUSHORT *)a, n_bits );
  unpack( eib, (EMUSHORT *)b, n_bits );

  ei_remain( eir, (EMUSHORT *)0, eia, eib, n_bits );

  pack( (EMUSHORT *)r, eir, n_bits );

  /* FREE eir ***************/
  /* FREE eia ***************/
  /* FREE eib ***************/
  __mpu_sbrk( -(int)(3*np*SIZE_OF_EMUSHORT) );
  /**************************/

} /* End of r_remain() */


void r_floor( mpu_real *c, mpu_real *a, int nb )
/*
  Return C = largest integer not greater
  than A (truncated toward minus infinity).
  Возвращает C = наиболшее (ближайшее) целое
  не большее чем A (срезает в сторону
  минус бесконечности).
 ********************************************/
{
  EMUSHORT *eic = NULL,
           *eia = NULL;
  int       n_bits;
  int       np;

  errno           = 0;
  __real_error_no = 0;

  __CLEAR_RFLAGS;

  n_bits = nb * BITS_PER_BYTE;

  np = internal_np( n_bits );

  /*** Allocate memory for eic, eia . *************************/
  eic = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eic )
  {
    /* fatal error */
    return;
  }

  eia = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eia )
  {
    /* fatal error */

    /* FREE eic ***************/
    __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }
  /************************************************************/

  unpack( eia, (EMUSHORT *)a, n_bits );

  ei_floor( eic, eia, n_bits );

  pack( (EMUSHORT *)c, eic, n_bits );

  /* FREE eic ***************/
  /* FREE eia ***************/
  __mpu_sbrk( -(int)(2*np*SIZE_OF_EMUSHORT) );
  /**************************/

} /* End of r_floor() */


void r_ceil( mpu_real *c, mpu_real *a, int nb )
/*
  Return C = neargest integer not smaller
  than A (truncated toward plus infinity).
  Возвращает C = наименьшее (ближайшее) целое
  не меньшее чем A (срезает в сторону
  плюс бесконечности).
 **********************************************/
{
  EMUSHORT *eic = NULL,
           *eia = NULL;
  int       n_bits;
  int       np;

  errno           = 0;
  __real_error_no = 0;

  __CLEAR_RFLAGS;

  n_bits = nb * BITS_PER_BYTE;

  np = internal_np( n_bits );

  /*** Allocate memory for eic, eia . *************************/
  eic = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eic )
  {
    /* fatal error */
    return;
  }

  eia = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eia )
  {
    /* fatal error */

    /* FREE eic ***************/
    __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }
  /************************************************************/

  unpack( eia, (EMUSHORT *)a, n_bits );

  ei_ceil( eic, eia, n_bits );

  pack( (EMUSHORT *)c, eic, n_bits );

  /* FREE eic ***************/
  /* FREE eia ***************/
  __mpu_sbrk( -(int)(2*np*SIZE_OF_EMUSHORT) );
  /**************************/

} /* End of r_ceil() */


void r_round( mpu_real *c, mpu_real *a, int nb )
/*
  Return C = nearest integer to A, as FLOOR( A + 0.5 ).
 *******************************************************/
{
  EMUSHORT *eic = NULL,
           *eia = NULL;
  int       n_bits;
  int       np;

  errno           = 0;
  __real_error_no = 0;

  __CLEAR_RFLAGS;

  n_bits = nb * BITS_PER_BYTE;

  np = internal_np( n_bits );

  /*** Allocate memory for eic, eia . *************************/
  eic = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eic )
  {
    /* fatal error */
    return;
  }

  eia = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eia )
  {
    /* fatal error */

    /* FREE eic ***************/
    __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }
  /************************************************************/

  unpack( eia, (EMUSHORT *)a, n_bits );

  ei_round( eic, eia, n_bits );

  pack( (EMUSHORT *)c, eic, n_bits );

  /* FREE eic ***************/
  /* FREE eia ***************/
  __mpu_sbrk( -(int)(2*np*SIZE_OF_EMUSHORT) );
  /**************************/

} /* End of r_round() */


void r_frexp( mpu_real *s, mpu_int *lexp, mpu_real *r, int nb_l, int nb_r )
/*
  Return S and LEXP such that
  S * 2^LEXP = R and 0.5 <= S < 1.0.
  For example, 1.1 = 0.55 * 2^1.
  ================================================
  Функция разбивает число R на мантиссу S и
  експоненту LEXP таким образом, что абсолютное
  значение S больше или равно 0.5 и меньше 1.0
  и R == S * 2^LEXP.
  Например, 1.1 = 0.55 * 2^1.
  ================================================
  NOTE:
  sizeof( lexp ) >= _sizeof_exp( unsigned nb_r ).
 **************************************************/
{
  EMUSHORT *eir = NULL,
           *p_s = NULL,
           *p_l = NULL;
  int       n_bits, n_parts, bytes_in_emushort;
  int       np;

  errno           = 0;
  __real_error_no = 0;

  __CLEAR_RFLAGS;

  bytes_in_emushort = (SIZE_OF_EMUSHORT);
  n_parts           = nb_l / bytes_in_emushort + 1;
  n_bits            = nb_r * BITS_PER_BYTE;

  np = internal_np( n_bits );

  /*** Allocate memory for eir, p_s, p_l . ********************/
  eir = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eir )
  {
    /* fatal error */
    return;
  }

  p_s = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !p_s )
  {
    /* fatal error */

    /* FREE eir ***************/
    __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }

  p_l = (EMUSHORT *)__mpu_sbrk( (int)(n_parts*SIZE_OF_EMUSHORT) );
  if( !p_l )
  {
    /* fatal error */

    /* FREE eir ***************/
    /* FREE p_s ***************/
    __mpu_sbrk( -(int)(2*np*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }
  /************************************************************/

  unpack( eir, (EMUSHORT *)r, n_bits );

  ei_frexp( p_s, p_l, eir, n_parts, n_bits );

  /***************************************************************
    Операция преобразования (convert) данных CVT.
    Воздействует на флаги: OF, PF, SF, ZF.  Флаги CF, AF не изменяются.
   ***************************************************************/
  icvt( lexp, (mpu_int *)p_l, nb_l, n_parts*bytes_in_emushort );

  pack( (EMUSHORT *)s, p_s, n_bits );

  /* FREE p_l ***************/
  __mpu_sbrk( -(int)(n_parts*SIZE_OF_EMUSHORT) );
  /**************************/

  /* FREE eir ***************/
  /* FREE p_s ***************/
  __mpu_sbrk( -(int)(2*np*SIZE_OF_EMUSHORT) );
  /**************************/

} /* End of r_frexp() */


void r_ldexp( mpu_real *c, mpu_real *r, mpu_int *lpwr2, int nb_r, int nb_l )
/*
  Return C = R * 2^PWR2.
  =====================================================
  Функция вычисляет значение C как
  R умноженное на 2 в степени LPWR2.
  =====================================================
  NOTE:
  sizeof( lpwr2 ) <= _sizeof_exp( unsigned nb_r ) + 1.
 *******************************************************/
{
  EMUSHORT *eir = NULL,
           *p_c = NULL,
           *p_l = NULL;
  int       n_bits, n_parts, bytes_in_emushort;
  int       np;

  errno           = 0;
  __real_error_no = 0;

  __CLEAR_RFLAGS;

  bytes_in_emushort = (SIZE_OF_EMUSHORT);
  n_parts           = nb_l / bytes_in_emushort + 1;
  n_bits            = nb_r * BITS_PER_BYTE;

  np = internal_np( n_bits );

  /*** Allocate memory for eir, p_c, p_l . ********************/
  eir = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eir )
  {
    /* fatal error */
    return;
  }

  p_c = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !p_c )
  {
    /* fatal error */

    /* FREE eir ***************/
    __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }

  p_l = (EMUSHORT *)__mpu_sbrk( (int)(n_parts*SIZE_OF_EMUSHORT) );
  if( !p_l )
  {
    /* fatal error */

    /* FREE eir ***************/
    /* FREE p_c ***************/
    __mpu_sbrk( -(int)(2*np*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }
  /************************************************************/

  unpack( eir, (EMUSHORT *)r, n_bits );
  /***************************************************************
    Операция преобразования (convert) данных CVT.
    Воздействует на флаги: OF, PF, SF, ZF.  Флаги CF, AF не изменяются.
   ***************************************************************/
  icvt( (mpu_int *)p_l, lpwr2, n_parts*bytes_in_emushort, nb_l );

  ei_ldexp( p_c, p_l, eir, n_parts, n_bits );

  pack( (EMUSHORT *)c, p_c, n_bits );

  /* FREE p_l ***************/
  __mpu_sbrk( -(int)(n_parts*SIZE_OF_EMUSHORT) );
  /**************************/

  /* FREE eir ***************/
  /* FREE p_c ***************/
  __mpu_sbrk( -(int)(2*np*SIZE_OF_EMUSHORT) );
  /**************************/

} /* End of r_ldexp() */


void r_logb( mpu_int *lbase2, mpu_real *r, int nb_l, int nb_r )
/*
  Return Lbase2 = the base 2 signed integral
  Exponent of R.
  ================================================
  Функция вычисляет значение Lbase2 как
  знаковую интегральную экспоненту по основанию 2
  вещественного числа R.
  ================================================
  NOTE:
   sizeof( lexp ) >= _sizeof_exp( unsigned nb_r ).
 **************************************************/
{
  EMUSHORT *eir = NULL,
           *p_l = NULL;
  int       n_bits, n_parts, bytes_in_emushort;
  int       np;

  errno           = 0;
  __real_error_no = 0;

  __CLEAR_RFLAGS;

  bytes_in_emushort = (SIZE_OF_EMUSHORT);
  n_parts           = nb_l / bytes_in_emushort + 1;
  n_bits            = nb_r * BITS_PER_BYTE;

  np = internal_np( n_bits );

  /*** Allocate memory for eir, p_l . *************************/
  eir = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eir )
  {
     /* fatal error */
     return;
  }

  p_l = (EMUSHORT *)__mpu_sbrk( (int)(n_parts*SIZE_OF_EMUSHORT) );
  if( !p_l )
  {
    /* fatal error */

    /* FREE eir ***************/
    __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }
  /************************************************************/

  unpack( eir, (EMUSHORT *)r, n_bits );

  ei_logb( p_l, eir, n_parts, n_bits );

  /***************************************************************
    Операция преобразования (convert) данных CVT.
    Воздействует на флаги: OF, PF, SF, ZF.  Флаги CF, AF не изменяются.
   ***************************************************************/
  icvt( lbase2, (mpu_int *)p_l, nb_l, n_parts*bytes_in_emushort );

  /* FREE p_l ***************/
  __mpu_sbrk( -(int)(n_parts*SIZE_OF_EMUSHORT) );
  /**************************/
  /* FREE eir ***************/
  __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) );
  /**************************/

} /* End of r_logb() */


void r_modf( mpu_real *fract, mpu_real *integer, mpu_real *r, int nb )
/*
  Returns fractional part of R (in *FRACT) (with sign of R),
  stores integer part in *INTEGER (as real number).
  ===============================================================
  Функция вычисляет дробную и целую части числа R.
  ===============================================================
 *****************************************************************/
{
  EMUSHORT  *eir = NULL,
            *eif = NULL,
            *eii = NULL,
           *zero = NULL;
  int       n_bits;
  int       np;

  errno           = 0;
  __real_error_no = 0;

  __CLEAR_RFLAGS;

  n_bits = nb * BITS_PER_BYTE;

  np = internal_np( n_bits );

  /*** Allocate memory for eir, eif, eii, zero . **************/
  eir = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eir )
  {
    /* fatal error */
    return;
  }

  eif = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eif )
  {
    /* fatal error */

    /* FREE eir ***************/
    __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }

  eii = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eii )
  {
    /* fatal error */

    /* FREE eir ***************/
    /* FREE eif ***************/
    __mpu_sbrk( -(int)(2*np*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }

  zero = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !zero )
  {
    /* fatal error */

    /* FREE eir ***************/
    /* FREE eif ***************/
    /* FREE eii ***************/
    __mpu_sbrk( -(int)(3*np*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }
  /************************************************************/

  _gen_zero( zero, n_bits );

  unpack( eir, (EMUSHORT *)r, n_bits );

  ei_copy( eif, eir, n_bits ); 
  ei_abs( eif, n_bits );           /* eif = abs( eir );   */

  ei_floor( eii, eif, n_bits );    /* eii = floor( eif ); */

  ei_sub( eif, eif, eii, n_bits ); /* eif -= eii;         */

  if( ei_cmp( eir, zero, n_bits ) < 0 )  /* if( eir < 0 ) */
  {
    ei_neg( eii, n_bits ); /* eii = -eii; */
    ei_neg( eif, n_bits ); /* eif = -eif; */
  }

  pack( (EMUSHORT *)fract,   eif, n_bits );
  pack( (EMUSHORT *)integer, eii, n_bits );

  /* FREE eir ***************/
  /* FREE eif ***************/
  /* FREE eii ***************/
  /* FREE zero **************/
  __mpu_sbrk( -(int)(4*np*SIZE_OF_EMUSHORT) );
  /**************************/

} /* End of r_modf() */


/***************************************************************
                   REAL MATHEMATIC OPERATIONS
 ***************************************************************/

void r_sqrt( mpu_real *c, mpu_real *a, int nb )
/*
  Longhand SQUARE ROOT routine.
 *******************************/
{
  EMUSHORT *eic = NULL,
           *eia = NULL;
  int       n_bits;
  int       np;

  errno           = 0;
  __real_error_no = 0;

  __CLEAR_RFLAGS;

  n_bits = nb * BITS_PER_BYTE;

  np = internal_np( n_bits );

  /*** Allocate memory for eic, eia . *************************/
  eic = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eic )
  {
    /* fatal error */
    return;
  }

  eia = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eia )
  {
    /* fatal error */

    /* FREE eic ***************/
    __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }
  /************************************************************/

  unpack( eia, (EMUSHORT *)a, n_bits );

  ei_sqrt( eic, eia, n_bits );

  pack( (EMUSHORT *)c, eic, n_bits );

  /* FREE eic ***************/
  /* FREE eia ***************/
  __mpu_sbrk( -(int)(2*np*SIZE_OF_EMUSHORT) );
  /**************************/

} /* End of r_sqrt() */


/***************************************************************
  BEGIN: __MPU_MATH.H
 **/

void r_sin( mpu_real *y, mpu_real *x, int nb )
/*
 *******************************/
{
  EMUSHORT *eiy = NULL,
           *eix = NULL;
  int       n_bits;
  int       np;

  errno           = 0;
  __real_error_no = 0;

  __CLEAR_RFLAGS;

  n_bits = nb * BITS_PER_BYTE;

  np = internal_np( n_bits );

  /*** Allocate memory for eiy, eix . *************************/
  eiy = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eiy )
  {
    /* fatal error */
    return;
  }

  eix = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eix )
  {
    /* fatal error */

    /* FREE eiy ***************/
    __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }
  /************************************************************/

  unpack( eix, (EMUSHORT *)x, n_bits );

  ei_sin( eiy, eix, n_bits );

  pack( (EMUSHORT *)y, eiy, n_bits );

  /* FREE eix ***************/
  /* FREE eiy ***************/
  __mpu_sbrk( -(int)(2*np*SIZE_OF_EMUSHORT) );
  /**************************/

} /* End of r_sin() */


void r_cos( mpu_real *y, mpu_real *x, int nb )
/*
 *******************************/
{
  EMUSHORT *eiy = NULL,
           *eix = NULL;
  int       n_bits;
  int       np;

  errno           = 0;
  __real_error_no = 0;

  __CLEAR_RFLAGS;

  n_bits = nb * BITS_PER_BYTE;

  np = internal_np( n_bits );

  /*** Allocate memory for eiy, eix . *************************/
  eiy = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eiy )
  {
    /* fatal error */
    return;
  }

  eix = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eix )
  {
    /* fatal error */

    /* FREE eiy ***************/
    __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }
  /************************************************************/

  unpack( eix, (EMUSHORT *)x, n_bits );

  ei_cos( eiy, eix, n_bits );

  pack( (EMUSHORT *)y, eiy, n_bits );

  /* FREE eix ***************/
  /* FREE eiy ***************/
  __mpu_sbrk( -(int)(2*np*SIZE_OF_EMUSHORT) );
  /**************************/

} /* End of r_cos() */


void r_tan( mpu_real *y, mpu_real *x, int nb )
/*
 *******************************/
{
  EMUSHORT *eiy = NULL,
           *eix = NULL;
  int       n_bits;
  int       np;

  errno           = 0;
  __real_error_no = 0;

  __CLEAR_RFLAGS;

  n_bits = nb * BITS_PER_BYTE;

  np = internal_np( n_bits );

  /*** Allocate memory for eiy, eix . *************************/
  eiy = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eiy )
  {
    /* fatal error */
    return;
  }

  eix = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eix )
  {
    /* fatal error */

    /* FREE eiy ***************/
    __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }
  /************************************************************/

  unpack( eix, (EMUSHORT *)x, n_bits );

  ei_tan( eiy, eix, n_bits );

  pack( (EMUSHORT *)y, eiy, n_bits );

  /* FREE eix ***************/
  /* FREE eiy ***************/
  __mpu_sbrk( -(int)(2*np*SIZE_OF_EMUSHORT) );
  /**************************/

} /* End of r_tan() */


void r_log1p( mpu_real *y, mpu_real *x, int nb )
/*
 *******************************/
{
  EMUSHORT *eiy = NULL,
           *eix = NULL;
  int       n_bits;
  int       np;

  errno           = 0;
  __real_error_no = 0;

  __CLEAR_RFLAGS;

  n_bits = nb * BITS_PER_BYTE;

  np = internal_np( n_bits );

  /*** Allocate memory for eiy, eix . *************************/
  eiy = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eiy )
  {
    /* fatal error */
    return;
  }

  eix = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eix )
  {
    /* fatal error */

    /* FREE eiy ***************/
    __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }
  /************************************************************/

  unpack( eix, (EMUSHORT *)x, n_bits );

  ei_log1p( eiy, eix, n_bits );

  pack( (EMUSHORT *)y, eiy, n_bits );

  /* FREE eix ***************/
  /* FREE eiy ***************/
  __mpu_sbrk( -(int)(2*np*SIZE_OF_EMUSHORT) );
  /**************************/

} /* End of r_log1p() */


void r_log( mpu_real *y, mpu_real *x, int nb )
/*
 *******************************/
{
  EMUSHORT *eiy = NULL,
           *eix = NULL;
  int       n_bits;
  int       np;

  errno           = 0;
  __real_error_no = 0;

  __CLEAR_RFLAGS;

  n_bits = nb * BITS_PER_BYTE;

  np = internal_np( n_bits );

  /*** Allocate memory for eiy, eix . *************************/
  eiy = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eiy )
  {
    /* fatal error */
    return;
  }

  eix = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eix )
  {
    /* fatal error */

    /* FREE eiy ***************/
    __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }
  /************************************************************/

  unpack( eix, (EMUSHORT *)x, n_bits );

  ei_log( eiy, eix, n_bits );

  pack( (EMUSHORT *)y, eiy, n_bits );

  /* FREE eix ***************/
  /* FREE eiy ***************/
  __mpu_sbrk( -(int)(2*np*SIZE_OF_EMUSHORT) );
  /**************************/

} /* End of r_log() */


void r_log10( mpu_real *y, mpu_real *x, int nb )
/*
 *******************************/
{
  EMUSHORT *eiy = NULL,
           *eix = NULL;
  int       n_bits;
  int       np;

  errno           = 0;
  __real_error_no = 0;

  __CLEAR_RFLAGS;

  n_bits = nb * BITS_PER_BYTE;

  np = internal_np( n_bits );

  /*** Allocate memory for eiy, eix . *************************/
  eiy = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eiy )
  {
    /* fatal error */
    return;
  }

  eix = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eix )
  {
    /* fatal error */

    /* FREE eiy ***************/
    __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }
  /************************************************************/

  unpack( eix, (EMUSHORT *)x, n_bits );

  ei_log10( eiy, eix, n_bits );

  pack( (EMUSHORT *)y, eiy, n_bits );

  /* FREE eix ***************/
  /* FREE eiy ***************/
  __mpu_sbrk( -(int)(2*np*SIZE_OF_EMUSHORT) );
  /**************************/

} /* End of r_log10() */


void r_log2( mpu_real *y, mpu_real *x, int nb )
/*
 *******************************/
{
  EMUSHORT *eiy = NULL,
           *eix = NULL;
  int       n_bits;
  int       np;

  errno           = 0;
  __real_error_no = 0;

  __CLEAR_RFLAGS;

  n_bits = nb * BITS_PER_BYTE;

  np = internal_np( n_bits );

  /*** Allocate memory for eiy, eix . *************************/
  eiy = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eiy )
  {
    /* fatal error */
    return;
  }

  eix = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eix )
  {
    /* fatal error */

    /* FREE eiy ***************/
    __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }
  /************************************************************/

  unpack( eix, (EMUSHORT *)x, n_bits );

  ei_log2( eiy, eix, n_bits );

  pack( (EMUSHORT *)y, eiy, n_bits );

  /* FREE eix ***************/
  /* FREE eiy ***************/
  __mpu_sbrk( -(int)(2*np*SIZE_OF_EMUSHORT) );
  /**************************/

} /* End of r_log2() */


void r_expm1( mpu_real *y, mpu_real *x, int nb )
/*
 *******************************/
{
  EMUSHORT *eiy = NULL,
           *eix = NULL;
  int       n_bits;
  int       np;

  errno           = 0;
  __real_error_no = 0;

  __CLEAR_RFLAGS;

  n_bits = nb * BITS_PER_BYTE;

  np = internal_np( n_bits );

  /*** Allocate memory for eiy, eix . *************************/
  eiy = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eiy )
  {
    /* fatal error */
    return;
  }

  eix = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eix )
  {
    /* fatal error */

    /* FREE eiy ***************/
    __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }
  /************************************************************/

  unpack( eix, (EMUSHORT *)x, n_bits );

  ei_expm1( eiy, eix, n_bits );

  pack( (EMUSHORT *)y, eiy, n_bits );

  /* FREE eix ***************/
  /* FREE eiy ***************/
  __mpu_sbrk( -(int)(2*np*SIZE_OF_EMUSHORT) );
  /**************************/

} /* End of r_expm1() */


void r_exp( mpu_real *y, mpu_real *x, int nb )
/*
 *******************************/
{
  EMUSHORT *eiy = NULL,
           *eix = NULL;
  int       n_bits;
  int       np;

  errno           = 0;
  __real_error_no = 0;

  __CLEAR_RFLAGS;

  n_bits = nb * BITS_PER_BYTE;

  np = internal_np( n_bits );

  /*** Allocate memory for eiy, eix . *************************/
  eiy = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eiy )
  {
    /* fatal error */
    return;
  }

  eix = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eix )
  {
    /* fatal error */

    /* FREE eiy ***************/
    __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }
  /************************************************************/

  unpack( eix, (EMUSHORT *)x, n_bits );

  ei_exp( eiy, eix, n_bits );

  pack( (EMUSHORT *)y, eiy, n_bits );

  /* FREE eix ***************/
  /* FREE eiy ***************/
  __mpu_sbrk( -(int)(2*np*SIZE_OF_EMUSHORT) );
  /**************************/

} /* End of r_exp() */


void r_atan2( mpu_real *c, mpu_real *y, mpu_real *x, int nb )
/*
  rATAN2( Y,X ) RETURN ARG(EIX+iEIY); ARG(x+iy) = arctan(y/x).
 ****************************************************************/
{
  EMUSHORT *eic = NULL,
           *eiy = NULL,
           *eix = NULL;
  int       n_bits;
  int       np;

  errno           = 0;
  __real_error_no = 0;

  __CLEAR_RFLAGS;

  n_bits = nb * BITS_PER_BYTE;

  np = internal_np( n_bits );

  /*** Allocate memory for eic, eiy, eix . ********************/
  eic = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eic )
  {
    /* fatal error */
    return;
  }

  eiy = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eiy )
  {
    /* fatal error */

    /* FREE eic ***************/
    __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }

  eix = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eix )
  {
    /* fatal error */

    /* FREE eiy ***************/
    /* FREE eic ***************/
    __mpu_sbrk( -(int)(2*np*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }
  /************************************************************/

  unpack( eix, (EMUSHORT *)x, n_bits );
  unpack( eiy, (EMUSHORT *)y, n_bits );

  ei_atan2( eic, eiy, eix, n_bits );

  pack( (EMUSHORT *)c, eic, n_bits );

  /* FREE eix ***************/
  /* FREE eiy ***************/
  /* FREE eic ***************/
  __mpu_sbrk( -(int)(3*np*SIZE_OF_EMUSHORT) );
  /**************************/

} /* End of r_atan2() */


void r_sinh( mpu_real *y, mpu_real *x, int nb )
/*
 *******************************/
{
  EMUSHORT *eiy = NULL,
           *eix = NULL;
  int       n_bits;
  int       np;

  errno           = 0;
  __real_error_no = 0;

  __CLEAR_RFLAGS;

  n_bits = nb * BITS_PER_BYTE;

  np = internal_np( n_bits );

  /*** Allocate memory for eiy, eix . *************************/
  eiy = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eiy )
  {
    /* fatal error */
    return;
  }

  eix = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eix )
  {
    /* fatal error */

    /* FREE eiy ***************/
    __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }
  /************************************************************/

  unpack( eix, (EMUSHORT *)x, n_bits );

  ei_sinh( eiy, eix, n_bits );

  pack( (EMUSHORT *)y, eiy, n_bits );

  /* FREE eix ***************/
  /* FREE eiy ***************/
  __mpu_sbrk( -(int)(2*np*SIZE_OF_EMUSHORT) );
  /**************************/

} /* End of r_sinh() */


void r_cosh( mpu_real *y, mpu_real *x, int nb )
/*
 *******************************/
{
  EMUSHORT *eiy = NULL,
           *eix = NULL;
  int       n_bits;
  int       np;

  errno           = 0;
  __real_error_no = 0;

  __CLEAR_RFLAGS;

  n_bits = nb * BITS_PER_BYTE;

  np = internal_np( n_bits );

  /*** Allocate memory for eiy, eix . *************************/
  eiy = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eiy )
  {
    /* fatal error */
    return;
  }

  eix = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eix )
  {
    /* fatal error */

    /* FREE eiy ***************/
    __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }
  /************************************************************/

  unpack( eix, (EMUSHORT *)x, n_bits );

  ei_cosh( eiy, eix, n_bits );

  pack( (EMUSHORT *)y, eiy, n_bits );

  /* FREE eix ***************/
  /* FREE eiy ***************/
  __mpu_sbrk( -(int)(2*np*SIZE_OF_EMUSHORT) );
  /**************************/

} /* End of r_cosh() */


void r_tanh( mpu_real *y, mpu_real *x, int nb )
/*
 *******************************/
{
  EMUSHORT *eiy = NULL,
           *eix = NULL;
  int       n_bits;
  int       np;

  errno           = 0;
  __real_error_no = 0;

  __CLEAR_RFLAGS;

  n_bits = nb * BITS_PER_BYTE;

  np = internal_np( n_bits );

  /*** Allocate memory for eiy, eix . *************************/
  eiy = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eiy )
  {
    /* fatal error */
    return;
  }

  eix = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eix )
  {
    /* fatal error */

    /* FREE eiy ***************/
    __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }
  /************************************************************/

  unpack( eix, (EMUSHORT *)x, n_bits );

  ei_tanh( eiy, eix, n_bits );

  pack( (EMUSHORT *)y, eiy, n_bits );

  /* FREE eix ***************/
  /* FREE eiy ***************/
  __mpu_sbrk( -(int)(2*np*SIZE_OF_EMUSHORT) );
  /**************************/

} /* End of r_tanh() */


void r_asinh( mpu_real *y, mpu_real *x, int nb )
/*
 *******************************/
{
  EMUSHORT *eiy = NULL,
           *eix = NULL;
  int       n_bits;
  int       np;

  errno           = 0;
  __real_error_no = 0;

  __CLEAR_RFLAGS;

  n_bits = nb * BITS_PER_BYTE;

  np = internal_np( n_bits );

  /*** Allocate memory for eiy, eix . *************************/
  eiy = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eiy )
  {
    /* fatal error */
    return;
  }

  eix = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eix )
  {
    /* fatal error */

    /* FREE eiy ***************/
    __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }
  /************************************************************/

  unpack( eix, (EMUSHORT *)x, n_bits );

  ei_asinh( eiy, eix, n_bits );

  pack( (EMUSHORT *)y, eiy, n_bits );

  /* FREE eix ***************/
  /* FREE eiy ***************/
  __mpu_sbrk( -(int)(2*np*SIZE_OF_EMUSHORT) );
  /**************************/

} /* End of r_asinh() */


void r_acosh( mpu_real *y, mpu_real *x, int nb )
/*
 *******************************/
{
  EMUSHORT *eiy = NULL,
           *eix = NULL;
  int       n_bits;
  int       np;

  errno           = 0;
  __real_error_no = 0;

  __CLEAR_RFLAGS;

  n_bits = nb * BITS_PER_BYTE;

  np = internal_np( n_bits );

  /*** Allocate memory for eiy, eix . *************************/
  eiy = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eiy )
  {
    /* fatal error */
    return;
  }

  eix = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eix )
  {
    /* fatal error */

    /* FREE eiy ***************/
    __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }
  /************************************************************/

  unpack( eix, (EMUSHORT *)x, n_bits );

  ei_acosh( eiy, eix, n_bits );

  pack( (EMUSHORT *)y, eiy, n_bits );

  /* FREE eix ***************/
  /* FREE eiy ***************/
  __mpu_sbrk( -(int)(2*np*SIZE_OF_EMUSHORT) );
  /**************************/

} /* End of r_acosh() */


void r_atanh( mpu_real *y, mpu_real *x, int nb )
/*
 *******************************/
{
  EMUSHORT *eiy = NULL,
           *eix = NULL;
  int       n_bits;
  int       np;

  errno           = 0;
  __real_error_no = 0;

  __CLEAR_RFLAGS;

  n_bits = nb * BITS_PER_BYTE;

  np = internal_np( n_bits );

  /*** Allocate memory for eiy, eix . *************************/
  eiy = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eiy )
  {
    /* fatal error */
    return;
  }

  eix = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eix )
  {
    /* fatal error */

    /* FREE eiy ***************/
    __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }
  /************************************************************/

  unpack( eix, (EMUSHORT *)x, n_bits );

  ei_atanh( eiy, eix, n_bits );

  pack( (EMUSHORT *)y, eiy, n_bits );

  /* FREE eix ***************/
  /* FREE eiy ***************/
  __mpu_sbrk( -(int)(2*np*SIZE_OF_EMUSHORT) );
  /**************************/

} /* End of r_atanh() */


void r_asin( mpu_real *y, mpu_real *x, int nb )
/*
 *******************************/
{
  EMUSHORT *eiy = NULL,
           *eix = NULL;
  int       n_bits;
  int       np;

  errno           = 0;
  __real_error_no = 0;

  __CLEAR_RFLAGS;

  n_bits = nb * BITS_PER_BYTE;

  np = internal_np( n_bits );

  /*** Allocate memory for eiy, eix . *************************/
  eiy = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eiy )
  {
    /* fatal error */
    return;
  }

  eix = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eix )
  {
    /* fatal error */

    /* FREE eiy ***************/
    __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }
  /************************************************************/

  unpack( eix, (EMUSHORT *)x, n_bits );

  ei_asin( eiy, eix, n_bits );

  pack( (EMUSHORT *)y, eiy, n_bits );

  /* FREE eix ***************/
  /* FREE eiy ***************/
  __mpu_sbrk( -(int)(2*np*SIZE_OF_EMUSHORT) );
  /**************************/

} /* End of r_asin() */


void r_acos( mpu_real *y, mpu_real *x, int nb )
/*
 *******************************/
{
  EMUSHORT *eiy = NULL,
           *eix = NULL;
  int       n_bits;
  int       np;

  errno           = 0;
  __real_error_no = 0;

  __CLEAR_RFLAGS;

  n_bits = nb * BITS_PER_BYTE;

  np = internal_np( n_bits );

  /*** Allocate memory for eiy, eix . *************************/
  eiy = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eiy )
  {
    /* fatal error */
    return;
  }

  eix = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eix )
  {
    /* fatal error */

    /* FREE eiy ***************/
    __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }
  /************************************************************/

  unpack( eix, (EMUSHORT *)x, n_bits );

  ei_acos( eiy, eix, n_bits );

  pack( (EMUSHORT *)y, eiy, n_bits );

  /* FREE eix ***************/
  /* FREE eiy ***************/
  __mpu_sbrk( -(int)(2*np*SIZE_OF_EMUSHORT) );
  /**************************/

} /* End of r_acos() */


void r_atan( mpu_real *y, mpu_real *x, int nb )
/*
 *******************************/
{
  EMUSHORT *eiy = NULL,
           *eix = NULL;
  int       n_bits;
  int       np;

  errno           = 0;
  __real_error_no = 0;

  __CLEAR_RFLAGS;

  n_bits = nb * BITS_PER_BYTE;

  np = internal_np( n_bits );

  /*** Allocate memory for eiy, eix . *************************/
  eiy = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eiy )
  {
    /* fatal error */
    return;
  }

  eix = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eix )
  {
    /* fatal error */

    /* FREE eiy ***************/
    __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }
  /************************************************************/

  unpack( eix, (EMUSHORT *)x, n_bits );

  ei_atan( eiy, eix, n_bits );

  pack( (EMUSHORT *)y, eiy, n_bits );

  /* FREE eix ***************/
  /* FREE eiy ***************/
  __mpu_sbrk( -(int)(2*np*SIZE_OF_EMUSHORT) );
  /**************************/

} /* End of r_atan() */


void r_pow( mpu_real *c, mpu_real *x, mpu_real *y, int nb )
/*
  rPOW( C, X, Y) RETURN C = X^Y.
 ********************************/
{
  EMUSHORT *eic = NULL,
           *eiy = NULL,
           *eix = NULL;
  int       n_bits;
  int       np;

  errno           = 0;
  __real_error_no = 0;

  __CLEAR_RFLAGS;

  n_bits = nb * BITS_PER_BYTE;

  np = internal_np( n_bits );

  /*** Allocate memory for eic, eiy, eix . ********************/
  eic = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eic )
  {
    /* fatal error */
    return;
  }

  eiy = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eiy )
  {
    /* fatal error */

    /* FREE eic ***************/
    __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }

  eix = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eix )
  {
    /* fatal error */

    /* FREE eiy ***************/
    /* FREE eic ***************/
    __mpu_sbrk( -(int)(2*np*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }
  /************************************************************/

  unpack( eix, (EMUSHORT *)x, n_bits );
  unpack( eiy, (EMUSHORT *)y, n_bits );

  ei_pow( eic, eix, eiy, n_bits );

  pack( (EMUSHORT *)c, eic, n_bits );

  /* FREE eix ***************/
  /* FREE eiy ***************/
  /* FREE eic ***************/
  __mpu_sbrk( -(int)(3*np*SIZE_OF_EMUSHORT) );
  /**************************/

} /* End of r_pow() */

/**
  END: __MPU_MATH.H
 ***************************************************************/

void r_hypot( mpu_real *c, mpu_real *x, mpu_real *y, int nb )
/*
  rHYPOT( C, X, Y ) RETURN C = sqrt(X*X + Y*Y).
 ***********************************************/
{
  EMUSHORT *eic = NULL,
           *eiy = NULL,
           *eix = NULL;
  int       n_bits;
  int       np;

  errno           = 0;
  __real_error_no = 0;

  __CLEAR_RFLAGS;

  n_bits = nb * BITS_PER_BYTE;

  np = internal_np( n_bits );

  /*** Allocate memory for eic, eiy, eix . ********************/
  eic = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eic )
  {
    /* fatal error */
    return;
  }

  eiy = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eiy )
  {
    /* fatal error */

    /* FREE eic ***************/
    __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }

  eix = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eix )
  {
    /* fatal error */

    /* FREE eiy ***************/
    /* FREE eic ***************/
    __mpu_sbrk( -(int)(2*np*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }
  /************************************************************/

  unpack( eix, (EMUSHORT *)x, n_bits );
  unpack( eiy, (EMUSHORT *)y, n_bits );

  ei_mul( eix, eix, eix, n_bits );
  ei_mul( eiy, eiy, eiy, n_bits );
  ei_add( eic, eix, eiy, n_bits ); 
  ei_sqrt( eic, eic, n_bits );

  pack( (EMUSHORT *)c, eic, n_bits );

  /* FREE eix ***************/
  /* FREE eiy ***************/
  /* FREE eic ***************/
  __mpu_sbrk( -(int)(3*np*SIZE_OF_EMUSHORT) );
  /**************************/

} /* End of r_hypot() */


/***************************************************************
  BEGIN: __MPU_IOREAL.H
 **/

/*************************************************
  ПРИМЕРЫ числовых констант для ascii_to_real():
    real:
      +NaN; nan; nAn; naN; Nan; и т.д.          ==  NaN;
      -i; +inf; inf;                            ==  inf;
      ind; -ind;                любыми буквами; == -ind;
      -3.14e+17;  + 3.14e-17;  +.e;  .e;   e;
      -3.14E+17;  + 3.14E-17;  +.E;  .E;  +E;
      .;
    ПО ПОВОДУ inf:
      можно писать и infinity но функция
      rASCII_TO_REAL() будет проверять только
      первые три буквы, => все равно что писать
      infinity или information (NOTE: отбрасывание 
      ненужных символов будет возложено на
      функции более высокого уровня).
    real_part only:
      -3.14r+17;  + 3.14r-17;  +.r;  .r;  -r;
      -3.14R+17;  + 3.14R-17;  +.R;  .R;   R;
    imaginary only:
      -3.14j+17;  + 3.14j-17;  +.j;  .j;   j;
      -3.14J+17;  + 3.14J-17;  +.J;  .J;  -J;

    ВЕЩЕСТВЕННЫЕ И МНИМЫЕ БЕСКОНЕЧНОСТИ
    И НЕЧИСЛА:

     infinity, inf, NaN, nan, ind, -ind,
     inf_e, NaN_e, -ind_e,
     inf_E, NaN_E, -ind_E, и т.д.
     ВСЕ СУТЬ:             _LONGHAND_REAL_NUMBER

     inf_r, NaN_r, -ind_r,
     inf_R, NaN_R, -ind_R, и т.д.
     ВСЕ СУТЬ:             _REAL_PART_OF_COMPLEX

     inf_j, NaN_j, -ind_j,
     inf_J, NaN_J, -ind_J, и т.д.
     ВСЕ СУТЬ:             _IMAGINARY_OF_COMPLEX
 *************************************************/

int ascii_to_real( mpu_real *c, __mpu_char8_t *s, int nb )
{
  EMUSHORT *eic = NULL;
  int       n_bits;
  int       np;
  int       ret = _ASCII_TO_REAL_ERROR;

  errno           = 0;
  __real_error_no = 0;

  __CLEAR_RFLAGS;

  n_bits = nb * BITS_PER_BYTE;

  np = internal_np( n_bits );

  /*** Allocate memory for eic . ******************************/
  eic = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eic )
  {
    /* fatal error */
    return( ret );
  }
  /************************************************************/

  ret = ei_ascii_to_real( eic, s, n_bits );

  /* В случае ошибки не портить ПРИЕМНИК! */
  /* Если производить упаковку без проверки на ошибку
    [ if( ret != _ASCII_TO_REAL_ERROR ) {} ], то в
    случае ошибки в ПРИЕМНИК будет записан NaN и RET
    будет равно RET = -1.
   */
  if( ret != _ASCII_TO_REAL_ERROR )
  {
    pack( (EMUSHORT *)c, eic, n_bits );
  }

  /* FREE eic ***************/
  __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) );
  /**************************/

  return( ret );

} /* End of ascii_to_real() */


/*************************************************
  МОЖЕТ ВЫВЕСТИ:
                 NaN;  -NaN;  inf;  -inf;  -ind;
  if( gen_plus )
                +NaN;        +inf;

  Если exp_delim == 'r' || 'R' то к обозначениям
        NaN;  -NaN;  inf;  -inf;  -ind;
       +NaN;        +inf;
  приписывается "_r" (например, inf_r).

  Если exp_delim == 'j' || 'J' то к обозначениям
        NaN;  -NaN;  inf;  -inf;  -ind;
       +NaN;        +inf;
  приписывается "_j" (например, inf_j).

  Если exp_delim == 'e' || 'E' || (любой другой)
  то к обозначениям
        NaN;  -NaN;  inf;  -inf;  -ind;
       +NaN;        +inf;
  ничего не приписывается.
 *************************************************/

void real_to_ascii( __mpu_char8_t *s, mpu_real *c, int ndigs, int exp_delim, int exp_digs, int gen_plus, int nb )
/* ndigs     - количество выводимых разрядов мантиссы */
/* exp_delim - символ ЭКСПОНЕНТЫ                      */
/* exp_digs  - количество цифр ЭКСПОНЕНТЫ             */
/* gen_plus  - ПРИНУДИТЕЛЬНАЯ ЗАПИСЬ символа '+'
               перед положительной экспонентой        */
{
  EMUSHORT *eic = NULL;
  int       n_bits;
  int       np;

  errno           = 0;
  __real_error_no = 0;

  __CLEAR_RFLAGS;

  n_bits = nb * BITS_PER_BYTE;

  np = internal_np( n_bits );

  /*** Allocate memory for eic . ******************************/
  eic = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eic )
  {
    /* fatal error */
    return;
  }
  /************************************************************/

  unpack( eic, (EMUSHORT *)c, n_bits );

  ei_real_to_ascii( s, eic, ndigs, exp_delim, exp_digs, gen_plus, n_bits );

  /* FREE eic ***************/
  __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) );
  /**************************/

} /* End of real_to_ascii() */

/**
  END: __MPU_IOREAL.H
 ***************************************************************/


/***************************************************************
                 COMPLEX ARITHMETIC OPERATIONS
 ***************************************************************/

/***************************************************************

  complex data struct:

 =====================================================================
  index:
  WORDS_BIG_ENDIAN == 0
  [nRx+nIx-1],  . . . ,       [nIx]|[nIx-1],      . . .,          [0].
  WORDS_BIG_ENDIAN == 1
  [0],          . . . ,     [nRx-1]|[nRx],        . . .,  [nRx+nIx-1].
 |--------------. . .--------------|--------------. . .--------------|
 |            Real part            |            Imaginary            |
 |--------------. . .--------------|--------------. . .--------------|
  size:                         nRx                               nIx.

 =====================================================================

  For alternative byte,Word ordering my by typedef the complex
  number data struct:

    typedef struct {
    #if WORDS_BIG_ENDIAN == 1
      // SEE: t_machine.h ->, for example, -> (i386.h).
      mpu_real re[X];
    #endif
      mpu_real im[X];
    #if WORDS_BIG_ENDIAN == 0
      mpu_real re[X];
    #endif
    } complex_Xbytes;

 ***************************************************************/

void c_real_part( mpu_real *r, mpu_complex *c, int nb )
{
  mpu_real *pc;

  __real_error_no = 0;

  __CLEAR_RFLAGS;

  pc = c;

  /****************
    mov REAL_PART
   ****************/
#if MPU_WORD_ORDER_BIG_ENDIAN == 0
  pc += nb; /* point to real_part */
#endif
  r_cpy( r, pc, nb );

} /* End of c_real_part() */


void c_imaginary( mpu_real *r, mpu_complex *c, int nb )
{
  mpu_real *pc;

  __real_error_no = 0;

  __CLEAR_RFLAGS;

  pc = c;

  /****************
    mov REAL_PART
   ****************/
#if MPU_WORD_ORDER_BIG_ENDIAN == 1
  pc += nb; /* point to imaginary */
#endif
  r_cpy( r, pc, nb );

} /* End of c_imaginary() */


void c_real_to_complex( mpu_complex *c, mpu_real *r, int nb )
{
  mpu_real *pc;
  int       i;

  __real_error_no = 0;

  __CLEAR_RFLAGS;

  pc = c;
  for( i = 0; i < nb*2; i++ ) *pc++ = 0;

  pc = c;

  /****************
    mov REAL_PART
   ****************/
#if MPU_WORD_ORDER_BIG_ENDIAN == 0
  pc += nb; /* point to real_part */
#endif
  r_cpy( pc, r, nb );

} /* End of c_real_to_complex() */


void c_gen_complex( mpu_complex *c, mpu_real *r, mpu_real *j, int nb )
{
  mpu_real *pc;

  __real_error_no = 0;

  __CLEAR_RFLAGS;

  pc = c;

  /****************
    mov IMAGINARY
   ****************/
#if MPU_WORD_ORDER_BIG_ENDIAN == 1
  pc += nb; /* point to imaginary */
#endif
  r_cpy( pc, j, nb );

  /****************
    mov REAL_PART
   ****************/
#if MPU_WORD_ORDER_BIG_ENDIAN == 1
  pc -= nb; /* point to real_part */
#else
  pc += nb; /* point to real_part */
#endif
  r_cpy( pc, r, nb );

} /* End of c_gen_complex() */


void c_polar( mpu_complex *c, mpu_real *rho, mpu_real *theta, int nb )
/*
  The function returns the complex value C
  whose magnitude is rho and whose phase angle is theta.
 ********************************************************/
{
  EMUSHORT *eic_r = NULL, *eic_j   = NULL,
           *eirho = NULL, *eitheta = NULL;
  mpu_real *pc;
  int       n_bits;
  int       np;

  errno           = 0;
  __real_error_no = 0;

  __CLEAR_RFLAGS;

  pc = c;

  n_bits = nb * BITS_PER_BYTE;

  np = internal_np( n_bits );

  /*** Allocate memory for eic_r, eic_j, eirho, eitheta . *****/
  eic_r = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eic_r )
  {
    /* fatal error */
    return;
  }

  eic_j = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eic_j )
  {
    /* fatal error */

    /* FREE eic_r *************/
    __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }

  eirho = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eirho )
  {
    /* fatal error */

    /* FREE eic_j *************/
    /* FREE eic_r *************/
    __mpu_sbrk( -(int)(2*np*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }

  eitheta = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eitheta )
  {
    /* fatal error */

    /* FREE eirho *************/
    /* FREE eic_j *************/
    /* FREE eic_r *************/
    __mpu_sbrk( -(int)(3*np*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }
  /************************************************************/

  /**********************
    unpack MODUL & ANGLE
   **********************/
  unpack( eirho,   (EMUSHORT *)rho,   n_bits );
  unpack( eitheta, (EMUSHORT *)theta, n_bits );

  /* Find the complex value whose magnitude is rho
    and whose phase angle is theta. */
  /*
    eic_r = rho * cos( theta );
    eic_j = rho * sin( theta );
   */
  ei_cos( eic_r, eitheta, n_bits );
  ei_mul( eic_r, eirho, eic_r, n_bits );

  ei_sin( eic_j, eitheta, n_bits );
  ei_mul( eic_j, eirho, eic_j, n_bits );

  /****************
    pack IMAGINARY
   ****************/
#if MPU_WORD_ORDER_BIG_ENDIAN == 1
  pc += nb; /* point to imaginary */
#endif
  pack( (EMUSHORT *)pc, eic_j, n_bits );

  /****************
    pack REAL_PART
   ****************/
#if MPU_WORD_ORDER_BIG_ENDIAN == 1
  pc -= nb; /* point to real_part */
#else
  pc += nb; /* point to real_part */
#endif
  pack( (EMUSHORT *)pc, eic_r, n_bits );

  /* FREE eitheta ***********/
  /* FREE eirho *************/
  /* FREE eic_j *************/
  /* FREE eic_r *************/
  __mpu_sbrk( -(int)(4*np*SIZE_OF_EMUSHORT) );
  /**************************/

} /* End of c_polar() */


void c_conj( mpu_complex *c, mpu_complex *x, int nb )
/*
  The function returns the conjugate of x.
 ******************************************/
{
  mpu_real *pc;
  int       i, n_bits;

  __real_error_no = 0;

  __CLEAR_RFLAGS;

  /* copy the complex number */
  pc = c;
  for( i = 0; i < nb*2; i++ ) *pc++ = *x++;

  pc = c; /* return to C */

  n_bits = nb * BITS_PER_BYTE;

#if MPU_WORD_ORDER_BIG_ENDIAN == 1
  pc += nb; /* point to imaginary */
#endif

  /* Negate IMAGINARY in External format */
  e_neg( (EMUSHORT *)pc, n_bits );

} /* End of c_conj() */


void c_abs( mpu_real *r, mpu_complex *c, int nb )
/*
  The function returns the magnitude of C.
 ******************************************/
{
  EMUSHORT *eic_r = NULL, *eic_j = NULL;
  mpu_real *pc;
  int       n_bits;
  int       np;

  errno           = 0;
  __real_error_no = 0;

  __CLEAR_RFLAGS;

  pc = c;

  n_bits = nb * BITS_PER_BYTE;

  np = internal_np( n_bits );

  /*** Allocate memory for eic_r, eic_j . *********************/
  eic_r = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eic_r )
  {
    /* fatal error */
    return;
  }

  eic_j = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eic_j )
  {
    /* fatal error */

    /* FREE eic_r *************/
    __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }
  /************************************************************/

  /******************
    unpack IMAGINARY
   ******************/
#if MPU_WORD_ORDER_BIG_ENDIAN == 1
  pc += nb; /* point to imaginary */
#endif
  unpack( eic_j, (EMUSHORT *)pc, n_bits );

  /******************
    unpack REAL_PART
   ******************/
#if MPU_WORD_ORDER_BIG_ENDIAN == 1
  pc -= nb; /* point to real_part */
#else
  pc += nb; /* point to real_part */
#endif
  unpack( eic_r, (EMUSHORT *)pc, n_bits );

  /* find the MODUL of a complex number */
  /*
     MOD(a+bi) = sqrt(a*a + b*b); 
   */
  ei_mul( eic_r, eic_r, eic_r, n_bits );
  ei_mul( eic_j, eic_j, eic_j, n_bits );
  ei_add( eic_r, eic_r, eic_j, n_bits ); 
  ei_sqrt( eic_r, eic_r, n_bits );

  pack( (EMUSHORT *)r, eic_r, n_bits );

  /* FREE eic_j *************/
  /* FREE eic_r *************/
  __mpu_sbrk( -(int)(2*np*SIZE_OF_EMUSHORT) );
  /**************************/

} /* End of c_abs() */


void c_norm( mpu_real *r, mpu_complex *c, int nb )
/*
  The function returns the squared magnitude of C.
 **************************************************/
{
  EMUSHORT *eic_r = NULL, *eic_j = NULL;
  mpu_real *pc;
  int       n_bits;
  int       np;

  errno           = 0;
  __real_error_no = 0;

  __CLEAR_RFLAGS;

  pc = c;

  n_bits = nb * BITS_PER_BYTE;

  np = internal_np( n_bits );

  /*** Allocate memory for eic_r, eic_j . *********************/
  eic_r = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eic_r )
  {
    /* fatal error */
    return;
  }

  eic_j = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eic_j )
  {
    /* fatal error */

    /* FREE eic_r *************/
    __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }
  /************************************************************/

  /******************
    unpack IMAGINARY
   ******************/
#if MPU_WORD_ORDER_BIG_ENDIAN == 1
  pc += nb; /* point to imaginary */
#endif
  unpack( eic_j, (EMUSHORT *)pc, n_bits );

  /******************
    unpack REAL_PART
   ******************/
#if MPU_WORD_ORDER_BIG_ENDIAN == 1
  pc -= nb; /* point to real_part */
#else
  pc += nb; /* point to real_part */
#endif
  unpack( eic_r, (EMUSHORT *)pc, n_bits );

  /* find the MODUL of a complex number */
  /*
     MOD(a+bi) = sqrt(a*a + b*b); 
   */
  ei_mul( eic_r, eic_r, eic_r, n_bits );
  ei_mul( eic_j, eic_j, eic_j, n_bits );
  ei_add( eic_r, eic_r, eic_j, n_bits ); 

  pack( (EMUSHORT *)r, eic_r, n_bits );

  /* FREE eic_j *************/
  /* FREE eic_r *************/
  __mpu_sbrk( -(int)(2*np*SIZE_OF_EMUSHORT) );
  /**************************/

} /* End of c_norm() */


void c_arg( mpu_real *r, mpu_complex *c, int nb )
/*
  The function returns the phase angle of C.
 ********************************************/
{
  EMUSHORT *eic_r = NULL, *eic_j = NULL;
  mpu_real *pc;
  int       n_bits;
  int       np;

  errno           = 0;
  __real_error_no = 0;

  __CLEAR_RFLAGS;

  pc = c;

  n_bits = nb * BITS_PER_BYTE;

  np = internal_np( n_bits );

  /*** Allocate memory for eic_r, eic_j . *********************/
  eic_r = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eic_r )
  {
    /* fatal error */
    return;
  }

  eic_j = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eic_j )
  {
    /* fatal error */

    /* FREE eic_r *************/
    __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }
  /************************************************************/

  /******************
    unpack IMAGINARY
   ******************/
#if MPU_WORD_ORDER_BIG_ENDIAN == 1
  pc += nb; /* point to imaginary */
#endif
  unpack( eic_j, (EMUSHORT *)pc, n_bits );

  /******************
    unpack REAL_PART
   ******************/
#if MPU_WORD_ORDER_BIG_ENDIAN == 1
  pc -= nb; /* point to real_part */
#else
  pc += nb; /* point to real_part */
#endif
  unpack( eic_r, (EMUSHORT *)pc, n_bits );

  /* find the ARGUMENT of a complex number */
  /*
     ARG(a+bi) = atan2(b/a); 
   */
  ei_atan2( eic_r, eic_j, eic_r, n_bits );

  pack( (EMUSHORT *)r, eic_r, n_bits );

  /* FREE eic_j *************/
  /* FREE eic_r *************/
  __mpu_sbrk( -(int)(2*np*SIZE_OF_EMUSHORT) );
  /**************************/

} /* End of c_arg() */


int c_is_equal( mpu_complex *a, mpu_complex *b, int nb )
{
  EMUSHORT *eia_r = NULL, *eia_j = NULL,
           *eib_r = NULL, *eib_j = NULL;
  mpu_real *pa, *pb;
  int       n_bits;
  int       np;

  errno           = 0;
  __real_error_no = 0;

  __CLEAR_RFLAGS;

  pa = a;
  pb = b;

  n_bits = nb * BITS_PER_BYTE;

  np = internal_np( n_bits );

  /*** Allocate memory for eia_r, eia_j, eib_r, eib_j . *******/
  eia_r = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eia_r )
  {
    /* fatal error */
    return( -1 );
  }

  eia_j = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eia_j )
  {
    /* fatal error */

    /* FREE eia_r *************/
    __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) );
    /**************************/

    return( -1 );
  }

  eib_r = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eib_r )
  {
    /* fatal error */

    /* FREE eia_j *************/
    /* FREE eia_r *************/
    __mpu_sbrk( -(int)(2*np*SIZE_OF_EMUSHORT) );
    /**************************/

    return( -1 );
  }

  eib_j = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eib_j )
  {
    /* fatal error */

    /* FREE eib_r *************/
    /* FREE eia_j *************/
    /* FREE eia_r *************/
    __mpu_sbrk( -(int)(3*np*SIZE_OF_EMUSHORT) );
    /**************************/

    return( -1 );
  }
  /************************************************************/

  /******************
    unpack IMAGINARY
   ******************/
#if MPU_WORD_ORDER_BIG_ENDIAN == 1
  pa += nb; /* point to imaginary */
  pb += nb;
#endif
  unpack( eia_j, (EMUSHORT *)pa, n_bits );
  unpack( eib_j, (EMUSHORT *)pb, n_bits );

  /******************
    unpack REAL_PART
   ******************/
#if MPU_WORD_ORDER_BIG_ENDIAN == 1
  pa -= nb; /* point to real_part */
  pb -= nb;
#else
  pa += nb; /* point to real_part */
  pb += nb;
#endif
  unpack( eia_r, (EMUSHORT *)pa, n_bits );
  unpack( eib_r, (EMUSHORT *)pb, n_bits );

  /* IS_EQUAL ? complex numbers */
  /*
     if( (a+bi) == (c+di) ) return 1;
     else                   return 0;
   */
  if( (ei_cmp( eia_r, eib_r, n_bits ) == 0) &&
      (ei_cmp( eia_j, eib_j, n_bits ) == 0)    )
  {
    /* FREE eib_j *************/
    /* FREE eib_r *************/
    /* FREE eia_j *************/
    /* FREE eia_r *************/
    __mpu_sbrk( -(int)(4*np*SIZE_OF_EMUSHORT) );
    /**************************/

    return( 1 );
  }
  else
  {
    /* FREE eib_j *************/
    /* FREE eib_r *************/
    /* FREE eia_j *************/
    /* FREE eia_r *************/
    __mpu_sbrk( -(int)(4*np*SIZE_OF_EMUSHORT) );
    /**************************/

    return( 0 );
  }

} /* End of c_is_equal() */


int c_is_nequal( mpu_complex *a, mpu_complex *b, int nb )
{
  EMUSHORT *eia_r = NULL, *eia_j = NULL,
           *eib_r = NULL, *eib_j = NULL;
  mpu_real *pa, *pb;
  int       n_bits;
  int       np;

  errno           = 0;
  __real_error_no = 0;

  __CLEAR_RFLAGS;

  pa = a;
  pb = b;

  n_bits = nb * BITS_PER_BYTE;

  np = internal_np( n_bits );

  /*** Allocate memory for eia_r, eia_j, eib_r, eib_j . *******/
  eia_r = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eia_r )
  {
    /* fatal error */
    return( -1 );
  }

  eia_j = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eia_j )
  {
    /* fatal error */

    /* FREE eia_r *************/
    __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) );
    /**************************/

    return( -1 );
  }

  eib_r = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eib_r )
  {
    /* fatal error */

    /* FREE eia_j *************/
    /* FREE eia_r *************/
    __mpu_sbrk( -(int)(2*np*SIZE_OF_EMUSHORT) );
    /**************************/

    return( -1 );
  }

  eib_j = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eib_j )
  {
    /* fatal error */

    /* FREE eib_r *************/
    /* FREE eia_j *************/
    /* FREE eia_r *************/
    __mpu_sbrk( -(int)(3*np*SIZE_OF_EMUSHORT) );
    /**************************/

    return( -1 );
  }
  /************************************************************/

  /******************
    unpack IMAGINARY
   ******************/
#if MPU_WORD_ORDER_BIG_ENDIAN == 1
  pa += nb; /* point to imaginary */
  pb += nb;
#endif
  unpack( eia_j, (EMUSHORT *)pa, n_bits );
  unpack( eib_j, (EMUSHORT *)pb, n_bits );

  /******************
    unpack REAL_PART
   ******************/
#if MPU_WORD_ORDER_BIG_ENDIAN == 1
  pa -= nb; /* point to real_part */
  pb -= nb;
#else
  pa += nb; /* point to real_part */
  pb += nb;
#endif
  unpack( eia_r, (EMUSHORT *)pa, n_bits );
  unpack( eib_r, (EMUSHORT *)pb, n_bits );

  /* IS_NEQUAL ? complex numbers */
  /*
     if( (a+bi) != (c+di) ) return 1;
     else                   return 0;
   */
  if( (ei_cmp( eia_r, eib_r, n_bits ) != 0) ||
      (ei_cmp( eia_j, eib_j, n_bits ) != 0)    )
  {
    /* FREE eib_j *************/
    /* FREE eib_r *************/
    /* FREE eia_j *************/
    /* FREE eia_r *************/
    __mpu_sbrk( -(int)(4*np*SIZE_OF_EMUSHORT) );
    /**************************/

    return( 1 );
  }
  else
  {
    /* FREE eib_j *************/
    /* FREE eib_r *************/
    /* FREE eia_j *************/
    /* FREE eia_r *************/
    __mpu_sbrk( -(int)(4*np*SIZE_OF_EMUSHORT) );
    /**************************/

    return( 0 );
  }

} /* End of c_is_nequal() */


void c_cpy( mpu_complex *a, mpu_complex *b, int nb )
{
  int  i;

  for( i = 0; i < nb*2; i++ ) *a++ = *b++;

} /* End of c_cpy() */


void c_cvt( mpu_complex *a, mpu_complex *b, int nb_a, int nb_b )
{
  EMUSHORT *eia_r = NULL, *eia_j = NULL,
           *eib_r = NULL, *eib_j = NULL;
  mpu_real *pa, *pb;
  int       n_bits_a, n_bits_b;
  int       np_a, np_b;

  errno           = 0;
  __real_error_no = 0;

  __CLEAR_RFLAGS;

  pa = a;
  pb = b;

  n_bits_a = nb_a * BITS_PER_BYTE;
  n_bits_b = nb_b * BITS_PER_BYTE;

  np_a = internal_np( n_bits_a );
  np_b = internal_np( n_bits_b );

  /*** Allocate memory for eia_r, eia_j, eib_r, eib_j . *******/
  eia_r = (EMUSHORT *)__mpu_sbrk( (int)(np_a*SIZE_OF_EMUSHORT) );
  if( !eia_r )
  {
    /* fatal error */
    return;
  }

  eia_j = (EMUSHORT *)__mpu_sbrk( (int)(np_a*SIZE_OF_EMUSHORT) );
  if( !eia_j )
  {
    /* fatal error */

    /* FREE eia_r *************/
    __mpu_sbrk( -(int)(np_a*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }

  eib_r = (EMUSHORT *)__mpu_sbrk( (int)(np_b*SIZE_OF_EMUSHORT) );
  if( !eib_r )
  {
    /* fatal error */

    /* FREE eia_j *************/
    /* FREE eia_r *************/
    __mpu_sbrk( -(int)(2*np_a*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }

  eib_j = (EMUSHORT *)__mpu_sbrk( (int)(np_b*SIZE_OF_EMUSHORT) );
  if( !eib_j )
  {
    /* fatal error */

    /* FREE eib_r *************/
    __mpu_sbrk( -(int)(np_b*SIZE_OF_EMUSHORT) );
    /**************************/

    /* FREE eia_j *************/
    /* FREE eia_r *************/
    __mpu_sbrk( -(int)(2*np_a*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }
  /************************************************************/

  /******************
    unpack IMAGINARY
   ******************/
#if MPU_WORD_ORDER_BIG_ENDIAN == 1
  pb += nb_b; /* point to imaginary */
#endif
  unpack( eib_j, (EMUSHORT *)pb, n_bits_b );

  /******************
    unpack REAL_PART
   ******************/
#if MPU_WORD_ORDER_BIG_ENDIAN == 1
  pb -= nb_b; /* point to real_part */
#else
  pb += nb_b; /* point to real_part */
#endif
  unpack( eib_r, (EMUSHORT *)pb, n_bits_b );

  /* CONVERT complex number */
  ei_convert( (EMUSHORT *)eia_r, (EMUSHORT *)eib_r, n_bits_a, n_bits_b );
  ei_convert( (EMUSHORT *)eia_j, (EMUSHORT *)eib_j, n_bits_a, n_bits_b );

  /****************
    pack IMAGINARY
   ****************/
#if MPU_WORD_ORDER_BIG_ENDIAN == 1
  pa += nb_a; /* point to imaginary */
#endif
  pack( (EMUSHORT *)pa, eia_j, n_bits_a );

  /****************
    pack REAL_PART
   ****************/
#if MPU_WORD_ORDER_BIG_ENDIAN == 1
  pa -= nb_a; /* point to real_part */
#else
  pa += nb_a; /* point to real_part */
#endif
  pack( (EMUSHORT *)pa, eia_r, n_bits_a );

  /* FREE eib_j *************/
  /* FREE eib_r *************/
  __mpu_sbrk( -(int)(2*np_b*SIZE_OF_EMUSHORT) );
  /**************************/

  /* FREE eia_j *************/
  /* FREE eia_r *************/
  __mpu_sbrk( -(int)(2*np_a*SIZE_OF_EMUSHORT) );
  /**************************/

} /* End of c_cvt() */


void c_add( mpu_complex *c, mpu_complex *a, mpu_complex *b, int nb )
{
  EMUSHORT *eic_r = NULL, *eic_j = NULL,
           *eia_r = NULL, *eia_j = NULL,
           *eib_r = NULL, *eib_j = NULL;
  mpu_real *pc, *pa, *pb;
  int       n_bits;
  int       np;

  errno           = 0;
  __real_error_no = 0;

  __CLEAR_RFLAGS;

  pa = a;
  pb = b;
  pc = c;

  n_bits = nb * BITS_PER_BYTE;

  np = internal_np( n_bits );

  /*** Allocate memory for eic_r, eic_j . *********************/
  eic_r = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eic_r )
  {
    /* fatal error */
    return;
  }

  eic_j = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eic_j )
  {
    /* fatal error */

    /* FREE eic_r *************/
    __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }
  /************************************************************/

  /*** Allocate memory for eia_r, eia_j, eib_r, eib_j . *******/
  eia_r = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eia_r )
  {
    /* fatal error */

    /* FREE eic_j *************/
    /* FREE eic_r *************/
    __mpu_sbrk( -(int)(2*np*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }

  eia_j = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eia_j )
  {
    /* fatal error */

    /* FREE eia_r *************/
    /* FREE eic_j *************/
    /* FREE eic_r *************/
    __mpu_sbrk( -(int)(3*np*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }

  eib_r = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eib_r )
  {
    /* fatal error */

    /* FREE eia_j *************/
    /* FREE eia_r *************/
    /* FREE eic_j *************/
    /* FREE eic_r *************/
    __mpu_sbrk( -(int)(4*np*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }

  eib_j = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eib_j )
  {
    /* fatal error */

    /* FREE eib_r *************/
    /* FREE eia_j *************/
    /* FREE eia_r *************/
    /* FREE eic_j *************/
    /* FREE eic_r *************/
    __mpu_sbrk( -(int)(5*np*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }
  /************************************************************/

  /******************
    unpack IMAGINARY
   ******************/
#if MPU_WORD_ORDER_BIG_ENDIAN == 1
  pa += nb; /* point to imaginary */
  pb += nb;
#endif
  unpack( eia_j, (EMUSHORT *)pa, n_bits );
  unpack( eib_j, (EMUSHORT *)pb, n_bits );

  /******************
    unpack REAL_PART
   ******************/
#if MPU_WORD_ORDER_BIG_ENDIAN == 1
  pa -= nb; /* point to real_part */
  pb -= nb;
#else
  pa += nb; /* point to real_part */
  pb += nb;
#endif
  unpack( eia_r, (EMUSHORT *)pa, n_bits );
  unpack( eib_r, (EMUSHORT *)pb, n_bits );

  /* ADD complex numbers */
  /*
     (a+bi) + (c+di) = (a + c) + (b + d)i; 
   */
  ei_add( eic_r, eia_r, eib_r, n_bits );
  ei_add( eic_j, eia_j, eib_j, n_bits );

  /****************
    pack IMAGINARY
   ****************/
#if MPU_WORD_ORDER_BIG_ENDIAN == 1
  pc += nb; /* point to imaginary */
#endif
  pack( (EMUSHORT *)pc, eic_j, n_bits );

  /****************
    pack REAL_PART
   ****************/
#if MPU_WORD_ORDER_BIG_ENDIAN == 1
  pc -= nb; /* point to real_part */
#else
  pc += nb; /* point to real_part */
#endif
  pack( (EMUSHORT *)pc, eic_r, n_bits );

  /* FREE eib_j *************/
  /* FREE eib_r *************/
  /* FREE eia_j *************/
  /* FREE eia_r *************/
  /* FREE eic_j *************/
  /* FREE eic_r *************/
  __mpu_sbrk( -(int)(6*np*SIZE_OF_EMUSHORT) );
  /**************************/

} /* End of c_add() */


void c_sub( mpu_complex *c, mpu_complex *a, mpu_complex *b, int nb )
{
  EMUSHORT *eic_r = NULL, *eic_j = NULL,
           *eia_r = NULL, *eia_j = NULL,
           *eib_r = NULL, *eib_j = NULL;
  mpu_real *pc, *pa, *pb;
  int       n_bits;
  int       np;

  errno           = 0;
  __real_error_no = 0;

  __CLEAR_RFLAGS;

  pa = a;
  pb = b;
  pc = c;

  n_bits = nb * BITS_PER_BYTE;

  np = internal_np( n_bits );

  /*** Allocate memory for eic_r, eic_j . *********************/
  eic_r = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eic_r )
  {
    /* fatal error */
    return;
  }

  eic_j = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eic_j )
  {
    /* fatal error */

    /* FREE eic_r *************/
    __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }
  /************************************************************/

  /*** Allocate memory for eia_r, eia_j, eib_r, eib_j . *******/
  eia_r = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eia_r )
  {
    /* fatal error */

    /* FREE eic_j *************/
    /* FREE eic_r *************/
    __mpu_sbrk( -(int)(2*np*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }

  eia_j = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eia_j )
  {
    /* fatal error */

    /* FREE eia_r *************/
    /* FREE eic_j *************/
    /* FREE eic_r *************/
    __mpu_sbrk( -(int)(3*np*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }

  eib_r = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eib_r )
  {
    /* fatal error */

    /* FREE eia_j *************/
    /* FREE eia_r *************/
    /* FREE eic_j *************/
    /* FREE eic_r *************/
    __mpu_sbrk( -(int)(4*np*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }

  eib_j = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eib_j )
  {
    /* fatal error */

    /* FREE eib_r *************/
    /* FREE eia_j *************/
    /* FREE eia_r *************/
    /* FREE eic_j *************/
    /* FREE eic_r *************/
    __mpu_sbrk( -(int)(5*np*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }
  /************************************************************/

  /******************
    unpack IMAGINARY
   ******************/
#if MPU_WORD_ORDER_BIG_ENDIAN == 1
  pa += nb; /* point to imaginary */
  pb += nb;
#endif
  unpack( eia_j, (EMUSHORT *)pa, n_bits );
  unpack( eib_j, (EMUSHORT *)pb, n_bits );

  /******************
    unpack REAL_PART
   ******************/
#if MPU_WORD_ORDER_BIG_ENDIAN == 1
  pa -= nb; /* point to real_part */
  pb -= nb;
#else
  pa += nb; /* point to real_part */
  pb += nb;
#endif
  unpack( eia_r, (EMUSHORT *)pa, n_bits );
  unpack( eib_r, (EMUSHORT *)pb, n_bits );

  /* SUB complex numbers */
  /*
     (a+bi) - (c+di) = (a - c) + (b - d)i; 
   */
  ei_sub( eic_r, eia_r, eib_r, n_bits );
  ei_sub( eic_j, eia_j, eib_j, n_bits );

  /****************
    pack IMAGINARY
   ****************/
#if MPU_WORD_ORDER_BIG_ENDIAN == 1
  pc += nb; /* point to imaginary */
#endif
  pack( (EMUSHORT *)pc, eic_j, n_bits );

  /****************
    pack REAL_PART
   ****************/
#if MPU_WORD_ORDER_BIG_ENDIAN == 1
  pc -= nb; /* point to real_part */
#else
  pc += nb; /* point to real_part */
#endif
  pack( (EMUSHORT *)pc, eic_r, n_bits );

  /* FREE eib_j *************/
  /* FREE eib_r *************/
  /* FREE eia_j *************/
  /* FREE eia_r *************/
  /* FREE eic_j *************/
  /* FREE eic_r *************/
  __mpu_sbrk( -(int)(6*np*SIZE_OF_EMUSHORT) );
  /**************************/

} /* End of c_sub() */


void c_mul( mpu_complex *c, mpu_complex *a, mpu_complex *b, int nb )
{
  EMUSHORT *eic_r = NULL, *eic_j = NULL,
           *eia_r = NULL, *eia_j = NULL,
           *eib_r = NULL, *eib_j = NULL,
           *eitmp = NULL;
  mpu_real *pc, *pa, *pb;
  int       n_bits;
  int       np;

  errno           = 0;
  __real_error_no = 0;

  __CLEAR_RFLAGS;

  pa = a;
  pb = b;
  pc = c;

  n_bits = nb * BITS_PER_BYTE;

  np = internal_np( n_bits );

  /*** Allocate memory for eic_r, eic_j . *********************/
  eic_r = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eic_r )
  {
    /* fatal error */
    return;
  }

  eic_j = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eic_j )
  {
    /* fatal error */

    /* FREE eic_r *************/
    __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }
  /************************************************************/

  /*** Allocate memory for eia_r, eia_j, eib_r, eib_j . *******/
  eia_r = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eia_r )
  {
    /* fatal error */

    /* FREE eic_j *************/
    /* FREE eic_r *************/
    __mpu_sbrk( -(int)(2*np*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }

  eia_j = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eia_j )
  {
    /* fatal error */

    /* FREE eia_r *************/
    /* FREE eic_j *************/
    /* FREE eic_r *************/
    __mpu_sbrk( -(int)(3*np*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }

  eib_r = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eib_r )
  {
    /* fatal error */

    /* FREE eia_j *************/
    /* FREE eia_r *************/
    /* FREE eic_j *************/
    /* FREE eic_r *************/
    __mpu_sbrk( -(int)(4*np*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }

  eib_j = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eib_j )
  {
    /* fatal error */

    /* FREE eib_r *************/
    /* FREE eia_j *************/
    /* FREE eia_r *************/
    /* FREE eic_j *************/
    /* FREE eic_r *************/
    __mpu_sbrk( -(int)(5*np*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }
  /************************************************************/

  /*** Allocate memory for eitmp . ****************************/
  eitmp = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eitmp )
  {
    /* fatal error */

    /* FREE eib_j *************/
    /* FREE eib_r *************/
    /* FREE eia_j *************/
    /* FREE eia_r *************/
    /* FREE eic_j *************/
    /* FREE eic_r *************/
    __mpu_sbrk( -(int)(6*np*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }
  /************************************************************/

  /******************
    unpack IMAGINARY
   ******************/
#if MPU_WORD_ORDER_BIG_ENDIAN == 1
  pa += nb; /* point to imaginary */
  pb += nb;
#endif
  unpack( eia_j, (EMUSHORT *)pa, n_bits );
  unpack( eib_j, (EMUSHORT *)pb, n_bits );

  /******************
    unpack REAL_PART
   ******************/
#if MPU_WORD_ORDER_BIG_ENDIAN == 1
  pa -= nb; /* point to real_part */
  pb -= nb;
#else
  pa += nb; /* point to real_part */
  pb += nb;
#endif
  unpack( eia_r, (EMUSHORT *)pa, n_bits );
  unpack( eib_r, (EMUSHORT *)pb, n_bits );

  /* MUL complex numbers */
  /*
     (a+bi) * (c+di) = (a*c - b*d) + (a*d + b*c)i; 
   */
  ei_mul( eic_r, eia_r, eib_r, n_bits );
  ei_mul( eitmp, eia_j, eib_j, n_bits );
  ei_sub( eic_r, eic_r, eitmp, n_bits );

  ei_mul( eic_j, eia_r, eib_j, n_bits );
  ei_mul( eitmp, eia_j, eib_r, n_bits );
  ei_add( eic_j, eic_j, eitmp, n_bits );

  /****************
    pack IMAGINARY
   ****************/
#if MPU_WORD_ORDER_BIG_ENDIAN == 1
  pc += nb; /* point to imaginary */
#endif
  pack( (EMUSHORT *)pc, eic_j, n_bits );

  /****************
    pack REAL_PART
   ****************/
#if MPU_WORD_ORDER_BIG_ENDIAN == 1
  pc -= nb; /* point to real_part */
#else
  pc += nb; /* point to real_part */
#endif
  pack( (EMUSHORT *)pc, eic_r, n_bits );

  /* FREE eitmp *************/
  /* FREE eib_j *************/
  /* FREE eib_r *************/
  /* FREE eia_j *************/
  /* FREE eia_r *************/
  /* FREE eic_j *************/
  /* FREE eic_r *************/
  __mpu_sbrk( -(int)(7*np*SIZE_OF_EMUSHORT) );
  /**************************/

} /* End of c_mul() */


static void __complex_divide_by_zero( void )
{
  /* error: Complex attempted division by zero */
  struct __exception  e;

  __complex_error_no = __C_EDIVZEROBYZERO__;

  e.who          = _COMPLEX_;
  e.type         = __complex_error_no;
  e.name         = (__mpu_char8_t *)"c_div";
  e.msg          = __mpu_utf8mpu_error( _COMPLEX_, __complex_error_no );
  e.msg_type     = _ERROR_MSG_;
  e.nb_a1        = 0;
  e.nb_a2        = 0;
  e.nb_rv        = 0;
  e.arg_1        = (unsigned char *)0;
  e.arg_2        = (unsigned char *)0;
  e.return_value = (unsigned char *)0;

  if( __extra_warnings )
  {
    __mpu_warning( &e );
  }

  if( e.msg ) free( e.msg );

  return;

} /* End of __complex_divide_by_zero( void ) */

void c_div( mpu_complex *c, mpu_complex *a, mpu_complex *b, int nb )
{
  EMUSHORT *eic_r = NULL, *eic_j = NULL,
           *eia_r = NULL, *eia_j = NULL,
           *eib_r = NULL, *eib_j = NULL,
           *eitmp = NULL, *eiden = NULL,
           *zero  = NULL;
  mpu_real *pc, *pa, *pb;
  int       n_bits;
  int       np;

  errno           = 0;
  __real_error_no = 0;

  __CLEAR_RFLAGS;

  pa = a;
  pb = b;
  pc = c;

  n_bits = nb * BITS_PER_BYTE;

  np = internal_np( n_bits );

  /*** Allocate memory for eic_r, eic_j . *********************/
  eic_r = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eic_r )
  {
    /* fatal error */
    return;
  }

  eic_j = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eic_j )
  {
    /* fatal error */

    /* FREE eic_r *************/
    __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }
  /************************************************************/

  /*** Allocate memory for eia_r, eia_j, eib_r, eib_j . *******/
  eia_r = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eia_r )
  {
    /* fatal error */

    /* FREE eic_j *************/
    /* FREE eic_r *************/
    __mpu_sbrk( -(int)(2*np*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }

  eia_j = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eia_j )
  {
    /* fatal error */

    /* FREE eia_r *************/
    /* FREE eic_j *************/
    /* FREE eic_r *************/
    __mpu_sbrk( -(int)(3*np*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }

  eib_r = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eib_r )
  {
    /* fatal error */

    /* FREE eia_j *************/
    /* FREE eia_r *************/
    /* FREE eic_j *************/
    /* FREE eic_r *************/
    __mpu_sbrk( -(int)(4*np*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }

  eib_j = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eib_j )
  {
    /* fatal error */

    /* FREE eib_r *************/
    /* FREE eia_j *************/
    /* FREE eia_r *************/
    /* FREE eic_j *************/
    /* FREE eic_r *************/
    __mpu_sbrk( -(int)(5*np*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }
  /************************************************************/

  /*** Allocate memory for eitmp, eiden, zero . ***************/
  eitmp = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eitmp )
  {
    /* fatal error */

    /* FREE eib_j *************/
    /* FREE eib_r *************/
    /* FREE eia_j *************/
    /* FREE eia_r *************/
    /* FREE eic_j *************/
    /* FREE eic_r *************/
    __mpu_sbrk( -(int)(6*np*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }

  eiden = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eiden )
  {
    /* fatal error */

    /* FREE eitmp *************/
    /* FREE eib_j *************/
    /* FREE eib_r *************/
    /* FREE eia_j *************/
    /* FREE eia_r *************/
    /* FREE eic_j *************/
    /* FREE eic_r *************/
    __mpu_sbrk( -(int)(7*np*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }

  zero = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !zero )
  {
    /* fatal error */

    /* FREE eiden *************/
    /* FREE eitmp *************/
    /* FREE eib_j *************/
    /* FREE eib_r *************/
    /* FREE eia_j *************/
    /* FREE eia_r *************/
    /* FREE eic_j *************/
    /* FREE eic_r *************/
    __mpu_sbrk( -(int)(8*np*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }
  /************************************************************/

  _gen_zero( zero, n_bits );

  /******************
    unpack IMAGINARY
   ******************/
#if MPU_WORD_ORDER_BIG_ENDIAN == 1
  pa += nb; /* point to imaginary */
  pb += nb;
#endif
  unpack( eia_j, (EMUSHORT *)pa, n_bits );
  unpack( eib_j, (EMUSHORT *)pb, n_bits );

  /******************
    unpack REAL_PART
   ******************/
#if MPU_WORD_ORDER_BIG_ENDIAN == 1
  pa -= nb; /* point to real_part */
  pb -= nb;
#else
  pa += nb; /* point to real_part */
  pb += nb;
#endif
  unpack( eia_r, (EMUSHORT *)pa, n_bits );
  unpack( eib_r, (EMUSHORT *)pb, n_bits );

  /* DIVIDE complex numbers */
  /*
     hyp = c^2 + d^2;
     (a+bi) / (c+di) = (a*c + b*d)/hyp + (c*b - d*a)i; 
   */
  ei_mul( eiden, eib_r, eib_r, n_bits );
  ei_mul( eitmp, eib_j, eib_j, n_bits );
  ei_add( eiden, eiden, eitmp, n_bits ); /* den */

  /*****************************************************
    Если EIDEN == 0, результат будет неопределен (InD).
   *****************************************************/
  if( ei_cmp( eiden, zero, n_bits ) == 0 )
  {
    /*****************************************
      Выставление  InD  произойдет и без этих
      операторов, но переход сразу на packing
      сократит время работы этой функции.
     *****************************************/
    ei_ind( eic_r, n_bits );
    ei_ind( eic_j, n_bits );
    __complex_divide_by_zero();
    goto packing;

  } /* End if( ZERO/ZERO ) */

  ei_mul( eic_r, eia_r, eib_r, n_bits );
  ei_mul( eitmp, eia_j, eib_j, n_bits );
  ei_add( eic_r, eic_r, eitmp, n_bits ); /* (a*c + b*d) */
  ei_div( eic_r, eic_r, eiden, n_bits );

  ei_mul( eic_j, eib_r, eia_j, n_bits );
  ei_mul( eitmp, eib_j, eia_r, n_bits );
  ei_sub( eic_j, eic_j, eitmp, n_bits ); /* (c*b - d*a) */
  ei_div( eic_j, eic_j, eiden, n_bits );

packing:

  /****************
    pack IMAGINARY
   ****************/
#if MPU_WORD_ORDER_BIG_ENDIAN == 1
  pc += nb; /* point to imaginary */
#endif
  pack( (EMUSHORT *)pc, eic_j, n_bits );

  /****************
    pack REAL_PART
   ****************/
#if MPU_WORD_ORDER_BIG_ENDIAN == 1
  pc -= nb; /* point to real_part */
#else
  pc += nb; /* point to real_part */
#endif
  pack( (EMUSHORT *)pc, eic_r, n_bits );

  /* FREE zero **************/
  /* FREE eiden *************/
  /* FREE eitmp *************/
  /* FREE eib_j *************/
  /* FREE eib_r *************/
  /* FREE eia_j *************/
  /* FREE eia_r *************/
  /* FREE eic_j *************/
  /* FREE eic_r *************/
  __mpu_sbrk( -(int)(9*np*SIZE_OF_EMUSHORT) );
  /**************************/

} /* End of c_div() */


/***************************************************************
                 COMPLEX MATHEMATIC OPERATIONS
 ***************************************************************/

void c_exp( mpu_complex *y, mpu_complex *x, int nb )
/*
  The function returns the exponential of X.
 ********************************************/
{
  EMUSHORT *eiy_r = NULL, *eiy_j = NULL,
           *eix_r = NULL, *eix_j = NULL,
             *eir = NULL;
  mpu_real *py, *px;
  int       n_bits;
  int       np;

  errno           = 0;
  __real_error_no = 0;

  __CLEAR_RFLAGS;

  px = x;
  py = y;

  n_bits = nb * BITS_PER_BYTE;

  np = internal_np( n_bits );

  /*** Allocate memory for eiy_r, eiy_j, eix_r, eix_j . *******/
  eiy_r = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eiy_r )
  {
    /* fatal error */
    return;
  }

  eiy_j = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eiy_j )
  {
    /* fatal error */

    /* FREE eiy_r *************/
    __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }

  eix_r = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eix_r )
  {
    /* fatal error */

    /* FREE eiy_j *************/
    /* FREE eiy_r *************/
    __mpu_sbrk( -(int)(2*np*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }

  eix_j = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eix_j )
  {
    /* fatal error */

    /* FREE eix_r *************/
    /* FREE eiy_j *************/
    /* FREE eiy_r *************/
    __mpu_sbrk( -(int)(3*np*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }
  /************************************************************/

  /*** Allocate memory for eir . ******************************/
  eir = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eir )
  {
    /* fatal error */

    /* FREE eix_j *************/
    /* FREE eix_r *************/
    /* FREE eiy_j *************/
    /* FREE eiy_r *************/
    __mpu_sbrk( -(int)(4*np*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }
  /************************************************************/

  /******************
    unpack IMAGINARY
   ******************/
#if MPU_WORD_ORDER_BIG_ENDIAN == 1
  px += nb; /* point to imaginary */
#endif
  unpack( eix_j, (EMUSHORT *)px, n_bits );

  /******************
    unpack REAL_PART
   ******************/
#if MPU_WORD_ORDER_BIG_ENDIAN == 1
  px -= nb; /* point to real_part */
#else
  px += nb; /* point to real_part */
#endif
  unpack( eix_r, (EMUSHORT *)px, n_bits );

  /* EXP of a complex number */
  /*
    real r = exp( x.real );

    y.real = r * cos( x.imag );
    y.imag = r * sin( x.imag );
   */
  ei_exp( eir, eix_r, n_bits );
  ei_cos( eiy_r, eix_j, n_bits );
  ei_mul( eiy_r, eir, eiy_r, n_bits );
  ei_sin( eiy_j, eix_j, n_bits );
  ei_mul( eiy_j, eir, eiy_j, n_bits );

  /****************
    pack IMAGINARY
   ****************/
#if MPU_WORD_ORDER_BIG_ENDIAN == 1
  py += nb; /* point to imaginary */
#endif
  pack( (EMUSHORT *)py, eiy_j, n_bits );

  /****************
    pack REAL_PART
   ****************/
#if MPU_WORD_ORDER_BIG_ENDIAN == 1
  py -= nb; /* point to real_part */
#else
  py += nb; /* point to real_part */
#endif
  pack( (EMUSHORT *)py, eiy_r, n_bits );

  /* FREE eir ***************/
  /* FREE eix_j *************/
  /* FREE eix_r *************/
  /* FREE eiy_j *************/
  /* FREE eiy_r *************/
  __mpu_sbrk( -(int)(5*np*SIZE_OF_EMUSHORT) );
  /**************************/

} /* End of c_exp() */


void c_sin( mpu_complex *y, mpu_complex *x, int nb )
/*
  The function returns the imaginary sine of X.
 ***********************************************/
{
  EMUSHORT *eiy_r = NULL, *eiy_j = NULL,
           *eix_r = NULL, *eix_j = NULL,
             *eir = NULL,   *eij = NULL;
  mpu_real *py, *px;
  int       n_bits;
  int       np;

  errno           = 0;
  __real_error_no = 0;

  __CLEAR_RFLAGS;

  px = x;
  py = y;

  n_bits = nb * BITS_PER_BYTE;

  np = internal_np( n_bits );

  /*** Allocate memory for eiy_r, eiy_j, eix_r, eix_j . *******/
  eiy_r = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eiy_r )
  {
    /* fatal error */
    return;
  }

  eiy_j = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eiy_j )
  {
    /* fatal error */

    /* FREE eiy_r *************/
    __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }

  eix_r = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eix_r )
  {
    /* fatal error */

    /* FREE eiy_j *************/
    /* FREE eiy_r *************/
    __mpu_sbrk( -(int)(2*np*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }

  eix_j = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eix_j )
  {
    /* fatal error */

    /* FREE eix_r *************/
    /* FREE eiy_j *************/
    /* FREE eiy_r *************/
    __mpu_sbrk( -(int)(3*np*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }
  /************************************************************/

  /*** Allocate memory for eir, eij . *************************/
  eir = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eir )
  {
    /* fatal error */

    /* FREE eix_j *************/
    /* FREE eix_r *************/
    /* FREE eiy_j *************/
    /* FREE eiy_r *************/
    __mpu_sbrk( -(int)(4*np*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }

  eij = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eij )
  {
    /* fatal error */

    /* FREE eir ***************/
    /* FREE eix_j *************/
    /* FREE eix_r *************/
    /* FREE eiy_j *************/
    /* FREE eiy_r *************/
    __mpu_sbrk( -(int)(5*np*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }
  /************************************************************/

  /******************
    unpack IMAGINARY
   ******************/
#if MPU_WORD_ORDER_BIG_ENDIAN == 1
  px += nb; /* point to imaginary */
#endif
  unpack( eix_j, (EMUSHORT *)px, n_bits );

  /******************
    unpack REAL_PART
   ******************/
#if MPU_WORD_ORDER_BIG_ENDIAN == 1
  px -= nb; /* point to real_part */
#else
  px += nb; /* point to real_part */
#endif
  unpack( eix_r, (EMUSHORT *)px, n_bits );

  /* SIN of a complex number */
  /*
    y.real = sin( x.real ) * cosh( x.imag );
    y.imag = cos( x.real ) * sinh( x.imag );
   */
  ei_sin( eir, eix_r, n_bits );
  ei_cosh( eij, eix_j, n_bits );
  ei_mul( eiy_r, eir, eij, n_bits );
  ei_cos( eir, eix_r, n_bits );
  ei_sinh( eij, eix_j, n_bits );
  ei_mul( eiy_j, eir, eij, n_bits );

  /****************
    pack IMAGINARY
   ****************/
#if MPU_WORD_ORDER_BIG_ENDIAN == 1
  py += nb; /* point to imaginary */
#endif
  pack( (EMUSHORT *)py, eiy_j, n_bits );

  /****************
    pack REAL_PART
   ****************/
#if MPU_WORD_ORDER_BIG_ENDIAN == 1
  py -= nb; /* point to real_part */
#else
  py += nb; /* point to real_part */
#endif
  pack( (EMUSHORT *)py, eiy_r, n_bits );

  /* FREE eij ***************/
  /* FREE eir ***************/
  /* FREE eix_j *************/
  /* FREE eix_r *************/
  /* FREE eiy_j *************/
  /* FREE eiy_r *************/
  __mpu_sbrk( -(int)(6*np*SIZE_OF_EMUSHORT) );
  /**************************/

} /* End of c_sin() */


void c_cos( mpu_complex *y, mpu_complex *x, int nb )
/*
  The function returns the cosine of X.
 *******************************************/
{
  EMUSHORT *eiy_r = NULL, *eiy_j = NULL,
           *eix_r = NULL, *eix_j = NULL,
             *eir = NULL,   *eij = NULL;
  mpu_real *py, *px;
  int       n_bits;
  int       np;

  errno           = 0;
  __real_error_no = 0;

  __CLEAR_RFLAGS;

  px = x;
  py = y;

  n_bits = nb * BITS_PER_BYTE;

  np = internal_np( n_bits );

  /*** Allocate memory for eiy_r, eiy_j, eix_r, eix_j . *******/
  eiy_r = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eiy_r )
  {
    /* fatal error */
    return;
  }

  eiy_j = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eiy_j )
  {
    /* fatal error */

    /* FREE eiy_r *************/
    __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }

  eix_r = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eix_r )
  {
    /* fatal error */

    /* FREE eiy_j *************/
    /* FREE eiy_r *************/
    __mpu_sbrk( -(int)(2*np*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }

  eix_j = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eix_j )
  {
    /* fatal error */

    /* FREE eix_r *************/
    /* FREE eiy_j *************/
    /* FREE eiy_r *************/
    __mpu_sbrk( -(int)(3*np*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }
  /************************************************************/

  /*** Allocate memory for eir, eij . *************************/
  eir = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eir )
  {
    /* fatal error */

    /* FREE eix_j *************/
    /* FREE eix_r *************/
    /* FREE eiy_j *************/
    /* FREE eiy_r *************/
    __mpu_sbrk( -(int)(4*np*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }

  eij = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eij )
  {
    /* fatal error */

    /* FREE eir ***************/
    /* FREE eix_j *************/
    /* FREE eix_r *************/
    /* FREE eiy_j *************/
    /* FREE eiy_r *************/
    __mpu_sbrk( -(int)(5*np*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }
  /************************************************************/

  /******************
    unpack IMAGINARY
   ******************/
#if MPU_WORD_ORDER_BIG_ENDIAN == 1
  px += nb; /* point to imaginary */
#endif
  unpack( eix_j, (EMUSHORT *)px, n_bits );

  /******************
    unpack REAL_PART
   ******************/
#if MPU_WORD_ORDER_BIG_ENDIAN == 1
  px -= nb; /* point to real_part */
#else
  px += nb; /* point to real_part */
#endif
  unpack( eix_r, (EMUSHORT *)px, n_bits );

  /* COS of a complex number */
  /*
    y.real =  cos( x.real ) * cosh( x.imag );
    y.imag = -sin( x.real ) * sinh( x.imag );
   */
  ei_cos( eir, eix_r, n_bits );
  ei_cosh( eij, eix_j, n_bits );
  ei_mul( eiy_r, eir, eij, n_bits );
  ei_sin( eir, eix_r, n_bits );
  ei_neg( eir, n_bits );
  ei_sinh( eij, eix_j, n_bits );
  ei_mul( eiy_j, eir, eij, n_bits );

  /****************
    pack IMAGINARY
   ****************/
#if MPU_WORD_ORDER_BIG_ENDIAN == 1
  py += nb; /* point to imaginary */
#endif
  pack( (EMUSHORT *)py, eiy_j, n_bits );

  /****************
    pack REAL_PART
   ****************/
#if MPU_WORD_ORDER_BIG_ENDIAN == 1
  py -= nb; /* point to real_part */
#else
  py += nb; /* point to real_part */
#endif
  pack( (EMUSHORT *)py, eiy_r, n_bits );

  /* FREE eij ***************/
  /* FREE eir ***************/
  /* FREE eix_j *************/
  /* FREE eix_r *************/
  /* FREE eiy_j *************/
  /* FREE eiy_r *************/
  __mpu_sbrk( -(int)(6*np*SIZE_OF_EMUSHORT) );
  /**************************/

} /* End of c_cos() */


void c_sinh( mpu_complex *y, mpu_complex *x, int nb )
/*
  The function returns the hyperbolic sine of X.  
 ************************************************/
{
  EMUSHORT *eiy_r = NULL, *eiy_j = NULL,
           *eix_r = NULL, *eix_j = NULL,
             *eir = NULL,   *eij = NULL;
  mpu_real *py, *px;
  int       n_bits;
  int       np;

  errno           = 0;
  __real_error_no = 0;

  __CLEAR_RFLAGS;

  px = x;
  py = y;

  n_bits = nb * BITS_PER_BYTE;

  np = internal_np( n_bits );

  /*** Allocate memory for eiy_r, eiy_j, eix_r, eix_j . *******/
  eiy_r = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eiy_r )
  {
    /* fatal error */
    return;
  }

  eiy_j = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eiy_j )
  {
    /* fatal error */

    /* FREE eiy_r *************/
    __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }

  eix_r = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eix_r )
  {
    /* fatal error */

    /* FREE eiy_j *************/
    /* FREE eiy_r *************/
    __mpu_sbrk( -(int)(2*np*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }

  eix_j = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eix_j )
  {
    /* fatal error */

    /* FREE eix_r *************/
    /* FREE eiy_j *************/
    /* FREE eiy_r *************/
    __mpu_sbrk( -(int)(3*np*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }
  /************************************************************/

  /*** Allocate memory for eir, eij . *************************/
  eir = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eir )
  {
    /* fatal error */

    /* FREE eix_j *************/
    /* FREE eix_r *************/
    /* FREE eiy_j *************/
    /* FREE eiy_r *************/
    __mpu_sbrk( -(int)(4*np*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }

  eij = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eij )
  {
    /* fatal error */

    /* FREE eir ***************/
    /* FREE eix_j *************/
    /* FREE eix_r *************/
    /* FREE eiy_j *************/
    /* FREE eiy_r *************/
    __mpu_sbrk( -(int)(5*np*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }
  /************************************************************/

  /******************
    unpack IMAGINARY
   ******************/
#if MPU_WORD_ORDER_BIG_ENDIAN == 1
  px += nb; /* point to imaginary */
#endif
  unpack( eix_j, (EMUSHORT *)px, n_bits );

  /******************
    unpack REAL_PART
   ******************/
#if MPU_WORD_ORDER_BIG_ENDIAN == 1
  px -= nb; /* point to real_part */
#else
  px += nb; /* point to real_part */
#endif
  unpack( eix_r, (EMUSHORT *)px, n_bits );

  /* SINH of a complex number */
  /*
    y.real = cos( x.imag ) * sinh( x.real );
    y.imag = sin( x.imag ) * cosh( x.real );
   */
  ei_cos( eij, eix_j, n_bits );
  ei_sinh( eir, eix_r, n_bits );
  ei_mul( eiy_r, eij, eir, n_bits );
  ei_sin( eij, eix_j, n_bits );
  ei_cosh( eir, eix_r, n_bits );
  ei_mul( eiy_j, eij, eir, n_bits );

  /****************
    pack IMAGINARY
   ****************/
#if MPU_WORD_ORDER_BIG_ENDIAN == 1
  py += nb; /* point to imaginary */
#endif
  pack( (EMUSHORT *)py, eiy_j, n_bits );

  /****************
    pack REAL_PART
   ****************/
#if MPU_WORD_ORDER_BIG_ENDIAN == 1
  py -= nb; /* point to real_part */
#else
  py += nb; /* point to real_part */
#endif
  pack( (EMUSHORT *)py, eiy_r, n_bits );

  /* FREE eij ***************/
  /* FREE eir ***************/
  /* FREE eix_j *************/
  /* FREE eix_r *************/
  /* FREE eiy_j *************/
  /* FREE eiy_r *************/
  __mpu_sbrk( -(int)(6*np*SIZE_OF_EMUSHORT) );
  /**************************/

} /* End of c_sinh() */


void c_cosh( mpu_complex *y, mpu_complex *x, int nb )
/*
  The function returns the hyperbolic cosine of X.
 **************************************************/
{
  EMUSHORT *eiy_r = NULL, *eiy_j = NULL,
           *eix_r = NULL, *eix_j = NULL,
             *eir = NULL,   *eij = NULL;
  mpu_real *py, *px;
  int       n_bits;
  int       np;

  errno           = 0;
  __real_error_no = 0;

  __CLEAR_RFLAGS;

  px = x;
  py = y;

  n_bits = nb * BITS_PER_BYTE;

  np = internal_np( n_bits );

  /*** Allocate memory for eiy_r, eiy_j, eix_r, eix_j . *******/
  eiy_r = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eiy_r )
  {
    /* fatal error */
    return;
  }

  eiy_j = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eiy_j )
  {
    /* fatal error */

    /* FREE eiy_r *************/
    __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }

  eix_r = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eix_r )
  {
    /* fatal error */

    /* FREE eiy_j *************/
    /* FREE eiy_r *************/
    __mpu_sbrk( -(int)(2*np*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }

  eix_j = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eix_j )
  {
    /* fatal error */

    /* FREE eix_r *************/
    /* FREE eiy_j *************/
    /* FREE eiy_r *************/
    __mpu_sbrk( -(int)(3*np*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }
  /************************************************************/

  /*** Allocate memory for eir, eij . *************************/
  eir = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eir )
  {
    /* fatal error */

    /* FREE eix_j *************/
    /* FREE eix_r *************/
    /* FREE eiy_j *************/
    /* FREE eiy_r *************/
    __mpu_sbrk( -(int)(4*np*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }

  eij = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eij )
  {
    /* fatal error */

    /* FREE eir ***************/
    /* FREE eix_j *************/
    /* FREE eix_r *************/
    /* FREE eiy_j *************/
    /* FREE eiy_r *************/
    __mpu_sbrk( -(int)(5*np*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }
  /************************************************************/

  /******************
    unpack IMAGINARY
   ******************/
#if MPU_WORD_ORDER_BIG_ENDIAN == 1
  px += nb; /* point to imaginary */
#endif
  unpack( eix_j, (EMUSHORT *)px, n_bits );

  /******************
    unpack REAL_PART
   ******************/
#if MPU_WORD_ORDER_BIG_ENDIAN == 1
  px -= nb; /* point to real_part */
#else
  px += nb; /* point to real_part */
#endif
  unpack( eix_r, (EMUSHORT *)px, n_bits );

  /* COSH of a complex number */
  /*
    y.real = cos( x.imag ) * cosh( x.real );
    y.imag = sin( x.imag ) * sinh( x.real );
   */
  ei_cos( eij, eix_j, n_bits );
  ei_cosh( eir, eix_r, n_bits );
  ei_mul( eiy_r, eij, eir, n_bits );
  ei_sin( eij, eix_j, n_bits );
  ei_sinh( eir, eix_r, n_bits );
  ei_mul( eiy_j, eij, eir, n_bits );

  /****************
    pack IMAGINARY
   ****************/
#if MPU_WORD_ORDER_BIG_ENDIAN == 1
  py += nb; /* point to imaginary */
#endif
  pack( (EMUSHORT *)py, eiy_j, n_bits );

  /****************
    pack REAL_PART
   ****************/
#if MPU_WORD_ORDER_BIG_ENDIAN == 1
  py -= nb; /* point to real_part */
#else
  py += nb; /* point to real_part */
#endif
  pack( (EMUSHORT *)py, eiy_r, n_bits );

  /* FREE eij ***************/
  /* FREE eir ***************/
  /* FREE eix_j *************/
  /* FREE eix_r *************/
  /* FREE eiy_j *************/
  /* FREE eiy_r *************/
  __mpu_sbrk( -(int)(6*np*SIZE_OF_EMUSHORT) );
  /**************************/

} /* End of c_cosh() */


static void __complex_LOG_of_zero( void )
{
  /* error: Complex attempted LOG of zero magnitude number */
  struct __exception  e;

  __complex_error_no = __C_ELOGOFZERO__;

  e.who          = _COMPLEX_;
  e.type         = __complex_error_no;
  e.name         = (__mpu_char8_t *)"c_log";
  e.msg          = __mpu_utf8mpu_error( _COMPLEX_, __complex_error_no );
  e.msg_type     = _ERROR_MSG_;
  e.nb_a1        = 0;
  e.nb_a2        = 0;
  e.nb_rv        = 0;
  e.arg_1        = (unsigned char *)0;
  e.arg_2        = (unsigned char *)0;
  e.return_value = (unsigned char *)0;

  if( __extra_warnings )
  {
    __mpu_warning( &e );
  }

  if( e.msg ) free( e.msg );

  return;

} /* End of __complex_LOG_of_zero( void ) */

void c_log( mpu_complex *y, mpu_complex *x, int nb )
/*
  The function returns the logarithm of X.
  The branch cuts are along the negative real axis.
 ***************************************************/
{
  EMUSHORT *eiy_r = NULL, *eiy_j = NULL,
           *eix_r = NULL, *eix_j = NULL,
             *eir = NULL,   *eij = NULL,
            *zero = NULL,
             *eih = NULL;
  mpu_real *py, *px;
  int       n_bits;
  int       np;

  errno           = 0;
  __real_error_no = 0;

  __CLEAR_RFLAGS;

  px = x;
  py = y;

  n_bits = nb * BITS_PER_BYTE;

  np = internal_np( n_bits );

  /*** Allocate memory for eiy_r, eiy_j, eix_r, eix_j . *******/
  eiy_r = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eiy_r )
  {
    /* fatal error */
    return;
  }

  eiy_j = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eiy_j )
  {
    /* fatal error */

    /* FREE eiy_r *************/
    __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }

  eix_r = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eix_r )
  {
    /* fatal error */

    /* FREE eiy_j *************/
    /* FREE eiy_r *************/
    __mpu_sbrk( -(int)(2*np*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }

  eix_j = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eix_j )
  {
    /* fatal error */

    /* FREE eix_r *************/
    /* FREE eiy_j *************/
    /* FREE eiy_r *************/
    __mpu_sbrk( -(int)(3*np*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }
  /************************************************************/

  /*** Allocate memory for eir, eij . *************************/
  eir = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eir )
  {
    /* fatal error */

    /* FREE eix_j *************/
    /* FREE eix_r *************/
    /* FREE eiy_j *************/
    /* FREE eiy_r *************/
    __mpu_sbrk( -(int)(4*np*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }

  eij = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eij )
  {
    /* fatal error */

    /* FREE eir ***************/
    /* FREE eix_j *************/
    /* FREE eix_r *************/
    /* FREE eiy_j *************/
    /* FREE eiy_r *************/
    __mpu_sbrk( -(int)(5*np*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }
  /************************************************************/

  /*** Allocate memory for zero, eih . ************************/
  zero = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !zero )
  {
    /* fatal error */

    /* FREE eij ***************/
    /* FREE eir ***************/
    /* FREE eix_j *************/
    /* FREE eix_r *************/
    /* FREE eiy_j *************/
    /* FREE eiy_r *************/
    __mpu_sbrk( -(int)(6*np*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }

  eih = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eih )
  {
    /* fatal error */

    /* FREE zero **************/
    /* FREE eij ***************/
    /* FREE eir ***************/
    /* FREE eix_j *************/
    /* FREE eix_r *************/
    /* FREE eiy_j *************/
    /* FREE eiy_r *************/
    __mpu_sbrk( -(int)(7*np*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }
  /************************************************************/

  _gen_zero( zero, n_bits );

  /******************
    unpack IMAGINARY
   ******************/
#if MPU_WORD_ORDER_BIG_ENDIAN == 1
  px += nb; /* point to imaginary */
#endif
  unpack( eix_j, (EMUSHORT *)px, n_bits );

  /******************
    unpack REAL_PART
   ******************/
#if MPU_WORD_ORDER_BIG_ENDIAN == 1
  px -= nb; /* point to real_part */
#else
  px += nb; /* point to real_part */
#endif
  unpack( eix_r, (EMUSHORT *)px, n_bits );

  /* LOG of a complex number */
  /*
    real h = hypot( x.real, x.imag );

    if( h <= 0.0 )
      x.error("attempted LOG of zero magnitude number.");

    y.real = log( h );
    y.imag = atan2( x.imag, x.real );
   */
  ei_mul( eir, eix_r, eix_r, n_bits );
  ei_mul( eij, eix_j, eix_j, n_bits );
  ei_add( eih, eir, eij, n_bits );
  ei_sqrt( eih, eih, n_bits );         /* eih = hypot( eix_r, eix_j ); */

  if( ei_cmp( eih, zero, n_bits ) <= 0 )
  {
    /*****************************************
      Выставление -InF  произойдет и без этих
      операторов, но переход сразу на packing
      сократит время работы этой функции.
     *****************************************/
    ei_infin( eiy_r, (unsigned)1, n_bits );
    _gen_zero( eiy_j, n_bits );
    __complex_LOG_of_zero();
    goto packing;
  }

  ei_log( eiy_r, eih, n_bits );
  ei_atan2( eiy_j, eix_j, eix_r, n_bits );

packing:

  /****************
    pack IMAGINARY
   ****************/
#if MPU_WORD_ORDER_BIG_ENDIAN == 1
  py += nb; /* point to imaginary */
#endif
  pack( (EMUSHORT *)py, eiy_j, n_bits );

  /****************
    pack REAL_PART
   ****************/
#if MPU_WORD_ORDER_BIG_ENDIAN == 1
  py -= nb; /* point to real_part */
#else
  py += nb; /* point to real_part */
#endif
  pack( (EMUSHORT *)py, eiy_r, n_bits );

  /* FREE eih ***************/
  /* FREE zero **************/
  /* FREE eij ***************/
  /* FREE eir ***************/
  /* FREE eix_j *************/
  /* FREE eix_r *************/
  /* FREE eiy_j *************/
  /* FREE eiy_r *************/
  __mpu_sbrk( -(int)(8*np*SIZE_OF_EMUSHORT) );
  /**************************/

} /* End of c_log() */


static void __complex_POW_of_zero( void )
{
  /* error: Complex attempted POW of zero magnitude number */
  struct __exception  e;

  __complex_error_no = __C_EPOWOFZERO__;

  e.who          = _COMPLEX_;
  e.type         = __complex_error_no;
  e.name         = (__mpu_char8_t *)"c_pow";
  e.msg          = __mpu_utf8mpu_error( _COMPLEX_, __complex_error_no );
  e.msg_type     = _ERROR_MSG_;
  e.nb_a1        = 0;
  e.nb_a2        = 0;
  e.nb_rv        = 0;
  e.arg_1        = (unsigned char *)0;
  e.arg_2        = (unsigned char *)0;
  e.return_value = (unsigned char *)0;

  if( __extra_warnings )
  {
    __mpu_warning( &e );
  }

  if( e.msg ) free( e.msg );

  return;

} /* End of __complex_POW_of_zero( void ) */

void c_pow( mpu_complex *y, mpu_complex *x, mpu_complex *p, int nb )
/*
  The functions return the Y = X^P.
  The branch cut for x is along the negative real axis.
 *******************************************************/
{
  EMUSHORT *eiy_r = NULL, *eiy_j = NULL,
           *eix_r = NULL, *eix_j = NULL,
           *eip_r = NULL, *eip_j = NULL,
             *eir = NULL,   *eij = NULL,
            *eilr = NULL,  *eilj = NULL,
            *zero = NULL,
             *eih = NULL,   *eia = NULL;
  mpu_real *py, *px, *pp;
  int       n_bits;
  int       np;

  errno           = 0;
  __real_error_no = 0;

  __CLEAR_RFLAGS;

  pp = p;
  px = x;
  py = y;

  n_bits = nb * BITS_PER_BYTE;

  np = internal_np( n_bits );

  /*** Allocate memory for eiy_r, eiy_j, eix_r, eix_j . *******/
  eiy_r = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eiy_r )
  {
    /* fatal error */
    return;
  }

  eiy_j = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eiy_j )
  {
    /* fatal error */

    /* FREE eiy_r *************/
    __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }

  eix_r = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eix_r )
  {
    /* fatal error */

    /* FREE eiy_j *************/
    /* FREE eiy_r *************/
    __mpu_sbrk( -(int)(2*np*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }

  eix_j = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eix_j )
  {
    /* fatal error */

    /* FREE eix_r *************/
    /* FREE eiy_j *************/
    /* FREE eiy_r *************/
    __mpu_sbrk( -(int)(3*np*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }
  /************************************************************/

  /*** Allocate memory for eip_r, eip_j . *********************/
  eip_r = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eip_r )
  {
    /* fatal error */

    /* FREE eix_j *************/
    /* FREE eix_r *************/
    /* FREE eiy_j *************/
    /* FREE eiy_r *************/
    __mpu_sbrk( -(int)(4*np*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }

  eip_j = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eip_j )
  {
    /* fatal error */

    /* FREE eip_r *************/
    /* FREE eix_j *************/
    /* FREE eix_r *************/
    /* FREE eiy_j *************/
    /* FREE eiy_r *************/
    __mpu_sbrk( -(int)(5*np*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }
  /************************************************************/

  /*** Allocate memory for eir, eij . *************************/
  eir = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eir )
  {
    /* fatal error */

    /* FREE eip_j *************/
    /* FREE eip_r *************/
    /* FREE eix_j *************/
    /* FREE eix_r *************/
    /* FREE eiy_j *************/
    /* FREE eiy_r *************/
    __mpu_sbrk( -(int)(6*np*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }

  eij = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eij )
  {
    /* fatal error */

    /* FREE eir ***************/
    /* FREE eip_j *************/
    /* FREE eip_r *************/
    /* FREE eix_j *************/
    /* FREE eix_r *************/
    /* FREE eiy_j *************/
    /* FREE eiy_r *************/
    __mpu_sbrk( -(int)(7*np*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }
  /************************************************************/

  /*** Allocate memory for eilr, eilj . ***********************/
  eilr = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eilr )
  {
    /* fatal error */

    /* FREE eij ***************/
    /* FREE eir ***************/
    /* FREE eip_j *************/
    /* FREE eip_r *************/
    /* FREE eix_j *************/
    /* FREE eix_r *************/
    /* FREE eiy_j *************/
    /* FREE eiy_r *************/
    __mpu_sbrk( -(int)(8*np*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }

  eilj = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eilj )
  {
    /* fatal error */

    /* FREE eilr **************/
    /* FREE eij ***************/
    /* FREE eir ***************/
    /* FREE eip_j *************/
    /* FREE eip_r *************/
    /* FREE eix_j *************/
    /* FREE eix_r *************/
    /* FREE eiy_j *************/
    /* FREE eiy_r *************/
    __mpu_sbrk( -(int)(9*np*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }
  /************************************************************/

  /*** Allocate memory for zero, eih, eia . *******************/
  zero = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !zero )
  {
    /* fatal error */

    /* FREE eilj **************/
    /* FREE eilr **************/
    /* FREE eij ***************/
    /* FREE eir ***************/
    /* FREE eip_j *************/
    /* FREE eip_r *************/
    /* FREE eix_j *************/
    /* FREE eix_r *************/
    /* FREE eiy_j *************/
    /* FREE eiy_r *************/
    __mpu_sbrk( -(int)(10*np*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }

  eih = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eih )
  {
    /* fatal error */

    /* FREE zero **************/
    /* FREE eilj **************/
    /* FREE eilr **************/
    /* FREE eij ***************/
    /* FREE eir ***************/
    /* FREE eip_j *************/
    /* FREE eip_r *************/
    /* FREE eix_j *************/
    /* FREE eix_r *************/
    /* FREE eiy_j *************/
    /* FREE eiy_r *************/
    __mpu_sbrk( -(int)(11*np*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }

  eia = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eia )
  {
    /* fatal error */

    /* FREE eih ***************/
    /* FREE zero **************/
    /* FREE eilj **************/
    /* FREE eilr **************/
    /* FREE eij ***************/
    /* FREE eir ***************/
    /* FREE eip_j *************/
    /* FREE eip_r *************/
    /* FREE eix_j *************/
    /* FREE eix_r *************/
    /* FREE eiy_j *************/
    /* FREE eiy_r *************/
    __mpu_sbrk( -(int)(12*np*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }
  /************************************************************/

  _gen_zero( zero, n_bits );

  /******************
    unpack IMAGINARY
   ******************/
#if MPU_WORD_ORDER_BIG_ENDIAN == 1
  px += nb; /* point to imaginary */
  pp += nb;
#endif
  unpack( eix_j, (EMUSHORT *)px, n_bits );
  unpack( eip_j, (EMUSHORT *)pp, n_bits );

  /******************
    unpack REAL_PART
   ******************/
#if MPU_WORD_ORDER_BIG_ENDIAN == 1
  px -= nb; /* point to real_part */
  pp -= nb;
#else
  px += nb; /* point to real_part */
  pp += nb;
#endif
  unpack( eix_r, (EMUSHORT *)px, n_bits );
  unpack( eip_r, (EMUSHORT *)pp, n_bits );

  /* POW of a complex number */
  /*
    real h = hypot( x.real, x.imag );

    if( h <= 0.0 )
      x.error("attempted POWER of zero magnitude number.");

    real a  = atan2( x.imag, x.real );
    real lr = pow( h, p.real );
    real lj = p.real * a;

    if( p.imag != 0.0 )
    {
      lr /= exp( p.imag * a );
      lj += p.imag * log( h );
    }

    y.real = lr * cos( lj );
    y.imag = lr * sin( lj );
   */
  ei_mul( eir, eix_r, eix_r, n_bits );
  ei_mul( eij, eix_j, eix_j, n_bits );
  ei_add( eih, eir, eij, n_bits );
  ei_sqrt( eih, eih, n_bits );         /* eih = hypot( eix_r, eix_j ); */

  if( ei_cmp( eih, zero, n_bits ) <= 0 )
  {
    /*********************************************************
      В принципе выражение 0^0, как и выражение 0/0, неопределено.
      Но функции POW, в этом случае, возвращают 1.0 и мы не будем
      здесь принудительно выставлять значения
        eiy_r = 0.0,
        eiy_j = 0.0
      и переходить на упаковку, т.к. можем пропустить
      выражение 0^0.
      ==============
     *********************************************************/
    /* _gen_zero( eiy_j, n_bits ); */
    /* _gen_zero( eiy_j, n_bits ); */
    __complex_POW_of_zero();
    /* goto packing; */
    /*********************************************************
      Здесь POW( 0.0r0+0.0j0, 0.0r0+0.0j0 ) == 1.0r0+0.0j0;
     *********************************************************/
  }

  ei_atan2( eia, eix_j, eix_r, n_bits );
  ei_pow( eilr, eih, eip_r, n_bits );
  ei_mul( eilj, eip_r, eia, n_bits );

  if( ei_cmp( eip_j, zero, n_bits ) != 0 )
  {
    ei_mul( eir, eip_j, eia, n_bits );
    ei_exp( eir, eir, n_bits );
    ei_div( eilr, eilr, eir, n_bits ); /* lr /= exp( p.imag * a ); */

    ei_log( eij, eih, n_bits );
    ei_mul( eij, eip_j, eij, n_bits );
    ei_add( eilj, eilj, eij, n_bits ); /* lj += p.imag * log( h ); */
  }

  ei_cos( eir, eilj, n_bits );
  ei_mul( eiy_r, eilr, eir, n_bits );   /* y.real = lr * cos( lj ); */

  ei_sin( eij, eilj, n_bits );
  ei_mul( eiy_j, eilr, eij, n_bits );   /* y.imag = lr * sin( lj ); */

/* packing: */

  /****************
    pack IMAGINARY
   ****************/
#if MPU_WORD_ORDER_BIG_ENDIAN == 1
  py += nb; /* point to imaginary */
#endif
  pack( (EMUSHORT *)py, eiy_j, n_bits );

  /****************
    pack REAL_PART
   ****************/
#if MPU_WORD_ORDER_BIG_ENDIAN == 1
  py -= nb; /* point to real_part */
#else
  py += nb; /* point to real_part */
#endif
  pack( (EMUSHORT *)py, eiy_r, n_bits );

  /* FREE eia ***************/
  /* FREE eih ***************/
  /* FREE zero **************/
  /* FREE eilj **************/
  /* FREE eilr **************/
  /* FREE eij ***************/
  /* FREE eir ***************/
  /* FREE eip_j *************/
  /* FREE eip_r *************/
  /* FREE eix_j *************/
  /* FREE eix_r *************/
  /* FREE eiy_j *************/
  /* FREE eiy_r *************/
  __mpu_sbrk( -(int)(13*np*SIZE_OF_EMUSHORT) );
  /**************************/

} /* End of c_pow() */


void c_sqrt( mpu_complex *y, mpu_complex *x, int nb )
/*
  The function returns the square root of X, with
  phase angle in the half-open interval (-pi/2, pi/2].
  The branch cuts are along the negative real axis.
 ******************************************************/
{
  EMUSHORT *eiy_r = NULL, *eiy_j = NULL,
           *eix_r = NULL, *eix_j = NULL,
             *eir = NULL,   *eij = NULL,
            *zero = NULL,  *half = NULL,
             *eih = NULL;
  mpu_real *py, *px;
  int       n_bits;
  int       np;

  errno           = 0;
  __real_error_no = 0;

  __CLEAR_RFLAGS;

  px = x;
  py = y;

  n_bits = nb * BITS_PER_BYTE;

  np = internal_np( n_bits );

  /*** Allocate memory for eiy_r, eiy_j, eix_r, eix_j . *******/
  eiy_r = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eiy_r )
  {
    /* fatal error */
    return;
  }

  eiy_j = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eiy_j )
  {
    /* fatal error */

    /* FREE eiy_r *************/
    __mpu_sbrk( -(int)(np*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }

  eix_r = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eix_r )
  {
    /* fatal error */

    /* FREE eiy_j *************/
    /* FREE eiy_r *************/
    __mpu_sbrk( -(int)(2*np*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }

  eix_j = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eix_j )
  {
    /* fatal error */

    /* FREE eix_r *************/
    /* FREE eiy_j *************/
    /* FREE eiy_r *************/
    __mpu_sbrk( -(int)(3*np*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }
  /************************************************************/

  /*** Allocate memory for eir, eij . *************************/
  eir = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eir )
  {
    /* fatal error */

    /* FREE eix_j *************/
    /* FREE eix_r *************/
    /* FREE eiy_j *************/
    /* FREE eiy_r *************/
    __mpu_sbrk( -(int)(4*np*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }

  eij = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eij )
  {
    /* fatal error */

    /* FREE eir ***************/
    /* FREE eix_j *************/
    /* FREE eix_r *************/
    /* FREE eiy_j *************/
    /* FREE eiy_r *************/
    __mpu_sbrk( -(int)(5*np*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }
  /************************************************************/

  /*** Allocate memory for zero, half, eih . ******************/
  zero = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !zero )
  {
    /* fatal error */

    /* FREE eij ***************/
    /* FREE eir ***************/
    /* FREE eix_j *************/
    /* FREE eix_r *************/
    /* FREE eiy_j *************/
    /* FREE eiy_r *************/
    __mpu_sbrk( -(int)(6*np*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }

  half = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !half )
  {
    /* fatal error */

    /* FREE zero **************/
    /* FREE eij ***************/
    /* FREE eir ***************/
    /* FREE eix_j *************/
    /* FREE eix_r *************/
    /* FREE eiy_j *************/
    /* FREE eiy_r *************/
    __mpu_sbrk( -(int)(7*np*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }

  eih = (EMUSHORT *)__mpu_sbrk( (int)(np*SIZE_OF_EMUSHORT) );
  if( !eih )
  {
    /* fatal error */

    /* FREE half **************/
    /* FREE zero **************/
    /* FREE eij ***************/
    /* FREE eir ***************/
    /* FREE eix_j *************/
    /* FREE eix_r *************/
    /* FREE eiy_j *************/
    /* FREE eiy_r *************/
    __mpu_sbrk( -(int)(8*np*SIZE_OF_EMUSHORT) );
    /**************************/

    return;
  }
  /************************************************************/

  _gen_zero( zero, n_bits );
  _gen_half( half, n_bits );

  /******************
    unpack IMAGINARY
   ******************/
#if MPU_WORD_ORDER_BIG_ENDIAN == 1
  px += nb; /* point to imaginary */
#endif
  unpack( eix_j, (EMUSHORT *)px, n_bits );

  /******************
    unpack REAL_PART
   ******************/
#if MPU_WORD_ORDER_BIG_ENDIAN == 1
  px -= nb; /* point to real_part */
#else
  px += nb; /* point to real_part */
#endif
  unpack( eix_r, (EMUSHORT *)px, n_bits );

  /* SQRT of a complex number */
  /*
    if( x.real == 0.0 && x.imag == 0.0 )
    {
      y.real = 0.0;
      y.imag = 0.0;
    }
    else
    {
      real s = sqrt( (abs( x.real ) + hypot( x.real, x.imag )) * 0.5 );
      real d = ( x.imag / s ) * 0.5;

      if( x.real > 0.0 )
      {
        y.real = s;
        y.imag = d;
      }
      else if( x.imag >= 0.0 )
      {
        y.real = d;
        y.imag = s;
      }
      else
      {
        y.real = -d;
        y.imag = -s;
      }
    }
   */

  if( (ei_cmp( eix_r, zero, n_bits ) == 0) &&
      (ei_cmp( eix_j, zero, n_bits ) == 0)   )
  {
    _gen_zero( eiy_r, n_bits );
    _gen_zero( eiy_j, n_bits );
  }
  else
  {
    ei_mul( eir, eix_r, eix_r, n_bits );
    ei_mul( eij, eix_j, eix_j, n_bits );
    ei_add( eih, eir, eij, n_bits );
    ei_sqrt( eih, eih, n_bits );      /* eih = hypot( eix_r, eix_j ); */

    ei_copy( eir, eix_r, n_bits );
    ei_abs( eir, n_bits );            /* eir = abs( eix_r ); */

    ei_add( eir, eir, eih, n_bits );
    ei_mul( eir, eir, half, n_bits );
    ei_sqrt( eir, eir, n_bits );      /* s := eir; */

    ei_div( eij, eix_j, eir, n_bits );
    ei_mul( eij, eij, half, n_bits ); /* d := eij; */

    if( ei_cmp( eix_r, zero, n_bits ) >  0 )
    {
      ei_copy( eiy_r, eir, n_bits ); /* y.real =  s; */
      ei_copy( eiy_j, eij, n_bits ); /* y.imag =  d; */
    }
    else if( ei_cmp( eix_j, zero, n_bits ) >= 0 )
    {
      ei_copy( eiy_r, eij, n_bits ); /* y.real =  d; */
      ei_copy( eiy_j, eir, n_bits ); /* y.imag =  s; */
    }
    else
    {
      ei_neg( eir, n_bits );
      ei_neg( eij, n_bits );

      ei_copy( eiy_r, eij, n_bits ); /* y.real = -d; */
      ei_copy( eiy_j, eir, n_bits ); /* y.imag = -s; */
    }

  } /* End if( X != 0.0r0+0.0j0 ) */

  /****************
    pack IMAGINARY
   ****************/
#if MPU_WORD_ORDER_BIG_ENDIAN == 1
  py += nb; /* point to imaginary */
#endif
  pack( (EMUSHORT *)py, eiy_j, n_bits );

  /****************
    pack REAL_PART
   ****************/
#if MPU_WORD_ORDER_BIG_ENDIAN == 1
  py -= nb; /* point to real_part */
#else
  py += nb; /* point to real_part */
#endif
  pack( (EMUSHORT *)py, eiy_r, n_bits );

  /* FREE eih ***************/
  /* FREE half **************/
  /* FREE zero **************/
  /* FREE eij ***************/
  /* FREE eir ***************/
  /* FREE eix_j *************/
  /* FREE eix_r *************/
  /* FREE eiy_j *************/
  /* FREE eiy_r *************/
  __mpu_sbrk( -(int)(9*np*SIZE_OF_EMUSHORT) );
  /**************************/

} /* End of c_sqrt() */