Function Repository Resource:

RationalQ

Source Notebook

Determine if a number is rational

Contributed by: Ed Pegg Jr

ResourceFunction["RationalQ"][n]

returns True if n is rational and False otherwise.

Examples

Basic Examples (2) 

The fraction 2/3 is rational:

In[1]:=
ResourceFunction["RationalQ"][2/3]
Out[1]=

The integer 2 is rational:

In[2]:=
ResourceFunction["RationalQ"][2]
Out[2]=

Scope (2) 

The numbers and are not rational:

In[3]:=
ResourceFunction["RationalQ"] /@ {Sqrt[2], \[Pi]}
Out[3]=

Decimal numbers are not considered to be rational:

In[4]:=
ResourceFunction["RationalQ"][3.14]
Out[4]=

Requirements

Wolfram Language 13.0 (December 2021) or above

Version History

  • 1.0.0 – 25 October 2023

Related Resources

License Information