Converts floats in expr into rational numbers. :param expr: Sympy expression in which floats need to be converterd into rational numbers. :type expr: sympy.Expression :return: expression in which floats have been replaced with rational numbers. :rtype: sympy.
(expr)
| 1839 | return voltage |
| 1840 | |
| 1841 | def float2rational(expr): |
| 1842 | """ |
| 1843 | Converts floats in expr into rational numbers. |
| 1844 | |
| 1845 | :param expr: Sympy expression in which floats need to be converterd into |
| 1846 | rational numbers. |
| 1847 | :type expr: sympy.Expression |
| 1848 | |
| 1849 | :return: expression in which floats have been replaced with rational numbers. |
| 1850 | :rtype: sympy.Expression |
| 1851 | """ |
| 1852 | if type(expr) == int: |
| 1853 | pass |
| 1854 | elif type(expr) == float: |
| 1855 | expr = sp.Rational(expr) |
| 1856 | else: |
| 1857 | try: |
| 1858 | expr = expr.xreplace({n: sp.Rational(str(n)) |
| 1859 | for n in expr.atoms(sp.Float)}) |
| 1860 | except AttributeError: |
| 1861 | pass |
| 1862 | return expr |
| 1863 | |
| 1864 | def rational2float(expr): |
| 1865 | """ |
no outgoing calls
no test coverage detected