⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mapmrsin.c

📁 任意精度的数学库
💻 C
字号:
/*  *  M_APM  -  mapmrsin.c * *  Copyright (C) 1999   Michael C. Ring * *  Permission to use, copy, and distribute this software and its *  documentation for any purpose with or without fee is hereby granted,  *  provided that the above copyright notice appear in all copies and  *  that both that copyright notice and this permission notice appear  *  in supporting documentation. * *  Permission to modify the software is granted, but not the right to *  distribute the modified code.  Modifications are to be distributed  *  as patches to released version. *   *  This software is provided "as is" without express or implied warranty. *//* *      $Id: mapmrsin.c,v 1.3 1999/06/20 16:23:10 mike Exp $ * *      This file contains the basic series expansion functions for  *	the SIN / COS functions. * *      $Log: mapmrsin.c,v $ *      Revision 1.3  1999/06/20 16:23:10  mike *      changed local static variables to MAPM stack variables * *      Revision 1.2  1999/05/12 21:06:36  mike *      changed global var names * *      Revision 1.1  1999/05/10 20:56:31  mike *      Initial revision */#include "m_apm_lc.h"/****************************************************************************//*                                x^3     x^5     x^7    x^9		 sin(x) == x -  ---  +  ---  -  ---  + ---  ...                                 3!      5!      7!     9!*/void	M_raw_sin(rr,places,xx)M_APM 	rr, xx;int 	places;{M_APM	sum, term, tmp6, tmp7, tmp8, tmp9;int     sign_flag, flag;long	m1, m2;sum  = M_get_stack_var();term = M_get_stack_var();tmp6 = M_get_stack_var();tmp7 = M_get_stack_var();tmp8 = M_get_stack_var();tmp9 = M_get_stack_var();m_apm_copy(sum, xx);m_apm_copy(term, xx);m_apm_multiply(tmp8, xx, xx);m_apm_round(tmp9, (places + 6), tmp8);m_apm_copy(tmp6, MM_One);tmp6->m_apm_exponent = -(places + 4);m1   = 2L;flag = 0;sign_flag = xx->m_apm_sign;tmp6->m_apm_sign = sign_flag;while (TRUE)  {   m2 = m1 * (m1 + 1);   m_apm_set_long(tmp7, m2);   m_apm_multiply(tmp8, term, tmp9);   m_apm_divide(term, (places + 6), tmp8, tmp7);   if (flag == 0)     {      m_apm_subtract(tmp7, sum, term);      m_apm_copy(sum, tmp7);     }   else     {      m_apm_add(tmp7, sum, term);      m_apm_copy(sum, tmp7);     }   /*    *    the SIN function only uses the odd powers of 'x',    *    so the terms will always be positive OR negative    *    during each call to this function.    */   if (sign_flag == -1)     {      if (m_apm_compare(term, tmp6) >= 0)        break;     }   else     {      if (m_apm_compare(term, tmp6) <= 0)        break;     }   m1 += 2;   flag = 1 - flag;  }m_apm_round(rr, places, sum);M_restore_stack(6);}/****************************************************************************//*                                x^2     x^4     x^6    x^8		 cos(x) == 1 -  ---  +  ---  -  ---  + ---  ...                                 2!      4!      6!     8!*/void	M_raw_cos(rr,places,xx)M_APM 	rr, xx;int 	places;{M_APM	sum, term, tmp6, tmp7, tmp8, tmp9;int     flag;long	m1, m2;sum  = M_get_stack_var();term = M_get_stack_var();tmp6 = M_get_stack_var();tmp7 = M_get_stack_var();tmp8 = M_get_stack_var();tmp9 = M_get_stack_var();m_apm_copy(sum, MM_One);m_apm_copy(term, MM_One);m_apm_multiply(tmp8, xx, xx);m_apm_round(tmp9, (places + 6), tmp8);m_apm_copy(tmp6, MM_One);tmp6->m_apm_exponent = -(places + 4);m1   = 1L;flag = 0;while (TRUE)  {   m2 = m1 * (m1 + 1);   m_apm_set_long(tmp7, m2);   m_apm_multiply(tmp8, term, tmp9);   m_apm_divide(term, (places + 6), tmp8, tmp7);   if (flag == 0)     {      m_apm_subtract(tmp7, sum, term);      m_apm_copy(sum, tmp7);     }   else     {      m_apm_add(tmp7, sum, term);      m_apm_copy(sum, tmp7);     }   /*    *  since the COS function only uses the even powers of 'x',    *  the terms will always be positive.    */   if (m_apm_compare(term, tmp6) <= 0)     break;   m1 += 2;   flag = 1 - flag;  }m_apm_round(rr, places, sum);M_restore_stack(6);}/****************************************************************************/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -