"Fossies" - the Fresh Open Source Software Archive

Member "mapm_4.9.5a/mapmcnst.c" (21 Feb 2010, 12635 Bytes) of package /linux/misc/old/mapm-4.9.5a.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "mapmcnst.c" see the Fossies "Dox" file reference documentation.

    1 
    2 /* 
    3  *  M_APM  -  mapmcnst.c
    4  *
    5  *  Copyright (C) 1999 - 2007   Michael C. Ring
    6  *
    7  *  Permission to use, copy, and distribute this software and its
    8  *  documentation for any purpose with or without fee is hereby granted,
    9  *  provided that the above copyright notice appear in all copies and
   10  *  that both that copyright notice and this permission notice appear
   11  *  in supporting documentation.
   12  *
   13  *  Permission to modify the software is granted. Permission to distribute
   14  *  the modified code is granted. Modifications are to be distributed by
   15  *  using the file 'license.txt' as a template to modify the file header.
   16  *  'license.txt' is available in the official MAPM distribution.
   17  *
   18  *  This software is provided "as is" without express or implied warranty.
   19  */
   20 
   21 /*
   22  *      $Id: mapmcnst.c,v 1.24 2007/12/03 01:51:16 mike Exp $
   23  *
   24  *      This file contains declarations and initializes the constants 
   25  *  used throughout the library.
   26  *
   27  *      $Log: mapmcnst.c,v $
   28  *      Revision 1.24  2007/12/03 01:51:16  mike
   29  *      Update license
   30  *
   31  *      Revision 1.23  2003/05/06 21:28:53  mike
   32  *      add lib version functions
   33  *
   34  *      Revision 1.22  2003/03/30 21:14:16  mike
   35  *      add local copies of log(2) and log(10)
   36  *
   37  *      Revision 1.21  2002/11/03 22:45:29  mike
   38  *      Updated function parameters to use the modern style
   39  *
   40  *      Revision 1.20  2002/05/17 22:40:25  mike
   41  *      call m_apm_init from cpp_precision to init the library
   42  *      if it hasn't been done yet.
   43  *
   44  *      Revision 1.19  2001/07/16 19:40:12  mike
   45  *      add function M_free_all_cnst
   46  *
   47  *      Revision 1.18  2001/02/07 19:17:58  mike
   48  *      eliminate MM_skip_limit_PI_check
   49  *
   50  *      Revision 1.17  2000/05/19 16:31:02  mike
   51  *      add local copies for PI variables
   52  *
   53  *      Revision 1.16  2000/05/04 23:52:03  mike
   54  *      added new constant, 256R.
   55  *      renamed _008 to _125R
   56  *
   57  *      Revision 1.15  2000/04/11 18:44:21  mike
   58  *      no longer need the constant 'Fifteen'
   59  *
   60  *      Revision 1.14  2000/04/05 20:12:53  mike
   61  *      add C++ min precision function
   62  *
   63  *      Revision 1.13  1999/07/09 22:47:48  mike
   64  *      add skip limit PI check
   65  *
   66  *      Revision 1.12  1999/07/08 23:34:50  mike
   67  *      change constant
   68  *
   69  *      Revision 1.11  1999/07/08 22:58:08  mike
   70  *      add new constant
   71  *
   72  *      Revision 1.10  1999/06/23 01:09:53  mike
   73  *      added new constant 15
   74  *
   75  *      Revision 1.9  1999/06/20 23:32:30  mike
   76  *      added new constants
   77  *
   78  *      Revision 1.8  1999/06/20 19:24:14  mike
   79  *      delete constants no longer needed
   80  *
   81  *      Revision 1.7  1999/06/20 18:57:29  mike
   82  *      fixed missing init for new constants
   83  *
   84  *      Revision 1.6  1999/06/20 18:53:44  mike
   85  *      added more constants
   86  *
   87  *      Revision 1.5  1999/05/31 23:50:30  mike
   88  *      delete constants no longer needed
   89  *
   90  *      Revision 1.4  1999/05/14 19:50:22  mike
   91  *      added more constants with more digits
   92  *
   93  *      Revision 1.3  1999/05/12 20:53:08  mike
   94  *      added more constants
   95  *
   96  *      Revision 1.2  1999/05/10 21:52:24  mike
   97  *      added some comments
   98  *
   99  *      Revision 1.1  1999/05/10 20:56:31  mike
  100  *      Initial revision
  101  */
  102 
  103 #include "m_apm_lc.h"
  104 
  105 int MM_lc_PI_digits = 0;
  106 int MM_lc_log_digits;
  107 int     MM_cpp_min_precision;       /* only used in C++ wrapper */
  108 
  109 M_APM   MM_Zero          = NULL;
  110 M_APM   MM_One           = NULL;
  111 M_APM   MM_Two           = NULL;
  112 M_APM   MM_Three         = NULL;
  113 M_APM   MM_Four          = NULL;
  114 M_APM   MM_Five          = NULL;
  115 M_APM   MM_Ten           = NULL;
  116 M_APM   MM_0_5           = NULL;
  117 M_APM   MM_E             = NULL;
  118 M_APM   MM_PI            = NULL;
  119 M_APM   MM_HALF_PI       = NULL;
  120 M_APM   MM_2_PI          = NULL;
  121 M_APM   MM_lc_PI         = NULL;
  122 M_APM   MM_lc_HALF_PI    = NULL;
  123 M_APM   MM_lc_2_PI       = NULL;
  124 M_APM   MM_lc_log2       = NULL;
  125 M_APM   MM_lc_log10      = NULL;
  126 M_APM   MM_lc_log10R     = NULL;
  127 M_APM   MM_0_85          = NULL;
  128 M_APM   MM_5x_125R       = NULL;
  129 M_APM   MM_5x_64R        = NULL;
  130 M_APM   MM_5x_256R       = NULL;
  131 M_APM   MM_5x_Eight      = NULL;
  132 M_APM   MM_5x_Sixteen    = NULL;
  133 M_APM   MM_5x_Twenty     = NULL;
  134 M_APM   MM_LOG_E_BASE_10 = NULL;
  135 M_APM   MM_LOG_10_BASE_E = NULL;
  136 M_APM   MM_LOG_2_BASE_E  = NULL;
  137 M_APM   MM_LOG_3_BASE_E  = NULL;
  138 
  139 
  140 static char MM_cnst_PI[] = 
  141 "3.1415926535897932384626433832795028841971693993751058209749445923078\
  142 1640628620899862803482534211706798214808651328230664709384460955";
  143 
  144 static char MM_cnst_E[] = 
  145 "2.7182818284590452353602874713526624977572470936999595749669676277240\
  146 76630353547594571382178525166427427466391932003059921817413596629";
  147 
  148 static char MM_cnst_log_2[] = 
  149 "0.6931471805599453094172321214581765680755001343602552541206800094933\
  150 93621969694715605863326996418687542001481020570685733685520235758";
  151 
  152 static char MM_cnst_log_3[] = 
  153 "1.0986122886681096913952452369225257046474905578227494517346943336374\
  154 9429321860896687361575481373208878797002906595786574236800422593";
  155 
  156 static char MM_cnst_log_10[] = 
  157 "2.3025850929940456840179914546843642076011014886287729760333279009675\
  158 7260967735248023599720508959829834196778404228624863340952546508";
  159 
  160 static char MM_cnst_1_log_10[] = 
  161 "0.4342944819032518276511289189166050822943970058036665661144537831658\
  162 64649208870774729224949338431748318706106744766303733641679287159";
  163 
  164 /*
  165  *     the following constants have ~520 digits each, if needed
  166  */
  167 
  168 /* 
  169 static char MM_cnst_PI[] = 
  170 "3.1415926535897932384626433832795028841971693993751058209749445923078\
  171 164062862089986280348253421170679821480865132823066470938446095505822\
  172 317253594081284811174502841027019385211055596446229489549303819644288\
  173 109756659334461284756482337867831652712019091456485669234603486104543\
  174 266482133936072602491412737245870066063155881748815209209628292540917\
  175 153643678925903600113305305488204665213841469519415116094330572703657\
  176 595919530921861173819326117931051185480744623799627495673518857527248\
  177 91227938183011949129833673362440656643";
  178 
  179 static char MM_cnst_E[] = 
  180 "2.7182818284590452353602874713526624977572470936999595749669676277240\
  181 766303535475945713821785251664274274663919320030599218174135966290435\
  182 729003342952605956307381323286279434907632338298807531952510190115738\
  183 341879307021540891499348841675092447614606680822648001684774118537423\
  184 454424371075390777449920695517027618386062613313845830007520449338265\
  185 602976067371132007093287091274437470472306969772093101416928368190255\
  186 151086574637721112523897844250569536967707854499699679468644549059879\
  187 3163688923009879312773617821542499923";
  188 
  189 static char MM_cnst_log_2[] = 
  190 "0.6931471805599453094172321214581765680755001343602552541206800094933\
  191 936219696947156058633269964186875420014810205706857336855202357581305\
  192 570326707516350759619307275708283714351903070386238916734711233501153\
  193 644979552391204751726815749320651555247341395258829504530070953263666\
  194 426541042391578149520437404303855008019441706416715186447128399681717\
  195 845469570262716310645461502572074024816377733896385506952606683411372\
  196 738737229289564935470257626520988596932019650585547647033067936544325\
  197 47632744951250406069438147104689946506";
  198 
  199 static char MM_cnst_log_3[] = 
  200 "1.0986122886681096913952452369225257046474905578227494517346943336374\
  201 942932186089668736157548137320887879700290659578657423680042259305198\
  202 210528018707672774106031627691833813671793736988443609599037425703167\
  203 959115211455919177506713470549401667755802222031702529468975606901065\
  204 215056428681380363173732985777823669916547921318181490200301038236301\
  205 222486527481982259910974524908964580534670088459650857484441190188570\
  206 876474948670796130858294116021661211840014098255143919487688936798494\
  207 3022557315353296853452952514592138765";
  208 
  209 static char MM_cnst_log_10[] = 
  210 "2.3025850929940456840179914546843642076011014886287729760333279009675\
  211 726096773524802359972050895982983419677840422862486334095254650828067\
  212 566662873690987816894829072083255546808437998948262331985283935053089\
  213 653777326288461633662222876982198867465436674744042432743651550489343\
  214 149393914796194044002221051017141748003688084012647080685567743216228\
  215 355220114804663715659121373450747856947683463616792101806445070648000\
  216 277502684916746550586856935673420670581136429224554405758925724208241\
  217 31469568901675894025677631135691929203";
  218 
  219 static char MM_cnst_1_log_10[] = 
  220 "0.4342944819032518276511289189166050822943970058036665661144537831658\
  221 646492088707747292249493384317483187061067447663037336416792871589639\
  222 065692210646628122658521270865686703295933708696588266883311636077384\
  223 905142844348666768646586085135561482123487653435434357317253835622281\
  224 395603048646652366095539377356176323431916710991411597894962993512457\
  225 934926357655469077671082419150479910989674900103277537653570270087328\
  226 550951731440674697951899513594088040423931518868108402544654089797029\
  227 86328682876262414401345704354613292060";
  228 */
  229 
  230 
  231 /****************************************************************************/
  232 char    *m_apm_lib_version(char *v)
  233 {
  234 strcpy(v, MAPM_LIB_VERSION);
  235 return(v);
  236 }
  237 /****************************************************************************/
  238 char    *m_apm_lib_short_version(char *v)
  239 {
  240 strcpy(v, MAPM_LIB_SHORT_VERSION);
  241 return(v);
  242 }
  243 /****************************************************************************/
  244 void    M_free_all_cnst()
  245 {
  246 if (MM_lc_PI_digits != 0)
  247   {
  248    m_apm_free(MM_Zero);
  249    m_apm_free(MM_One);
  250    m_apm_free(MM_Two);
  251    m_apm_free(MM_Three);
  252    m_apm_free(MM_Four);
  253    m_apm_free(MM_Five);
  254    m_apm_free(MM_Ten);
  255    m_apm_free(MM_0_5);
  256    m_apm_free(MM_LOG_2_BASE_E);
  257    m_apm_free(MM_LOG_3_BASE_E);
  258    m_apm_free(MM_E);
  259    m_apm_free(MM_PI);
  260    m_apm_free(MM_HALF_PI);
  261    m_apm_free(MM_2_PI);
  262    m_apm_free(MM_lc_PI);
  263    m_apm_free(MM_lc_HALF_PI);
  264    m_apm_free(MM_lc_2_PI);
  265    m_apm_free(MM_lc_log2);
  266    m_apm_free(MM_lc_log10);
  267    m_apm_free(MM_lc_log10R);
  268    m_apm_free(MM_0_85);
  269    m_apm_free(MM_5x_125R);
  270    m_apm_free(MM_5x_64R);
  271    m_apm_free(MM_5x_256R);
  272    m_apm_free(MM_5x_Eight);
  273    m_apm_free(MM_5x_Sixteen);
  274    m_apm_free(MM_5x_Twenty);
  275    m_apm_free(MM_LOG_E_BASE_10);
  276    m_apm_free(MM_LOG_10_BASE_E);
  277 
  278    MM_lc_PI_digits = 0;
  279   }
  280 }
  281 /****************************************************************************/
  282 void    M_init_trig_globals()
  283 {
  284 MM_lc_PI_digits      = VALID_DECIMAL_PLACES;
  285 MM_lc_log_digits     = VALID_DECIMAL_PLACES;
  286 MM_cpp_min_precision = 30;
  287 
  288 MM_Zero          = m_apm_init();
  289 MM_One           = m_apm_init();
  290 MM_Two           = m_apm_init();
  291 MM_Three         = m_apm_init();
  292 MM_Four          = m_apm_init();
  293 MM_Five          = m_apm_init();
  294 MM_Ten           = m_apm_init();
  295 MM_0_5           = m_apm_init();
  296 MM_LOG_2_BASE_E  = m_apm_init();
  297 MM_LOG_3_BASE_E  = m_apm_init();
  298 MM_E             = m_apm_init();
  299 MM_PI            = m_apm_init();
  300 MM_HALF_PI       = m_apm_init();
  301 MM_2_PI          = m_apm_init();
  302 MM_lc_PI         = m_apm_init();
  303 MM_lc_HALF_PI    = m_apm_init();
  304 MM_lc_2_PI       = m_apm_init();
  305 MM_lc_log2       = m_apm_init();
  306 MM_lc_log10      = m_apm_init();
  307 MM_lc_log10R     = m_apm_init();
  308 MM_0_85          = m_apm_init();
  309 MM_5x_125R       = m_apm_init();
  310 MM_5x_64R        = m_apm_init();
  311 MM_5x_256R       = m_apm_init();
  312 MM_5x_Eight      = m_apm_init();
  313 MM_5x_Sixteen    = m_apm_init();
  314 MM_5x_Twenty     = m_apm_init();
  315 MM_LOG_E_BASE_10 = m_apm_init();
  316 MM_LOG_10_BASE_E = m_apm_init();
  317 
  318 m_apm_set_string(MM_One, "1");
  319 m_apm_set_string(MM_Two, "2");
  320 m_apm_set_string(MM_Three, "3");
  321 m_apm_set_string(MM_Four, "4");
  322 m_apm_set_string(MM_Five, "5");
  323 m_apm_set_string(MM_Ten, "10");
  324 m_apm_set_string(MM_0_5, "0.5");
  325 m_apm_set_string(MM_0_85, "0.85");
  326 
  327 m_apm_set_string(MM_5x_125R, "8.0E-3");
  328 m_apm_set_string(MM_5x_64R, "1.5625E-2");
  329 m_apm_set_string(MM_5x_256R, "3.90625E-3");
  330 m_apm_set_string(MM_5x_Eight, "8");
  331 m_apm_set_string(MM_5x_Sixteen, "16");
  332 m_apm_set_string(MM_5x_Twenty, "20");
  333 
  334 m_apm_set_string(MM_LOG_2_BASE_E, MM_cnst_log_2);
  335 m_apm_set_string(MM_LOG_3_BASE_E, MM_cnst_log_3);
  336 m_apm_set_string(MM_LOG_10_BASE_E, MM_cnst_log_10);
  337 m_apm_set_string(MM_LOG_E_BASE_10, MM_cnst_1_log_10);
  338 
  339 m_apm_set_string(MM_lc_log2, MM_cnst_log_2);
  340 m_apm_set_string(MM_lc_log10, MM_cnst_log_10);
  341 m_apm_set_string(MM_lc_log10R, MM_cnst_1_log_10);
  342 
  343 m_apm_set_string(MM_E, MM_cnst_E);
  344 m_apm_set_string(MM_PI, MM_cnst_PI);
  345 m_apm_multiply(MM_HALF_PI, MM_PI, MM_0_5);
  346 m_apm_multiply(MM_2_PI, MM_PI, MM_Two);
  347 
  348 m_apm_copy(MM_lc_PI, MM_PI);
  349 m_apm_copy(MM_lc_HALF_PI, MM_HALF_PI);
  350 m_apm_copy(MM_lc_2_PI, MM_2_PI);
  351 }
  352 /****************************************************************************/
  353 void    m_apm_cpp_precision(int digits)
  354 {
  355 if (MM_lc_PI_digits == 0)
  356   {
  357    m_apm_free(m_apm_init());
  358   }
  359 
  360 if (digits >= 2)
  361   MM_cpp_min_precision = digits;
  362 else
  363   MM_cpp_min_precision = 2;
  364 }
  365 /****************************************************************************/