1111823Sgshapiro 290792Sgshapiro/* 390792Sgshapiro * M_APM - mapmcnst.c 490792Sgshapiro * 590792Sgshapiro * Copyright (C) 1999 - 2007 Michael C. Ring 690792Sgshapiro * 790792Sgshapiro * Permission to use, copy, and distribute this software and its 8168515Sgshapiro * documentation for any purpose with or without fee is hereby granted, 990792Sgshapiro * provided that the above copyright notice appear in all copies and 1090792Sgshapiro * that both that copyright notice and this permission notice appear 1190792Sgshapiro * in supporting documentation. 1290792Sgshapiro * 1390792Sgshapiro * Permission to modify the software is granted. Permission to distribute 1490792Sgshapiro * the modified code is granted. Modifications are to be distributed by 1590792Sgshapiro * using the file 'license.txt' as a template to modify the file header. 1690792Sgshapiro * 'license.txt' is available in the official MAPM distribution. 1790792Sgshapiro * 1890792Sgshapiro * This software is provided "as is" without express or implied warranty. 1990792Sgshapiro */ 2090792Sgshapiro 2190792Sgshapiro/* 2290792Sgshapiro * $Id: mapmcnst.c,v 1.24 2007/12/03 01:51:16 mike Exp $ 2390792Sgshapiro * 2490792Sgshapiro * This file contains declarations and initializes the constants 2590792Sgshapiro * used throughout the library. 2690792Sgshapiro * 2790792Sgshapiro * $Log: mapmcnst.c,v $ 2890792Sgshapiro * Revision 1.24 2007/12/03 01:51:16 mike 2990792Sgshapiro * Update license 3090792Sgshapiro * 3190792Sgshapiro * Revision 1.23 2003/05/06 21:28:53 mike 3290792Sgshapiro * add lib version functions 3390792Sgshapiro * 3490792Sgshapiro * Revision 1.22 2003/03/30 21:14:16 mike 3590792Sgshapiro * add local copies of log(2) and log(10) 3690792Sgshapiro * 3790792Sgshapiro * Revision 1.21 2002/11/03 22:45:29 mike 3890792Sgshapiro * Updated function parameters to use the modern style 3990792Sgshapiro * 4090792Sgshapiro * Revision 1.20 2002/05/17 22:40:25 mike 4190792Sgshapiro * call m_apm_init from cpp_precision to init the library 42168515Sgshapiro * if it hasn't been done yet. 4390792Sgshapiro * 4490792Sgshapiro * Revision 1.19 2001/07/16 19:40:12 mike 4590792Sgshapiro * add function M_free_all_cnst 4690792Sgshapiro * 4790792Sgshapiro * Revision 1.18 2001/02/07 19:17:58 mike 4890792Sgshapiro * eliminate MM_skip_limit_PI_check 4990792Sgshapiro * 5090792Sgshapiro * Revision 1.17 2000/05/19 16:31:02 mike 5190792Sgshapiro * add local copies for PI variables 52168515Sgshapiro * 5390792Sgshapiro * Revision 1.16 2000/05/04 23:52:03 mike 5490792Sgshapiro * added new constant, 256R. 5590792Sgshapiro * renamed _008 to _125R 5690792Sgshapiro * 5790792Sgshapiro * Revision 1.15 2000/04/11 18:44:21 mike 5890792Sgshapiro * no longer need the constant 'Fifteen' 5990792Sgshapiro * 6090792Sgshapiro * Revision 1.14 2000/04/05 20:12:53 mike 6190792Sgshapiro * add C++ min precision function 6290792Sgshapiro * 6390792Sgshapiro * Revision 1.13 1999/07/09 22:47:48 mike 6490792Sgshapiro * add skip limit PI check 6590792Sgshapiro * 6690792Sgshapiro * Revision 1.12 1999/07/08 23:34:50 mike 6790792Sgshapiro * change constant 6890792Sgshapiro * 6990792Sgshapiro * Revision 1.11 1999/07/08 22:58:08 mike 7090792Sgshapiro * add new constant 7190792Sgshapiro * 7290792Sgshapiro * Revision 1.10 1999/06/23 01:09:53 mike 7390792Sgshapiro * added new constant 15 7490792Sgshapiro * 7590792Sgshapiro * Revision 1.9 1999/06/20 23:32:30 mike 7690792Sgshapiro * added new constants 7790792Sgshapiro * 7890792Sgshapiro * Revision 1.8 1999/06/20 19:24:14 mike 79168515Sgshapiro * delete constants no longer needed 8090792Sgshapiro * 8190792Sgshapiro * Revision 1.7 1999/06/20 18:57:29 mike 8290792Sgshapiro * fixed missing init for new constants 8390792Sgshapiro * 8490792Sgshapiro * Revision 1.6 1999/06/20 18:53:44 mike 8590792Sgshapiro * added more constants 8690792Sgshapiro * 8790792Sgshapiro * Revision 1.5 1999/05/31 23:50:30 mike 8890792Sgshapiro * delete constants no longer needed 8990792Sgshapiro * 9090792Sgshapiro * Revision 1.4 1999/05/14 19:50:22 mike 9190792Sgshapiro * added more constants with more digits 9290792Sgshapiro * 9390792Sgshapiro * Revision 1.3 1999/05/12 20:53:08 mike 9490792Sgshapiro * added more constants 9590792Sgshapiro * 9690792Sgshapiro * Revision 1.2 1999/05/10 21:52:24 mike 9790792Sgshapiro * added some comments 98168515Sgshapiro * 9990792Sgshapiro * Revision 1.1 1999/05/10 20:56:31 mike 10090792Sgshapiro * Initial revision 10190792Sgshapiro */ 10290792Sgshapiro 10390792Sgshapiro#include "m_apm_lc.h" 10490792Sgshapiro 10590792Sgshapiroint MM_lc_PI_digits = 0; 10690792Sgshapiroint MM_lc_log_digits; 10790792Sgshapiroint MM_cpp_min_precision; /* only used in C++ wrapper */ 10890792Sgshapiro 10990792SgshapiroM_APM MM_Zero = NULL; 11090792SgshapiroM_APM MM_One = NULL; 11190792SgshapiroM_APM MM_Two = NULL; 11290792SgshapiroM_APM MM_Three = NULL; 11390792SgshapiroM_APM MM_Four = NULL; 11490792SgshapiroM_APM MM_Five = NULL; 11590792SgshapiroM_APM MM_Ten = NULL; 11690792SgshapiroM_APM MM_0_5 = NULL; 11790792SgshapiroM_APM MM_E = NULL; 11890792SgshapiroM_APM MM_PI = NULL; 11990792SgshapiroM_APM MM_HALF_PI = NULL; 12090792SgshapiroM_APM MM_2_PI = NULL; 12190792SgshapiroM_APM MM_lc_PI = NULL; 12290792SgshapiroM_APM MM_lc_HALF_PI = NULL; 12390792SgshapiroM_APM MM_lc_2_PI = NULL; 12490792SgshapiroM_APM MM_lc_log2 = NULL; 12590792SgshapiroM_APM MM_lc_log10 = NULL; 12690792SgshapiroM_APM MM_lc_log10R = NULL; 12790792SgshapiroM_APM MM_0_85 = NULL; 12890792SgshapiroM_APM MM_5x_125R = NULL; 12990792SgshapiroM_APM MM_5x_64R = NULL; 13090792SgshapiroM_APM MM_5x_256R = NULL; 13190792SgshapiroM_APM MM_5x_Eight = NULL; 13290792SgshapiroM_APM MM_5x_Sixteen = NULL; 13390792SgshapiroM_APM MM_5x_Twenty = NULL; 13490792SgshapiroM_APM MM_LOG_E_BASE_10 = NULL; 13590792SgshapiroM_APM MM_LOG_10_BASE_E = NULL; 13690792SgshapiroM_APM MM_LOG_2_BASE_E = NULL; 13790792SgshapiroM_APM MM_LOG_3_BASE_E = NULL; 13890792Sgshapiro 13990792Sgshapiro 14090792Sgshapirostatic char MM_cnst_PI[] = 14190792Sgshapiro"3.1415926535897932384626433832795028841971693993751058209749445923078\ 142168515Sgshapiro1640628620899862803482534211706798214808651328230664709384460955"; 14390792Sgshapiro 14494334Sgshapirostatic char MM_cnst_E[] = 14594334Sgshapiro"2.7182818284590452353602874713526624977572470936999595749669676277240\ 14694334Sgshapiro76630353547594571382178525166427427466391932003059921817413596629"; 14794334Sgshapiro 14894334Sgshapirostatic char MM_cnst_log_2[] = 14994334Sgshapiro"0.6931471805599453094172321214581765680755001343602552541206800094933\ 15090792Sgshapiro93621969694715605863326996418687542001481020570685733685520235758"; 151168515Sgshapiro 152168515Sgshapirostatic char MM_cnst_log_3[] = 153168515Sgshapiro"1.0986122886681096913952452369225257046474905578227494517346943336374\ 15490792Sgshapiro9429321860896687361575481373208878797002906595786574236800422593"; 15590792Sgshapiro 15690792Sgshapirostatic char MM_cnst_log_10[] = 15790792Sgshapiro"2.3025850929940456840179914546843642076011014886287729760333279009675\ 15890792Sgshapiro7260967735248023599720508959829834196778404228624863340952546508"; 15990792Sgshapiro 16090792Sgshapirostatic char MM_cnst_1_log_10[] = 16190792Sgshapiro"0.4342944819032518276511289189166050822943970058036665661144537831658\ 16290792Sgshapiro64649208870774729224949338431748318706106744766303733641679287159"; 16390792Sgshapiro 16490792Sgshapiro/* 16590792Sgshapiro * the following constants have ~520 digits each, if needed 16690792Sgshapiro */ 16790792Sgshapiro 16890792Sgshapiro/* 16990792Sgshapirostatic char MM_cnst_PI[] = 17090792Sgshapiro"3.1415926535897932384626433832795028841971693993751058209749445923078\ 17190792Sgshapiro164062862089986280348253421170679821480865132823066470938446095505822\ 17290792Sgshapiro317253594081284811174502841027019385211055596446229489549303819644288\ 17390792Sgshapiro109756659334461284756482337867831652712019091456485669234603486104543\ 17490792Sgshapiro266482133936072602491412737245870066063155881748815209209628292540917\ 17590792Sgshapiro153643678925903600113305305488204665213841469519415116094330572703657\ 17690792Sgshapiro595919530921861173819326117931051185480744623799627495673518857527248\ 17790792Sgshapiro91227938183011949129833673362440656643"; 17890792Sgshapiro 17990792Sgshapirostatic char MM_cnst_E[] = 18090792Sgshapiro"2.7182818284590452353602874713526624977572470936999595749669676277240\ 18190792Sgshapiro766303535475945713821785251664274274663919320030599218174135966290435\ 18290792Sgshapiro729003342952605956307381323286279434907632338298807531952510190115738\ 18390792Sgshapiro341879307021540891499348841675092447614606680822648001684774118537423\ 18490792Sgshapiro454424371075390777449920695517027618386062613313845830007520449338265\ 18590792Sgshapiro602976067371132007093287091274437470472306969772093101416928368190255\ 18690792Sgshapiro151086574637721112523897844250569536967707854499699679468644549059879\ 18790792Sgshapiro3163688923009879312773617821542499923"; 18890792Sgshapiro 18990792Sgshapirostatic char MM_cnst_log_2[] = 19090792Sgshapiro"0.6931471805599453094172321214581765680755001343602552541206800094933\ 19190792Sgshapiro936219696947156058633269964186875420014810205706857336855202357581305\ 19290792Sgshapiro570326707516350759619307275708283714351903070386238916734711233501153\ 19390792Sgshapiro644979552391204751726815749320651555247341395258829504530070953263666\ 19490792Sgshapiro426541042391578149520437404303855008019441706416715186447128399681717\ 19590792Sgshapiro845469570262716310645461502572074024816377733896385506952606683411372\ 19690792Sgshapiro738737229289564935470257626520988596932019650585547647033067936544325\ 19790792Sgshapiro47632744951250406069438147104689946506"; 19890792Sgshapiro 19990792Sgshapirostatic char MM_cnst_log_3[] = 20090792Sgshapiro"1.0986122886681096913952452369225257046474905578227494517346943336374\ 20190792Sgshapiro942932186089668736157548137320887879700290659578657423680042259305198\ 20290792Sgshapiro210528018707672774106031627691833813671793736988443609599037425703167\ 20390792Sgshapiro959115211455919177506713470549401667755802222031702529468975606901065\ 20490792Sgshapiro215056428681380363173732985777823669916547921318181490200301038236301\ 20590792Sgshapiro222486527481982259910974524908964580534670088459650857484441190188570\ 20690792Sgshapiro876474948670796130858294116021661211840014098255143919487688936798494\ 20790792Sgshapiro3022557315353296853452952514592138765"; 20890792Sgshapiro 20990792Sgshapirostatic char MM_cnst_log_10[] = 21090792Sgshapiro"2.3025850929940456840179914546843642076011014886287729760333279009675\ 21190792Sgshapiro726096773524802359972050895982983419677840422862486334095254650828067\ 212168515Sgshapiro566662873690987816894829072083255546808437998948262331985283935053089\ 21390792Sgshapiro653777326288461633662222876982198867465436674744042432743651550489343\ 21490792Sgshapiro149393914796194044002221051017141748003688084012647080685567743216228\ 215168515Sgshapiro355220114804663715659121373450747856947683463616792101806445070648000\ 21690792Sgshapiro277502684916746550586856935673420670581136429224554405758925724208241\ 21790792Sgshapiro31469568901675894025677631135691929203"; 21890792Sgshapiro 21990792Sgshapirostatic char MM_cnst_1_log_10[] = 22090792Sgshapiro"0.4342944819032518276511289189166050822943970058036665661144537831658\ 22190792Sgshapiro646492088707747292249493384317483187061067447663037336416792871589639\ 22290792Sgshapiro065692210646628122658521270865686703295933708696588266883311636077384\ 22390792Sgshapiro905142844348666768646586085135561482123487653435434357317253835622281\ 22490792Sgshapiro395603048646652366095539377356176323431916710991411597894962993512457\ 22590792Sgshapiro934926357655469077671082419150479910989674900103277537653570270087328\ 22690792Sgshapiro550951731440674697951899513594088040423931518868108402544654089797029\ 22790792Sgshapiro86328682876262414401345704354613292060"; 22890792Sgshapiro*/ 22990792Sgshapiro 23090792Sgshapiro 231/****************************************************************************/ 232char *m_apm_lib_version(char *v) 233{ 234strcpy(v, MAPM_LIB_VERSION); 235return(v); 236} 237/****************************************************************************/ 238char *m_apm_lib_short_version(char *v) 239{ 240strcpy(v, MAPM_LIB_SHORT_VERSION); 241return(v); 242} 243/****************************************************************************/ 244void M_free_all_cnst() 245{ 246if (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/****************************************************************************/ 282void M_init_trig_globals() 283{ 284MM_lc_PI_digits = VALID_DECIMAL_PLACES; 285MM_lc_log_digits = VALID_DECIMAL_PLACES; 286MM_cpp_min_precision = 30; 287 288MM_Zero = m_apm_init(); 289MM_One = m_apm_init(); 290MM_Two = m_apm_init(); 291MM_Three = m_apm_init(); 292MM_Four = m_apm_init(); 293MM_Five = m_apm_init(); 294MM_Ten = m_apm_init(); 295MM_0_5 = m_apm_init(); 296MM_LOG_2_BASE_E = m_apm_init(); 297MM_LOG_3_BASE_E = m_apm_init(); 298MM_E = m_apm_init(); 299MM_PI = m_apm_init(); 300MM_HALF_PI = m_apm_init(); 301MM_2_PI = m_apm_init(); 302MM_lc_PI = m_apm_init(); 303MM_lc_HALF_PI = m_apm_init(); 304MM_lc_2_PI = m_apm_init(); 305MM_lc_log2 = m_apm_init(); 306MM_lc_log10 = m_apm_init(); 307MM_lc_log10R = m_apm_init(); 308MM_0_85 = m_apm_init(); 309MM_5x_125R = m_apm_init(); 310MM_5x_64R = m_apm_init(); 311MM_5x_256R = m_apm_init(); 312MM_5x_Eight = m_apm_init(); 313MM_5x_Sixteen = m_apm_init(); 314MM_5x_Twenty = m_apm_init(); 315MM_LOG_E_BASE_10 = m_apm_init(); 316MM_LOG_10_BASE_E = m_apm_init(); 317 318m_apm_set_string(MM_One, "1"); 319m_apm_set_string(MM_Two, "2"); 320m_apm_set_string(MM_Three, "3"); 321m_apm_set_string(MM_Four, "4"); 322m_apm_set_string(MM_Five, "5"); 323m_apm_set_string(MM_Ten, "10"); 324m_apm_set_string(MM_0_5, "0.5"); 325m_apm_set_string(MM_0_85, "0.85"); 326 327m_apm_set_string(MM_5x_125R, "8.0E-3"); 328m_apm_set_string(MM_5x_64R, "1.5625E-2"); 329m_apm_set_string(MM_5x_256R, "3.90625E-3"); 330m_apm_set_string(MM_5x_Eight, "8"); 331m_apm_set_string(MM_5x_Sixteen, "16"); 332m_apm_set_string(MM_5x_Twenty, "20"); 333 334m_apm_set_string(MM_LOG_2_BASE_E, MM_cnst_log_2); 335m_apm_set_string(MM_LOG_3_BASE_E, MM_cnst_log_3); 336m_apm_set_string(MM_LOG_10_BASE_E, MM_cnst_log_10); 337m_apm_set_string(MM_LOG_E_BASE_10, MM_cnst_1_log_10); 338 339m_apm_set_string(MM_lc_log2, MM_cnst_log_2); 340m_apm_set_string(MM_lc_log10, MM_cnst_log_10); 341m_apm_set_string(MM_lc_log10R, MM_cnst_1_log_10); 342 343m_apm_set_string(MM_E, MM_cnst_E); 344m_apm_set_string(MM_PI, MM_cnst_PI); 345m_apm_multiply(MM_HALF_PI, MM_PI, MM_0_5); 346m_apm_multiply(MM_2_PI, MM_PI, MM_Two); 347 348m_apm_copy(MM_lc_PI, MM_PI); 349m_apm_copy(MM_lc_HALF_PI, MM_HALF_PI); 350m_apm_copy(MM_lc_2_PI, MM_2_PI); 351} 352/****************************************************************************/ 353void m_apm_cpp_precision(int digits) 354{ 355if (MM_lc_PI_digits == 0) 356 { 357 m_apm_free(m_apm_init()); 358 } 359 360if (digits >= 2) 361 MM_cpp_min_precision = digits; 362else 363 MM_cpp_min_precision = 2; 364} 365/****************************************************************************/ 366