* hb_reduce ********************************************************************** * Given a numerator (num) and a denominator (den), reduce them to an * equivalent fraction and store the result in x and y. *********************************************************************/
| 3725 | * equivalent fraction and store the result in x and y. |
| 3726 | *********************************************************************/ |
| 3727 | void hb_reduce( int *x, int *y, int num, int den ) |
| 3728 | { |
| 3729 | // find the greatest common divisor of num & den by Euclid's algorithm |
| 3730 | int n = num, d = den; |
| 3731 | while ( d ) |
| 3732 | { |
| 3733 | int t = d; |
| 3734 | d = n % d; |
| 3735 | n = t; |
| 3736 | } |
| 3737 | |
| 3738 | // at this point n is the gcd. if it's non-zero remove it from num |
| 3739 | // and den. Otherwise just return the original values. |
| 3740 | if ( n ) |
| 3741 | { |
| 3742 | *x = num / n; |
| 3743 | *y = den / n; |
| 3744 | } |
| 3745 | else |
| 3746 | { |
| 3747 | *x = num; |
| 3748 | *y = den; |
| 3749 | } |
| 3750 | } |
| 3751 | |
| 3752 | void hb_limit_rational( int *x, int *y, int64_t num, int64_t den, int limit ) |
| 3753 | { |
no outgoing calls
no test coverage detected