Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Round near-integer values to integers
ResourceFunction["IntegerChop"][n] rounds n to an integer if n is close to an integer. | |
ResourceFunction["IntegerChop"][n,delta] rounds n if the absolute difference between n and the result is within delta. |
Round a real number close to 7 to the integer 7:
| In[1]:= |
|
| Out[1]= |
|
The following values are not close enough and remain unchanged:
| In[2]:= |
|
| Out[2]= |
|
| In[3]:= |
|
| Out[3]= |
|
Round elements of a list that are close to integers:
| In[4]:= |
|
| Out[4]= |
|
| In[5]:= |
|
| Out[5]= |
|
The Ramanujan constant gets chopped by default:
| In[6]:= |
|
| Out[6]= |
|
The number is within 10-10 of an integer:
| In[7]:= |
|
| Out[7]= |
|
A tighter bound eliminates the chopping:
| In[8]:= |
|
| Out[8]= |
|
This work is licensed under a Creative Commons Attribution 4.0 International License