Esempio n. 1
0
void	M_limit_angle_to_pi(M_APM rr, int places, M_APM aa)
{
	M_APM	tmp7, tmp8, tmp9;

	M_check_PI_places(places);

	tmp9 = M_get_stack_var();
	m_apm_copy(tmp9, MM_lc_PI);

	if (m_apm_compare(aa, tmp9) == 1)       /*  > PI  */
	{
		tmp7 = M_get_stack_var();
		tmp8 = M_get_stack_var();

		m_apm_add(tmp7, aa, tmp9);
		m_apm_integer_divide(tmp9, tmp7, MM_lc_2_PI);
		m_apm_multiply(tmp8, tmp9, MM_lc_2_PI);
		m_apm_subtract(tmp9, aa, tmp8);
		m_apm_round(rr, places, tmp9);

		M_restore_stack(3);
		return;
	}

	tmp9->m_apm_sign = -1;
	if (m_apm_compare(aa, tmp9) == -1)       /*  < -PI  */
	{
		tmp7 = M_get_stack_var();
		tmp8 = M_get_stack_var();

		m_apm_add(tmp7, aa, tmp9);
		m_apm_integer_divide(tmp9, tmp7, MM_lc_2_PI);
		m_apm_multiply(tmp8, tmp9, MM_lc_2_PI);
		m_apm_subtract(tmp9, aa, tmp8);
		m_apm_round(rr, places, tmp9);

		M_restore_stack(3);
		return;
	}

	m_apm_copy(rr, aa);
	M_restore_stack(1);
}
Esempio n. 2
0
void	m_apm_lcm(M_APM r, M_APM u, M_APM v)
{
M_APM   tmpN, tmpG;

tmpN = M_get_stack_var();
tmpG = M_get_stack_var();

m_apm_multiply(tmpN, u, v);
m_apm_gcd(tmpG, u, v);
m_apm_integer_divide(r, tmpN, tmpG);

M_restore_stack(2);
}
Esempio n. 3
0
void	m_apm_integer_div_rem(M_APM qq, M_APM rr, M_APM aa, M_APM bb)
{
 if (aa->m_apm_error || bb->m_apm_error)
   {
     M_set_to_error(rr);
     M_set_to_error(qq);
     return;
   }

m_apm_integer_divide(qq, aa, bb);
m_apm_multiply(M_div_tmp7, qq, bb);
m_apm_subtract(rr, aa, M_div_tmp7);
}
Esempio n. 4
0
void	M_get_rnd_seed(M_APM mm)
{
	double		 timer0;
	int		 millisec;
	char             *cvi_time, *cvi_date, buf1[64], buf2[32];
	M_APM		 atmp;

	atmp = M_get_stack_var();

	cvi_date = DateStr();
	cvi_time = TimeStr();
	timer0   = Timer();

	/*
	 *  note that Timer() is not syncronized to TimeStr(),
	 *  but we don't care here since we are just looking
	 *  for a random source of digits.
	 */

	millisec = (int)(0.01 + 1000.0 * (timer0 - floor(timer0)));

	sprintf(buf1, "%d", millisec);

	buf2[0]  = cvi_time[6];	/* time format: "HH:MM:SS" */
	buf2[1]  = cvi_time[7];
	buf2[2]  = cvi_time[3];
	buf2[3]  = cvi_time[4];
	buf2[4]  = cvi_time[0];
	buf2[5]  = cvi_time[1];

	buf2[6]  = cvi_date[3];	/* date format: "MM-DD-YYYY" */
	buf2[7]  = cvi_date[4];
	buf2[8]  = cvi_date[0];
	buf2[9]  = cvi_date[1];
	buf2[10] = cvi_date[8];
	buf2[11] = cvi_date[9];
	buf2[12] = cvi_date[7];

	buf2[13] = '4';
	buf2[14] = '7';
	buf2[15] = '\0';

	strcat(buf1, buf2);

	m_apm_set_string(atmp, buf1);
	atmp->m_apm_exponent = 15;
	m_apm_integer_divide(mm, atmp, MM_One);

	M_restore_stack(1);
}
Esempio n. 5
0
void	m_apm_lcm(M_APM r, M_APM u, M_APM v)
{
M_APM   tmpN, tmpG;
 if (u->m_apm_error || v->m_apm_error)
   {
     M_set_to_error(r);
     return;
   }

tmpN = M_get_stack_var();
tmpG = M_get_stack_var();

m_apm_multiply(tmpN, u, v);
m_apm_gcd(tmpG, u, v);
m_apm_integer_divide(r, tmpN, tmpG);

M_restore_stack(2);
}
Esempio n. 6
0
/*
 *  for DOS / Win 9x/NT systems : use 'ftime'
 */
void	M_get_rnd_seed(M_APM mm)
{
	int              millisec;
	time_t 		 timestamp;
	unsigned long    ul;
	char             ss[32], buf1[48], buf2[32];
	struct timeb     timebuffer;
	M_APM		 atmp;

	atmp = M_get_stack_var();

	ftime(&timebuffer);

	millisec  = (int)timebuffer.millitm;
	timestamp = timebuffer.time;
	ul        = (unsigned long)(timestamp / 7);
	ul       += timestamp + 537;
	strcpy(ss, ctime(&timestamp));       /* convert to string and copy to ss */

	sprintf(buf1, "%d", (millisec / 10));
	sprintf(buf2, "%lu", ul);

	ss[0] = ss[18];
	ss[1] = ss[17];
	ss[2] = ss[15];
	ss[3] = ss[14];
	ss[4] = ss[12];
	ss[5] = ss[11];
	ss[6] = ss[9];
	ss[7] = ss[23];
	ss[8] = ss[20];
	ss[9] = '\0';

	M_reverse_string(buf2);
	strcat(buf1, buf2);
	strcat(buf1, ss);

	m_apm_set_string(atmp, buf1);
	atmp->m_apm_exponent = 15;
	m_apm_integer_divide(mm, atmp, MM_One);

	M_restore_stack(1);
}
Esempio n. 7
0
/*
 *  for unix systems : use 'gettimeofday'
 */
void	M_get_rnd_seed(M_APM mm)
{
	unsigned long    sec3;
	long             usec3;
	char             buf1[32], buf2[32];
	M_APM		 atmp;

	atmp = M_get_stack_var();
	M_get_microsec(&sec3, &usec3);

	sprintf(buf1, "%ld", usec3);
	sprintf(buf2, "%lu", sec3);
	M_reverse_string(buf2);
	strcat(buf1, buf2);

	m_apm_set_string(atmp, buf1);
	atmp->m_apm_exponent = 15;
	m_apm_integer_divide(mm, atmp, MM_One);

	M_restore_stack(1);
}
Esempio n. 8
0
int main(int argc, char *argv[])
{
char	 version_info[80];
int      ct;
				/* declare the M_APM variables ... */
M_APM    aa_mapm;
M_APM    bb_mapm;
M_APM    cc_mapm;
M_APM    dd_mapm;

if (argc < 2)
  {
   m_apm_lib_short_version(version_info);

   fprintf(stdout,
      "Usage: primenum number\t\t\t[Version 1.3, MAPM Version %s]\n",
      	      version_info);
   fprintf(stdout,
      "       find the first 10 prime numbers starting with \'number\'\n");

   exit(4);
  }
				/* now initialize the M_APM variables ... */
aa_mapm = m_apm_init();
bb_mapm = m_apm_init();
cc_mapm = m_apm_init();
dd_mapm = m_apm_init();

init_working_mapm();

m_apm_set_string(dd_mapm, argv[1]);

/*
 *  if input < 3, set start point = 3
 */

if (m_apm_compare(dd_mapm, MM_Three) == -1)
  {
   m_apm_copy(dd_mapm, MM_Three);
  }

/*
 *  make sure we start with an odd integer
 */

m_apm_integer_divide(aa_mapm, dd_mapm, MM_Two);
m_apm_multiply(bb_mapm, MM_Two, aa_mapm);
m_apm_add(aa_mapm, MM_One, bb_mapm);

ct = 0;

while (TRUE)
  {
   if (is_number_prime(aa_mapm))
     {
      m_apm_to_integer_string(buffer, aa_mapm);
      fprintf(stdout,"%s\n",buffer);

      if (++ct == 10)
        break;
     }

   m_apm_add(cc_mapm, MM_Two, aa_mapm);
   m_apm_copy(aa_mapm, cc_mapm);
  }

free_working_mapm();

m_apm_free(aa_mapm);
m_apm_free(bb_mapm);
m_apm_free(cc_mapm);
m_apm_free(dd_mapm);

m_apm_free_all_mem();

exit(0);
}
Esempio n. 9
0
void	m_apm_integer_divide_mt(M_APM rr, M_APM aa, M_APM bb)
{
	m_apm_enter();
	m_apm_integer_divide(rr,aa,bb);
	m_apm_leave();
}