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
author: kx <kx@radix-linux.su> 2024-12-20 16:11:07 +0300 committer: kx <kx@radix-linux.su> 2024-12-20 16:11:07 +0300 commit: 868b2b66b564b5c00e3a74d10be45db7151627ac parent: cce2ae8d3312493b7653358bb4af201d3271377b
Commit Summary:
Version 1.0.14
Diffstat:
1 file changed, 615 insertions, 0 deletions
diff --git a/mpu/mpu-floatp.c b/mpu/mpu-floatp.c
new file mode 100644
index 0000000..b2e0b52
--- /dev/null
+++ b/mpu/mpu-floatp.c
@@ -0,0 +1,714 @@
+
+/***************************************************************
+  __MPU_FLOATP.C
+
+       This file contains source code of functions for
+       REAL constants 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 <libmpu.h>
+#include <mpu-context.h>
+
+#include <mpu-emutype.h>
+#include <mpu-integer.h>
+#include <mpu-real.h>
+#include <mpu-floatp.h>
+
+#include <mpu-char.h>
+#include <mpu-symbols.h>
+
+#include <mpu-math-errno.h>
+#include <mpu-mtherr.h>
+
+
+#if MPU_WORD_ORDER_BIG_ENDIAN == 0
+#include <binexp/lbin_exp_emu32lsb.dfn>
+#else
+#include <binexp/lbin_exp_emu32msb.dfn>
+#endif
+
+#if MPU_WORD_ORDER_BIG_ENDIAN == 0
+#include <decexp/ldec_exp_emu32lsb.dfn>
+#else
+#include <decexp/ldec_exp_emu32msb.dfn>
+#endif
+
+#if MPU_WORD_ORDER_BIG_ENDIAN == 0
+#include <epsilon/ei_epsilon_emu32lsb.dfn>
+#else
+#include <epsilon/ei_epsilon_emu32msb.dfn>
+#endif
+
+
+/***************************************************************
+  LIMITS for DECIMAL Exponent of all
+  Internal e-type data struct.
+
+    SIZE of CONSTANTS == nE+1.
+                nE  = (int)internalNE( nb );
+                nb  - number of bits of external
+                      e-type number.
+ ***************************************************************/
+
+EMUSHORT *_get_maxdecexp_ptr( int nb )
+{
+  EMUSHORT *rc = (EMUSHORT *)NULL;
+
+  switch( nb )
+  {
+    case NBR_32    :
+    case NBR_64    :
+    case NBR_128   :
+      rc = (EMUSHORT *)&_max_dec_exp_128_[0];
+      break;
+    case NBR_256   :
+      rc = (EMUSHORT *)&_max_dec_exp_256_[0];
+      break;
+    case NBR_512   :
+      rc = (EMUSHORT *)&_max_dec_exp_512_[0];
+      break;
+    case NBR_1024  :
+      rc = (EMUSHORT *)&_max_dec_exp_1024_[0];
+      break;
+    case NBR_2048  :
+      rc = (EMUSHORT *)&_max_dec_exp_2048_[0];
+      break;
+    case NBR_4096  :
+      rc = (EMUSHORT *)&_max_dec_exp_4096_[0];
+      break;
+    case NBR_8192  :
+      rc = (EMUSHORT *)&_max_dec_exp_8192_[0];
+      break;
+    case NBR_16384 :
+      rc = (EMUSHORT *)&_max_dec_exp_16384_[0];
+      break;
+    case NBR_32768 :
+      rc = (EMUSHORT *)&_max_dec_exp_32768_[0];
+      break;
+    case NBR_65536 :
+      rc = (EMUSHORT *)&_max_dec_exp_65536_[0];
+      break;
+    case NBR_131072:
+      rc = (EMUSHORT *)&_max_dec_exp_131072_[0];
+      break;
+
+    default:
+    {
+      /* error: Invalid size of operand(s) */
+      __real_error_no = __R_ESIZE__;
+      __STIND; /* Set REAL ind-produsing operation Flag */
+      break;
+    }
+
+  } /* End of switch( nb ) */
+
+  return( rc );
+
+} /* End of _get_maxdecexp_ptr() */
+
+
+EMUSHORT *_get_mindecexp_ptr( int nb )
+{
+  EMUSHORT *rc = (EMUSHORT *)NULL;
+
+  switch( nb )
+  {
+    case NBR_32    :
+    case NBR_64    :
+    case NBR_128   :
+      rc = (EMUSHORT *)&_min_dec_exp_128_[0];
+      break;
+    case NBR_256   :
+      rc = (EMUSHORT *)&_min_dec_exp_256_[0];
+      break;
+    case NBR_512   :
+      rc = (EMUSHORT *)&_min_dec_exp_512_[0];
+      break;
+    case NBR_1024  :
+      rc = (EMUSHORT *)&_min_dec_exp_1024_[0];
+      break;
+    case NBR_2048  :
+      rc = (EMUSHORT *)&_min_dec_exp_2048_[0];
+      break;
+    case NBR_4096  :
+      rc = (EMUSHORT *)&_min_dec_exp_4096_[0];
+      break;
+    case NBR_8192  :
+      rc =  (EMUSHORT *)&_min_dec_exp_8192_[0];
+      break;
+    case NBR_16384 :
+      rc = (EMUSHORT *)&_min_dec_exp_16384_[0];
+      break;
+    case NBR_32768 :
+      rc = (EMUSHORT *)&_min_dec_exp_32768_[0];
+      break;
+    case NBR_65536 :
+      rc = (EMUSHORT *)&_min_dec_exp_65536_[0];
+      break;
+    case NBR_131072:
+      rc = (EMUSHORT *)&_min_dec_exp_131072_[0];
+      break;
+
+    default:
+    {
+      /* error: Invalid size of operand(s) */
+      __real_error_no = __R_ESIZE__;
+      __STIND; /* Set REAL ind-produsing operation Flag */
+      break;
+    }
+
+  } /* End of switch( nb ) */
+
+  return( rc );
+
+} /* End of _get_mindecexp_ptr() */
+
+
+EMUSHORT *_get_max_10_exp_ptr( int nb )
+{
+  EMUSHORT *rc = (EMUSHORT *)NULL;
+
+  switch( nb )
+  {
+    case NBR_32    :
+      rc = (EMUSHORT *)&_max_dec_exp_32_[0];
+      break;
+    case NBR_64    :
+      rc = (EMUSHORT *)&_max_dec_exp_64_[0];
+      break;
+    case NBR_128   :
+      rc = (EMUSHORT *)&_max_dec_exp_128_[0];
+      break;
+    case NBR_256   :
+      rc = (EMUSHORT *)&_max_dec_exp_256_[0];
+      break;
+    case NBR_512   :
+      rc = (EMUSHORT *)&_max_dec_exp_512_[0];
+      break;
+    case NBR_1024  :
+      rc = (EMUSHORT *)&_max_dec_exp_1024_[0];
+      break;
+    case NBR_2048  :
+      rc = (EMUSHORT *)&_max_dec_exp_2048_[0];
+      break;
+    case NBR_4096  :
+      rc = (EMUSHORT *)&_max_dec_exp_4096_[0];
+      break;
+    case NBR_8192  :
+      rc = (EMUSHORT *)&_max_dec_exp_8192_[0];
+      break;
+    case NBR_16384 :
+      rc = (EMUSHORT *)&_max_dec_exp_16384_[0];
+      break;
+    case NBR_32768 :
+      rc = (EMUSHORT *)&_max_dec_exp_32768_[0];
+      break;
+    case NBR_65536 :
+      rc = (EMUSHORT *)&_max_dec_exp_65536_[0];
+      break;
+    case NBR_131072:
+      rc = (EMUSHORT *)&_max_dec_exp_131072_[0];
+      break;
+
+    default:
+    {
+      /* error: Invalid size of operand(s) */
+      __real_error_no = __R_ESIZE__;
+      __STIND; /* Set REAL ind-produsing operation Flag */
+      break;
+    }
+
+  } /* End of switch( nb ) */
+
+  return( rc );
+
+} /* End of _get_max_10_exp_ptr() */
+
+
+EMUSHORT *_get_min_10_exp_ptr( int nb )
+{
+  EMUSHORT *rc = (EMUSHORT *)NULL;
+
+  switch( nb )
+  {
+    case NBR_32    :
+      rc = (EMUSHORT *)&_min_dec_exp_32_[0];
+      break;
+    case NBR_64    :
+      rc = (EMUSHORT *)&_min_dec_exp_64_[0];
+      break;
+    case NBR_128   :
+      rc = (EMUSHORT *)&_min_dec_exp_128_[0];
+      break;
+    case NBR_256   :
+      rc = (EMUSHORT *)&_min_dec_exp_256_[0];
+      break;
+    case NBR_512   :
+      rc = (EMUSHORT *)&_min_dec_exp_512_[0];
+      break;
+    case NBR_1024  :
+      rc = (EMUSHORT *)&_min_dec_exp_1024_[0];
+      break;
+    case NBR_2048  :
+      rc = (EMUSHORT *)&_min_dec_exp_2048_[0];
+      break;
+    case NBR_4096  :
+      rc = (EMUSHORT *)&_min_dec_exp_4096_[0];
+      break;
+    case NBR_8192  :
+      rc = (EMUSHORT *)&_min_dec_exp_8192_[0];
+      break;
+    case NBR_16384 :
+      rc = (EMUSHORT *)&_min_dec_exp_16384_[0];
+      break;
+    case NBR_32768 :
+      rc = (EMUSHORT *)&_min_dec_exp_32768_[0];
+      break;
+    case NBR_65536 :
+      rc = (EMUSHORT *)&_min_dec_exp_65536_[0];
+      break;
+    case NBR_131072:
+      rc = (EMUSHORT *)&_min_dec_exp_131072_[0];
+      break;
+
+    default:
+    {
+      /* error: Invalid size of operand(s) */
+      __real_error_no = __R_ESIZE__;
+      __STIND; /* Set REAL ind-produsing operation Flag */
+      break;
+    }
+
+  } /* End of switch( nb ) */
+
+  return( rc );
+
+} /* End of _get_min_10_exp_ptr() */
+
+
+/***************************************************************
+  LIMITS for BINARY Exponent of all
+  Internal e-type data struct.
+
+    SIZE of CONSTANTS == nE+1.
+                nE  = (int)internalNE( nb );
+                nb  - number of bits of external
+                      e-type number.
+ ***************************************************************/
+
+EMUSHORT *_get_max_max_2_exp_ptr( int nb )
+{
+  EMUSHORT *rc = (EMUSHORT *)NULL;
+
+  switch( nb )
+  {
+    case NBR_32    :
+      rc = (EMUSHORT *)&_max_max_bin_exp_32_[0];
+      break;
+    case NBR_64    :
+      rc = (EMUSHORT *)&_max_max_bin_exp_64_[0];
+      break;
+    case NBR_128   :
+      rc = (EMUSHORT *)&_max_max_bin_exp_128_[0];
+      break;
+    case NBR_256   :
+      rc = (EMUSHORT *)&_max_max_bin_exp_256_[0];
+      break;
+    case NBR_512   :
+      rc = (EMUSHORT *)&_max_max_bin_exp_512_[0];
+      break;
+    case NBR_1024  :
+      rc = (EMUSHORT *)&_max_max_bin_exp_1024_[0];
+      break;
+    case NBR_2048  :
+      rc = (EMUSHORT *)&_max_max_bin_exp_2048_[0];
+      break;
+    case NBR_4096  :
+      rc = (EMUSHORT *)&_max_max_bin_exp_4096_[0];
+      break;
+    case NBR_8192  :
+      rc = (EMUSHORT *)&_max_max_bin_exp_8192_[0];
+      break;
+    case NBR_16384 :
+      rc = (EMUSHORT *)&_max_max_bin_exp_16384_[0];
+      break;
+    case NBR_32768 :
+      rc = (EMUSHORT *)&_max_max_bin_exp_32768_[0];
+      break;
+    case NBR_65536 :
+      rc = (EMUSHORT *)&_max_max_bin_exp_65536_[0];
+      break;
+    case NBR_131072:
+      rc = (EMUSHORT *)&_max_max_bin_exp_131072_[0];
+      break;
+
+    default:
+    {
+      /* error: Invalid size of operand(s) */
+      __real_error_no = __R_ESIZE__;
+      __STIND; /* Set REAL ind-produsing operation Flag */
+      break;
+    }
+
+  } /* End of switch( nb ) */
+
+  return( rc );
+
+} /* End of _get_max_max_2_exp_ptr() */
+
+
+EMUSHORT *_get_max_2_exp_ptr( int nb )
+{
+  EMUSHORT *rc = (EMUSHORT *)NULL;
+
+  switch( nb )
+  {
+    case NBR_32    :
+      rc = (EMUSHORT *)&_max_bin_exp_32_[0];
+      break;
+    case NBR_64    :
+      rc = (EMUSHORT *)&_max_bin_exp_64_[0];
+      break;
+    case NBR_128   :
+      rc = (EMUSHORT *)&_max_bin_exp_128_[0];
+      break;
+    case NBR_256   :
+      rc = (EMUSHORT *)&_max_bin_exp_256_[0];
+      break;
+    case NBR_512   :
+      rc = (EMUSHORT *)&_max_bin_exp_512_[0];
+      break;
+    case NBR_1024  :
+      rc = (EMUSHORT *)&_max_bin_exp_1024_[0];
+      break;
+    case NBR_2048  :
+      rc = (EMUSHORT *)&_max_bin_exp_2048_[0];
+      break;
+    case NBR_4096  :
+      rc = (EMUSHORT *)&_max_bin_exp_4096_[0];
+      break;
+    case NBR_8192  :
+      rc = (EMUSHORT *)&_max_bin_exp_8192_[0];
+      break;
+    case NBR_16384 :
+      rc = (EMUSHORT *)&_max_bin_exp_16384_[0];
+      break;
+    case NBR_32768 :
+      rc = (EMUSHORT *)&_max_bin_exp_32768_[0];
+      break;
+    case NBR_65536 :
+      rc = (EMUSHORT *)&_max_bin_exp_65536_[0];
+      break;
+    case NBR_131072:
+      rc = (EMUSHORT *)&_max_bin_exp_131072_[0];
+      break;
+
+    default:
+    {
+      /* error: Invalid size of operand(s) */
+      __real_error_no = __R_ESIZE__;
+      __STIND; /* Set REAL ind-produsing operation Flag */
+      break;
+    }
+
+  } /* End of switch( nb ) */
+
+  return( rc );
+
+} /* End of _get_max_2_exp_ptr() */
+
+
+EMUSHORT *_get_min_2_exp_ptr( int nb )
+{
+  EMUSHORT *rc = (EMUSHORT *)NULL;
+
+  switch( nb )
+  {
+    case NBR_32    :
+      rc = (EMUSHORT *)&_min_bin_exp_32_[0];
+      break;
+    case NBR_64    :
+      rc = (EMUSHORT *)&_min_bin_exp_64_[0];
+      break;
+    case NBR_128   :
+      rc = (EMUSHORT *)&_min_bin_exp_128_[0];
+      break;
+    case NBR_256   :
+      rc = (EMUSHORT *)&_min_bin_exp_256_[0];
+      break;
+    case NBR_512   :
+      rc = (EMUSHORT *)&_min_bin_exp_512_[0];
+      break;
+    case NBR_1024  :
+      rc = (EMUSHORT *)&_min_bin_exp_1024_[0];
+      break;
+    case NBR_2048  :
+      rc = (EMUSHORT *)&_min_bin_exp_2048_[0];
+      break;
+    case NBR_4096  :
+      rc = (EMUSHORT *)&_min_bin_exp_4096_[0];
+      break;
+    case NBR_8192  :
+      rc = (EMUSHORT *)&_min_bin_exp_8192_[0];
+      break;
+    case NBR_16384 :
+      rc = (EMUSHORT *)&_min_bin_exp_16384_[0];
+      break;
+    case NBR_32768 :
+      rc = (EMUSHORT *)&_min_bin_exp_32768_[0];
+      break;
+    case NBR_65536 :
+      rc = (EMUSHORT *)&_min_bin_exp_65536_[0];
+      break;
+    case NBR_131072:
+      rc = (EMUSHORT *)&_min_bin_exp_131072_[0];
+      break;
+
+    default:
+    {
+      /* error: Invalid size of operand(s) */
+      __real_error_no = __R_ESIZE__;
+      __STIND; /* Set REAL ind-produsing operation Flag */
+      break;
+    }
+
+  } /* End of switch( nb ) */
+
+  return( rc );
+
+} /* End of _get_min_2_exp_ptr() */
+
+
+int _get_ndec( int nb )
+/*****************************************
+  Количество десятичных знаков в мантиссе
+ *****************************************/
+{
+  int  rc = 0;
+
+  switch( nb )
+  {
+    case NBR_32    :
+      rc = REAL_32_MDEC_DIG;
+      break;
+    case NBR_64    :
+      rc = REAL_64_MDEC_DIG;
+      break;
+    case NBR_128   :
+      rc = REAL_128_MDEC_DIG;
+      break;
+    case NBR_256   :
+      rc = REAL_256_MDEC_DIG;
+      break;
+    case NBR_512   :
+      rc = REAL_512_MDEC_DIG;
+      break;
+    case NBR_1024  :
+      rc = REAL_1024_MDEC_DIG;
+      break;
+    case NBR_2048  :
+      rc = REAL_2048_MDEC_DIG;
+      break;
+    case NBR_4096  :
+      rc = REAL_4096_MDEC_DIG;
+      break;
+    case NBR_8192  :
+      rc = REAL_8192_MDEC_DIG;
+      break;
+    case NBR_16384 :
+      rc = REAL_16384_MDEC_DIG;
+      break;
+    case NBR_32768 :
+      rc = REAL_32768_MDEC_DIG;
+      break;
+    case NBR_65536 :
+      rc = REAL_65536_MDEC_DIG;
+      break;
+    case NBR_131072:
+      rc = REAL_131072_MDEC_DIG;
+      break;
+
+    default:
+    {
+      /* error: Invalid size of operand(s) */
+      __real_error_no = __R_ESIZE__;
+      __STIND; /* Set REAL ind-produsing operation Flag */
+      break;
+    }
+
+  } /* End of switch( nb ) */
+
+  return( rc );
+
+} /* End of _get_ndec() */
+
+
+int _get_max_string( int nb )
+/***************************************************
+  Максимальное количество десятичных знаков в числе
+ ***************************************************/
+{
+  int  rc = 0;
+
+  switch( nb )
+  {
+    case NBR_32    :
+      rc = REAL_32_MAX_STRING;
+      break;
+    case NBR_64    :
+      rc = REAL_64_MAX_STRING;
+      break;
+    case NBR_128   :
+      rc = REAL_128_MAX_STRING;
+      break;
+    case NBR_256   :
+      rc = REAL_256_MAX_STRING;
+      break;
+    case NBR_512   :
+      rc = REAL_512_MAX_STRING;
+      break;
+    case NBR_1024  :
+      rc = REAL_1024_MAX_STRING;
+      break;
+    case NBR_2048  :
+      rc = REAL_2048_MAX_STRING;
+      break;
+    case NBR_4096  :
+      rc = REAL_4096_MAX_STRING;
+      break;
+    case NBR_8192  :
+      rc = REAL_8192_MAX_STRING;
+      break;
+    case NBR_16384 :
+      rc = REAL_16384_MAX_STRING;
+      break;
+    case NBR_32768 :
+      rc = REAL_32768_MAX_STRING;
+      break;
+    case NBR_65536 :
+      rc = REAL_65536_MAX_STRING;
+      break;
+    case NBR_131072:
+      rc = REAL_131072_MAX_STRING;
+      break;
+
+    default:
+    {
+      /* error: Invalid size of operand(s) */
+      __real_error_no = __R_ESIZE__;
+      __STIND; /* Set REAL ind-produsing operation Flag */
+      break;
+    }
+
+  } /* End of switch( nb ) */
+
+  return( rc );
+
+} /* End of _get_max_string() */
+
+
+/***************************************************************
+  EPSILONs for all Internal e-type data struct.
+  EPSILON is smallest such that 1.0+EPSILON != 1.0.
+ ***************************************************************/
+
+EMUSHORT *_get_epsilon_ptr( int nb )
+{
+  EMUSHORT *rc = (EMUSHORT *)NULL;
+
+  switch( nb )
+  {
+    case NBR_32    :
+      rc = (EMUSHORT *)&_ei_epsilon_32_[0];
+      break;
+    case NBR_64    :
+      rc = (EMUSHORT *)&_ei_epsilon_64_[0];
+      break;
+    case NBR_128   :
+      rc = (EMUSHORT *)&_ei_epsilon_128_[0];
+      break;
+    case NBR_256   :
+      rc = (EMUSHORT *)&_ei_epsilon_256_[0];
+      break;
+    case NBR_512   :
+      rc = (EMUSHORT *)&_ei_epsilon_512_[0];
+      break;
+    case NBR_1024  :
+      rc = (EMUSHORT *)&_ei_epsilon_1024_[0];
+      break;
+    case NBR_2048  :
+      rc = (EMUSHORT *)&_ei_epsilon_2048_[0];
+      break;
+    case NBR_4096  :
+      rc = (EMUSHORT *)&_ei_epsilon_4096_[0];
+      break;
+    case NBR_8192  :
+      rc = (EMUSHORT *)&_ei_epsilon_8192_[0];
+      break;
+    case NBR_16384 :
+      rc = (EMUSHORT *)&_ei_epsilon_16384_[0];
+      break;
+    case NBR_32768 :
+      rc = (EMUSHORT *)&_ei_epsilon_32768_[0];
+      break;
+    case NBR_65536 :
+      rc = (EMUSHORT *)&_ei_epsilon_65536_[0];
+      break;
+    case NBR_131072:
+      rc = (EMUSHORT *)&_ei_epsilon_131072_[0];
+      break;
+
+    default:
+    {
+      /* error: Invalid size of operand(s) */
+      __real_error_no = __R_ESIZE__;
+      __STIND; /* Set REAL ind-produsing operation Flag */
+      break;
+    }
+
+  } /* End of switch( nb ) */
+
+  return( rc );
+
+} /* End of _get_epsilon_ptr() */
+
+
+
+/***************************************************************
+  Hide internal symbols:
+ ***************************************************************/
+
+__mpu_hidden_decl(_get_maxdecexp_ptr);
+__mpu_hidden_decl(_get_mindecexp_ptr);
+__mpu_hidden_decl(_get_max_10_exp_ptr);
+__mpu_hidden_decl(_get_min_10_exp_ptr);
+__mpu_hidden_decl(_get_max_max_2_exp_ptr);
+__mpu_hidden_decl(_get_max_2_exp_ptr);
+__mpu_hidden_decl(_get_min_2_exp_ptr);
+
+__mpu_hidden_decl(_get_ndec);
+__mpu_hidden_decl(_get_max_string);
+
+__mpu_hidden_decl(_get_epsilon_ptr);
+
+
+/*
+  End of hide internal symbols.
+ ***************************************************************/