コード例 #1
0
static int compare_fraction(fraction *a, fraction *b)
{
  int lcm_denominator = 
    least_common_multiple(a->denominator, b->denominator);

  return (lcm_denominator / a->denominator * a->numerator) -
         (lcm_denominator / b->denominator * b->numerator);
}
コード例 #2
0
ファイル: q005.c プロジェクト: watertiger/tx-question
int
main ()
{
	u64 sum_ret = 0;
//	u64 lcm = 16 * 9 * 5 * 7 * 11 * 13 * 17 * 19;	//232792560
//	printf("The result is %llu.\n", lcm);
	sum_ret = least_common_multiple(20);	//232792560
	printf("The result is %llu.\n", sum_ret);
	
	return 0;
}
コード例 #3
0
static unsigned
determine_unroll_factor (struct loop *loop, struct mem_ref_group *refs,
			 unsigned ninsns, struct tree_niter_desc *desc,
			 HOST_WIDE_INT est_niter)
{
  unsigned upper_bound;
  unsigned nfactor, factor, mod_constraint;
  struct mem_ref_group *agp;
  struct mem_ref *ref;

  /* First check whether the loop is not too large to unroll.  We ignore
     PARAM_MAX_UNROLL_TIMES, because for small loops, it prevented us
     from unrolling them enough to make exactly one cache line covered by each
     iteration.  Also, the goal of PARAM_MAX_UNROLL_TIMES is to prevent
     us from unrolling the loops too many times in cases where we only expect
     gains from better scheduling and decreasing loop overhead, which is not
     the case here.  */
  upper_bound = PARAM_VALUE (PARAM_MAX_UNROLLED_INSNS) / ninsns;

  /* If we unrolled the loop more times than it iterates, the unrolled version
     of the loop would be never entered.  */
  if (est_niter >= 0 && est_niter < (HOST_WIDE_INT) upper_bound)
    upper_bound = est_niter;

  if (upper_bound <= 1)
    return 1;

  /* Choose the factor so that we may prefetch each cache just once,
     but bound the unrolling by UPPER_BOUND.  */
  factor = 1;
  for (agp = refs; agp; agp = agp->next)
    for (ref = agp->refs; ref; ref = ref->next)
      if (should_issue_prefetch_p (ref))
	{
	  mod_constraint = ref->prefetch_mod;
	  nfactor = least_common_multiple (mod_constraint, factor);
	  if (nfactor <= upper_bound)
	    factor = nfactor;
	}

  if (!should_unroll_loop_p (loop, desc, factor))
    return 1;

  return factor;
}
コード例 #4
0
static void add_fraction(fraction *a, fraction *b, fraction *result)
{
  int lcm_denominator = 
    least_common_multiple(a->denominator, b->denominator);
  int gcd, a_num, b_num;
  fraction ret;

  ret.denominator = lcm_denominator;
  ret.numerator = (lcm_denominator / a->denominator * a->numerator) + 
                  (lcm_denominator / b->denominator * b->numerator);

  gcd = greatest_common_divisor(ret.denominator, ret.numerator);
  if (gcd != 1) {
    ret.denominator /= gcd;
    ret.numerator /= gcd;
  }

  *result = ret;
}