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

Function _replaceScaleFactors

SLiCAP/SLiCAPlex.py:216–239  ·  view source on GitHub ↗

Replaces scale factors in expressions with their value in scientific notation: :param txt: Expression or number with scale factors :type txt: str :return: out: Text in which scale factors are replaced with their corresponding scientific notation. :rtype: str

(txt)

Source from the content-addressed store, hash-verified

214 t.lexer.skip(1)
215
216def _replaceScaleFactors(txt):
217 """
218 Replaces scale factors in expressions with their value in scientific
219 notation:
220
221 :param txt: Expression or number with scale factors
222 :type txt: str
223
224 :return: out: Text in which scale factors are replaced with their
225 corresponding scientific notation.
226 :rtype: str
227
228 :Example:
229
230 >>> _replaceScaleFactors('sin(2*pi*1M)')
231 'sin(2*pi*1E6)'
232 """
233 pos = 0
234 out = ''
235 for m in re.finditer(r'\d+\.?\d*([yzafpnumkMGTP])', txt):
236 out += txt[pos: m.end()-1] + 'e' + _SCALEFACTORS[m.group(0)[-1]]
237 pos = m.end()
238 out += txt[pos:]
239 return out
240
241def _tokenize(netlist):
242 """

Callers 3

_checkNumberFunction · 0.90
str2numberFunction · 0.90
_checkExpressionFunction · 0.90

Calls 1

groupMethod · 0.80

Tested by

no test coverage detected