A rational number can have several representations of the same value. Normalization reduces its numerator and denominator by their greatest common divisor, leaving no unnecessary common factors. section 10.2.2
12 rat rat_get_normal(rat x) {
13 size_t c = gcd(x.num, x.denom);
14 x.num /= c;
15 x.denom /= c;
16 return x;
17 }
!@%STYLE%@!
{"css":"{\"css\": \"font-weight: bold;\"}","target":"[[{\"line\":0,\"ch\":0},{\"line\":0,\"ch\":2}],[{\"line\":1,\"ch\":0},{\"line\":1,\"ch\":2}],[{\"line\":1,\"ch\":7},{\"line\":1,\"ch\":13}],[{\"line\":2,\"ch\":0},{\"line\":2,\"ch\":2}],[{\"line\":3,\"ch\":0},{\"line\":3,\"ch\":2}],[{\"line\":4,\"ch\":0},{\"line\":4,\"ch\":2}],[{\"line\":4,\"ch\":7},{\"line\":4,\"ch\":13}],[{\"line\":5,\"ch\":0},{\"line\":5,\"ch\":2}]]"}
!@%STYLE%@!
The function divides both fields by their greatest common divisor and returns the reduced value. section 10.2.2
Normalize results after rational multiplication or addition. Besides making representations easier to read, this can help avoid overflow during arithmetic. section 10.2.2




















