ratio_less() function in C++

The ratio_less() is an inbuilt function in C++ which checks if the ratio R1 is less than the ratio R2. It returns True if the ratio is less than ratio 2, else it returns false.

Syntax:

template < class ratio1_name, class ratio2_name > ratio_less

Template Parameters: The function accepts two template parameters ratio1 and ratio2 which are to be compared.

Return value: The function returns a boolean value which is true if the ratio1 is less than ratio2 otherwise it returns false.

Below programs illustrates the above function:



Program 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

// C++ program to illustrate the
// ratio_less function
#include <iostream>
#include <ratio>
using namespace std;
int main()
{
    typedef ratio<3, 9> ratio1;
    typedef ratio<1, 3> ratio2;
  
    // check if R1<R2
    if (ratio_less<ratio1, ratio2>::value)
        cout << "3/9 is less than 1/3";
    else
        cout << "3/9 is not less than 1/3";
  
    return 0;
}

chevron_right


Output:

3/9 is not less than 1/3

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// C++ program to illustrate the
// ratio_less function
#include <iostream>
#include <ratio>
using namespace std;
int main()
{
    typedef ratio<1, 2> ratio1;
    typedef ratio<4, 7> ratio2;
  
    // check if R1<R2
    if (ratio_less<ratio1, ratio2>::value)
        cout << "1/2 is less than 4/7";
    else
        cout << "1/2 is not less than 4/7";
  
    return 0;
}

chevron_right


Output:

1/2 is less than 4/7


My Personal Notes arrow_drop_up

Contented with little yet wishing for more

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.