# Wolfram CloudResource Object

Function Resource

# RealRationalize

Express a real number as a nearby rational number

 ResourceFunction["RealRationalize"][r] expresses real number r as a rational number p/q.

## Details and Options

ResourceFunction["RealRationalize"] uses RealDigits to compute its answer.
Unlike Rationalize which returns rational numbers only under certain conditions, ResourceFunction["RealRationalize"] returns a rational numbers for most real number inputs.
ResourceFunction["RealRationalize"] works with complex numbers by operating on its real and imaginary parts directly.

## Examples

### Basic Examples (3)

Express 0.5 as a rational number:

 In[1]:=
 Out[1]=

Express the machine precision approximation of π as a rational number:

 In[2]:=
 Out[2]=

Express a 50-digit approximation of π as a rational number:

 In[3]:=
 Out[3]=

### Scope (5)

Integers are returned unchanged:

 In[4]:=
 Out[4]=

Rationals are returned unchanged:

 In[5]:=
 Out[5]=

Exact representations of irrational numbers are returned unchanged:

 In[6]:=
 Out[6]=

RealRationalize also works with complex numbers by applying itself to the real and imaginary parts of that number:

 In[7]:=
 Out[7]=

RealRationalize has the Listable attribute, so it automatically works with lists:

 In[8]:=
 Out[8]=

### Properties and Relations (4)

Converting the rational representation back to a real number typically yields the original real number:

 In[9]:=
 Out[9]=
 In[10]:=
 Out[10]=
 In[11]:=
 Out[11]=

Unlike Rationalize, which has specific constraints on which numbers are rationalized and which ones are not, RealRationalize always attempts to return the nearest a rational number using RealDigits as its guide:

 In[12]:=
 Out[12]=
 In[13]:=
 Out[13]=

RealRationalize simply finds a close approximation, whereas Rationalize aims to find a human-friendly approximation:

 In[14]:=
 Out[14]=
 In[15]:=
 Out[15]=
 In[16]:=
 Out[16]=

RealRationalize may give slightly "better" results than Rationalize for certain special real number inputs:

 In[17]:=
 Out[17]=
 In[18]:=
 Out[18]=
 In[19]:=
 Out[19]=

### Possible Issues (2)

No attempt is made to rationalize exact representations of irrational numbers:

 In[20]:=
 Out[20]=

Convert these numbers to a machine or high-precision real first:

 In[21]:=
 Out[21]=