MCPcopy Index your code
hub / github.com/SLiCAP/SLiCAP_python / float2rational

Function float2rational

SLiCAP/SLiCAPmath.py:1841–1862  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

1839 return voltage
1840
1841def 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
1864def rational2float(expr):
1865 """

Callers 13

_getValueFunction · 0.90
_makeMatricesFunction · 0.90
_makeSrcVectorFunction · 0.90
_makeAllMatricesFunction · 0.90
_doPyLoopGainServoFunction · 0.90
_doPyNoiseFunction · 0.90
_doPyDCvarFunction · 0.90
detFunction · 0.85
fullSubsFunction · 0.85
besselPolyFunction · 0.85
chebyshev1PolyFunction · 0.85
_doVarNoiseDataFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected