A rational type represents a rational number with a sign, numerator, and denominator. Its value is stored directly in a C structure. section 10.2.2
Rational type
The rational type is a book-specific C structure type representing a rational number with a numerator, denominator, and sign.
How Modern C, Third Edition covers it
- How deep it goes
- Defines the representation and demonstrates construction, normalization, multiplication, and addition, but stops short of a complete library.
- Examples
- Uses struct rat, rat_get, rat_get_normal, rat_get_prod, rat_get_sum, and the equivalent representations 6/15 and 2/5.
- What it assumes
- Assumes familiarity with C structures, bool, size_t, compound literals, and greatest common divisors.
- What you can do after
- Apply rational arithmetic through constructors and pure functions for normalization, multiplication, and addition.
- How it connects
- Connects rational arithmetic with pure functions, compound literals, greatest common divisors, normalization, and overflow avoidance.
This explainer was generated by Manning's knowledge graph from the text of Modern C, Third Edition. The section links point to the parts of the book it draws on.
