Rational Numbers : Rational Numbers « Number « Ruby

Rational Numbers

A rational number is a number that can be expressed as a fraction of integers. 
Ruby supports the use of rational numbers via the Rational class. 
To use the Rational class, you must require it in the program. 
You create a rational number with the Rational method. 
Rational expects you to use integers, by the way. 
It will generate errors if you use floats.


Related examples in the same category

1.how to create a fraction;
2.Create a rational number
3.Add two rational number up
4.Subtract one number from another
5.Rational number without using Rational class
6.Multiply two rational numbers
7.Divide two rational numbers
8.how to add (+), subtract (-), multiply (*), and divide (/) fractions;
9.how to perform modulo (%), power (**), and equality (== or <=>);
10.how to produce a string or a float representation of a fraction (inspect).
11.Compare two rational numbers
12.Comparable operator on rational numbers
13.Inspect a rational number
14.Power a rational number
15.Modulo two rational numbers