コード例 #1
0
ファイル: p23.c プロジェクト: mattwollf/pe_solutions
uint16_t divisor_sum( uint16_t n )
{
	uint16_t s = 0 ;

	uint16_t i;

	for( i = 1; i <= n/2 ; ++ i )
	{

		if( is_divisor( n, i ) == 1)
		{
			s += i;
		}
	}

	return s ;
}
コード例 #2
0
ファイル: can.c プロジェクト: gedare/rtems
/**
 * @brief Gets the brp and tsegbitsize in order to achieve the desired bitwidth.
 * @details The following must be fullfilled:
 *(brp + CAN_BRP_EXTRA_BIT) * (tsegbitsize + CAN_TSEG_EXTRA_BITS) == bitwidth
 *
 * @param bitwidth The bitwidth that we need to achieve.
 * @param brp Here it returns the calculated brp value.
 * @param tsegbitsize Here it returns the calculated tseg bit size value.
 * @return true if brp and tsegbitsize have been calculated.
 */
static inline bool get_brp_and_bitsize(
  const uint32_t  bitwidth,
  uint16_t *const brp,
  uint32_t *const tsegbitsize
)
{
  bool hit = false;

  while ( ( !hit ) && ( *brp < bitwidth / MIN_NUMBER_OF_CAN_BITS ) ) {
    if ( ( is_divisor( bitwidth, *brp + CAN_BRP_EXTRA_BIT ) )
         && ( get_tseg_bit_size( bitwidth, *brp ) < MAX_TSEG1_TSEG2_BITS ) ) {
      hit = true;
      *tsegbitsize = get_tseg_bit_size( bitwidth, *brp );
    } else { /*Correct values not found, keep looking*/
      ( *brp )++;
    }
  }

  return hit;
}