* hb_reduce64 ********************************************************************** * Given a numerator (num) and a denominator (den), reduce them to an * equivalent fraction and store the result in x and y. *********************************************************************/
| 3787 | * equivalent fraction and store the result in x and y. |
| 3788 | *********************************************************************/ |
| 3789 | void hb_reduce64( int64_t *x, int64_t *y, int64_t num, int64_t den ) |
| 3790 | { |
| 3791 | // find the greatest common divisor of num & den by Euclid's algorithm |
| 3792 | int64_t n = num, d = den; |
| 3793 | while ( d ) |
| 3794 | { |
| 3795 | int64_t t = d; |
| 3796 | d = n % d; |
| 3797 | n = t; |
| 3798 | } |
| 3799 | |
| 3800 | // at this point n is the gcd. if it's non-zero remove it from num |
| 3801 | // and den. Otherwise just return the original values. |
| 3802 | if ( n ) |
| 3803 | { |
| 3804 | num /= n; |
| 3805 | den /= n; |
| 3806 | } |
| 3807 | |
| 3808 | *x = num; |
| 3809 | *y = den; |
| 3810 | |
| 3811 | } |
| 3812 | |
| 3813 | void hb_limit_rational64( int64_t *x, int64_t *y, int64_t num, int64_t den, int64_t limit ) |
| 3814 | { |
no outgoing calls
no test coverage detected