'; } */ } // ----- END LONG DIVISION ----- // If the fraction evaluates to a repeating decimal, calculate the number of digits that repeat; otherwise, set it to 'None'. $repeating = $repeating_decimal_flag ? $decimal_length - $non_repeating_tally : 'None'; // Decorate the sections (optional) // $section_list[0] = '' . $section_list[0] . ''; // $section_list[1] = '' . $section_list[1] . ''; // $section_list[2] = '' . $section_list[2] . ''; // Set properties determined by this method. $this->decimal_length = $decimal_length; $this->repeating = $repeating; $this->section_list = $section_list; $this->decimal = '.' . implode($section_list); } private function count_non_repeating() { $base_factor_tally = 0; $base_tmp = $this->base; $denom_tmp = $this->reduced_denom; $max_non_repeat_tally = 0; $non_repeat_tally = 0; $prime_ndx = 1; $retval = 0; // Loop through the prime number list, starting with 2 and continuing through the largest prime factor of the number base. while ($this->primes[$prime_ndx] <= $base_tmp) { // $non_repeat_tally must be initialized to 0 for each prime number in the cycle, so that the maximum tally can be determined. $non_repeat_tally = 0; $base_factor_tally = 0; // First, tally the occurrences of the present prime number in the base's set of factors. while (is_int($base_tmp / $this->primes[$prime_ndx])) { $base_tmp /= $this->primes[$prime_ndx]; $base_factor_tally++; } // If the present prime is indeed a factor of the base, process this block. if ($base_factor_tally > 0) { // This block will determine the number of non-repeating decimal places generated for the current prime number. The maximum value from this will be returned. $prime_power = pow($this->primes[$prime_ndx], $base_factor_tally); // First, divide out all complete sets of the present prime number from the denominator, and tally the number of divisions. while (is_int($denom_tmp / $prime_power)) { $denom_tmp /= $prime_power; $non_repeat_tally++; } // Second, check for any remaining instances of the prime number. If there are any, increment the tally, and divide out all that remain. if (is_int($denom_tmp / $this->primes[$prime_ndx])) { $non_repeat_tally++; while (is_int($denom_tmp / $this->primes[$prime_ndx])) { $denom_tmp /= $this->primes[$prime_ndx]; } } // Keep the $max_non_repeat_tally up-to-date. $max_non_repeat_tally = max($non_repeat_tally, $max_non_repeat_tally); } $prime_ndx++; } // If $denom_tmp is equal to 1 at this point, the denominator's prime factors are all included in the set of factors for the base, which means the decimal resolves. // If the denominator has no factors in common with the base, then there are no non-repeating digits. $retval = $denom_tmp == 1 ? -1 : $max_non_repeat_tally; return $retval; } private function get_gcf($int1, $int2) { $ints = array($int1, $int2); $finished = false; while (!$finished) { $ints = array(max($ints), min($ints)); if (is_int($ints[0] / $ints[1])) { $finished = true; } else { $ints[0] = $ints[0] - $ints[1]; } } return $ints[1]; } } ?>