summary refs log tree commit diff stats
path: root/lib/std/formatfloat.nim
blob: b216d1fd067108fda1766557e976dede012f308e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#
#
#            Nim's Runtime Library
#        (c) Copyright 2022 Nim contributors
#
#    See the file "copying.txt", included in this
#    distribution, for details about the copyright.
#

## This module implements formatting floats as strings.

when defined(nimPreviewSlimSystem):
  import std/assertions

proc c_memcpy(a, b: pointer, size: csize_t): pointer {.importc: "memcpy", header: "<string.h>", discardable.}

proc addCstringN(result: var string, buf: cstring; buflen: int) =
  # no nimvm support needed, so it doesn't need to be fast here either
  let oldLen = result.len
  let newLen = oldLen + buflen
  result.setLen newLen
  c_memcpy(result[oldLen].addr, buf, buflen.csize_t)

import std/private/[dragonbox, schubfach]

proc writeFloatToBufferRoundtrip*(buf: var array[65, char]; value: BiggestFloat): int =
  ## This is the implementation to format floats.
  ##
  ## returns the amount of bytes written to `buf` not counting the
  ## terminating '\0' character.
  result = toChars(buf, value, forceTrailingDotZero=true).int
  buf[result] = '\0'

proc writeFloatToBufferRoundtrip*(buf: var array[65, char]; value: float32): int =
  result = float32ToChars(buf, value, forceTrailingDotZero=true).int
  buf[result] = '\0'

proc c_sprintf(buf, frmt: cstring): cint {.header: "<stdio.h>",
                                    importc: "sprintf", varargs, noSideEffect.}

proc writeToBuffer(buf: var array[65, char]; value: cstring) =
  var i = 0
  while value[i] != '\0':
    buf[i] = value[i]
    inc i

proc writeFloatToBufferSprintf*(buf: var array[65, char]; value: BiggestFloat): int =
  ## This is the implementation to format floats.
  ##
  ## returns the amount of bytes written to `buf` not counting the
  ## terminating '\0' character.
  var n = c_sprintf(cast[cstring](addr buf), "%.16g", value).int
  var hasDot = false
  for i in 0..n-1:
    if buf[i] == ',':
      buf[i] = '.'
      hasDot = true
    elif buf[i] in {'a'..'z', 'A'..'Z', '.'}:
      hasDot = true
  if not hasDot:
    buf[n] = '.'
    buf[n+1] = '0'
    buf[n+2] = '\0'
    result = n + 2
  else:
    result = n
  # On Windows nice numbers like '1.#INF', '-1.#INF' or '1.#NAN' or 'nan(ind)'
  # of '-1.#IND' are produced.
  # We want to get rid of these here:
  if buf[n-1] in {'n', 'N', 'D', 'd', ')'}:
    writeToBuffer(buf, "nan")
    result = 3
  elif buf[n-1] == 'F':
    if buf[0] == '-':
      writeToBuffer(buf, "-inf")
      result = 4
    else:
      writeToBuffer(buf, "inf")
      result = 3

proc writeFloatToBuffer*(buf: var array[65, char]; value: BiggestFloat | float32): int {.inline.} =
  when defined(nimPreviewFloatRoundtrip) or defined(nimPreviewSlimSystem):
    writeFloatToBufferRoundtrip(buf, value)
  else:
    writeFloatToBufferSprintf(buf, value)

proc addFloatRoundtrip*(result: var string; x: float | float32) =
  when nimvm:
    doAssert false
  else:
    var buffer {.noinit.}: array[65, char]
    let n = writeFloatToBufferRoundtrip(buffer, x)
    result.addCstringN(cast[cstring](buffer[0].addr), n)

proc addFloatSprintf*(result: var string; x: float) =
  when nimvm:
    doAssert false
  else:
    var buffer {.noinit.}: array[65, char]
    let n = writeFloatToBufferSprintf(buffer, x)
    result.addCstringN(cast[cstring](buffer[0].addr), n)

proc nimFloatToString(a: float): cstring =
  ## ensures the result doesn't print like an integer, i.e. return 2.0, not 2
  # print `-0.0` properly
  asm """
    function nimOnlyDigitsOrMinus(n) {
      return n.toString().match(/^-?\d+$/);
    }
    if (Number.isSafeInteger(`a`))
      `result` = `a` === 0 && 1 / `a` < 0 ? "-0.0" : `a`+".0"
    else {
      `result` = `a`+""
      if(nimOnlyDigitsOrMinus(`result`)){
        `result` = `a`+".0"
      }
    }
  """

proc addFloat*(result: var string; x: float | float32) {.inline.} =
  ## Converts float to its string representation and appends it to `result`.
  runnableExamples:
    var
      s = "foo:"
      b = 45.67
    s.addFloat(45.67)
    assert s == "foo:45.67"
  template impl =
    when defined(nimPreviewFloatRoundtrip) or defined(nimPreviewSlimSystem):
      addFloatRoundtrip(result, x)
    else:
      addFloatSprintf(result, x)
  when defined(js):
    when nimvm: impl()
    else:
      result.add nimFloatToString(x)
  else: impl()

when defined(nimPreviewSlimSystem):
  func `$`*(x: float | float32): string =
    ## Outplace version of `addFloat`.
    result.addFloat(x)
p;return&nbsp;the&nbsp;max&nbsp;recursion&nbsp;depth&nbsp;for&nbsp;the&nbsp;interpreter<br> <a href="#-getsizeof">getsizeof</a>()&nbsp;--&nbsp;return&nbsp;the&nbsp;size&nbsp;of&nbsp;an&nbsp;object&nbsp;in&nbsp;bytes<br> <a href="#-gettrace">gettrace</a>()&nbsp;--&nbsp;get&nbsp;the&nbsp;global&nbsp;debug&nbsp;tracing&nbsp;function<br> <a href="#-setcheckinterval">setcheckinterval</a>()&nbsp;--&nbsp;control&nbsp;how&nbsp;often&nbsp;the&nbsp;interpreter&nbsp;checks&nbsp;for&nbsp;events<br> <a href="#-setdlopenflags">setdlopenflags</a>()&nbsp;--&nbsp;set&nbsp;the&nbsp;flags&nbsp;to&nbsp;be&nbsp;used&nbsp;for&nbsp;dlopen()&nbsp;calls<br> <a href="#-setprofile">setprofile</a>()&nbsp;--&nbsp;set&nbsp;the&nbsp;global&nbsp;profiling&nbsp;function<br> <a href="#-setrecursionlimit">setrecursionlimit</a>()&nbsp;--&nbsp;set&nbsp;the&nbsp;max&nbsp;recursion&nbsp;depth&nbsp;for&nbsp;the&nbsp;interpreter<br> <a href="#-settrace">settrace</a>()&nbsp;--&nbsp;set&nbsp;the&nbsp;global&nbsp;debug&nbsp;tracing&nbsp;function</tt></p> <p> <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> <tr bgcolor="#eeaa77"> <td colspan=3 valign=bottom>&nbsp;<br> <font color="#ffffff" face="helvetica, arial"><big><strong>Functions</strong></big></font></td></tr> <tr><td bgcolor="#eeaa77"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td> <td width="100%"><dl><dt><a name="-__displayhook__"><strong>__displayhook__</strong></a> = displayhook(...)</dt><dd><tt><a href="#-displayhook">displayhook</a>(object)&nbsp;-&gt;&nbsp;None<br> &nbsp;<br> Print&nbsp;an&nbsp;object&nbsp;to&nbsp;sys.stdout&nbsp;and&nbsp;also&nbsp;save&nbsp;it&nbsp;in&nbsp;builtins.</tt></dd></dl> <dl><dt><a name="-__excepthook__"><strong>__excepthook__</strong></a> = excepthook(...)</dt><dd><tt><a href="#-excepthook">excepthook</a>(exctype,&nbsp;value,&nbsp;traceback)&nbsp;-&gt;&nbsp;None<br> &nbsp;<br> Handle&nbsp;an&nbsp;exception&nbsp;by&nbsp;displaying&nbsp;it&nbsp;with&nbsp;a&nbsp;traceback&nbsp;on&nbsp;sys.stderr.</tt></dd></dl> <dl><dt><a name="-call_tracing"><strong>call_tracing</strong></a>(...)</dt><dd><tt><a href="#-call_tracing">call_tracing</a>(func,&nbsp;args)&nbsp;-&gt;&nbsp;object<br> &nbsp;<br> Call&nbsp;func(*args),&nbsp;while&nbsp;tracing&nbsp;is&nbsp;enabled.&nbsp;&nbsp;The&nbsp;tracing&nbsp;state&nbsp;is<br> saved,&nbsp;and&nbsp;restored&nbsp;afterwards.&nbsp;&nbsp;This&nbsp;is&nbsp;intended&nbsp;to&nbsp;be&nbsp;called&nbsp;from<br> a&nbsp;debugger&nbsp;from&nbsp;a&nbsp;checkpoint,&nbsp;to&nbsp;recursively&nbsp;debug&nbsp;some&nbsp;other&nbsp;code.</tt></dd></dl> <dl><dt><a name="-callstats"><strong>callstats</strong></a>(...)</dt><dd><tt><a href="#-callstats">callstats</a>()&nbsp;-&gt;&nbsp;tuple&nbsp;of&nbsp;integers<br> &nbsp;<br> Return&nbsp;a&nbsp;tuple&nbsp;of&nbsp;function&nbsp;call&nbsp;statistics,&nbsp;if&nbsp;CALL_PROFILE&nbsp;was&nbsp;defined<br> when&nbsp;Python&nbsp;was&nbsp;built.&nbsp;&nbsp;Otherwise,&nbsp;return&nbsp;None.<br> &nbsp;<br> When&nbsp;enabled,&nbsp;this&nbsp;function&nbsp;returns&nbsp;detailed,&nbsp;implementation-specific<br> details&nbsp;about&nbsp;the&nbsp;number&nbsp;of&nbsp;function&nbsp;calls&nbsp;executed.&nbsp;The&nbsp;return&nbsp;value&nbsp;is<br> a&nbsp;11-tuple&nbsp;where&nbsp;the&nbsp;entries&nbsp;in&nbsp;the&nbsp;tuple&nbsp;are&nbsp;counts&nbsp;of:<br> 0.&nbsp;all&nbsp;function&nbsp;calls<br> 1.&nbsp;calls&nbsp;to&nbsp;PyFunction_Type&nbsp;objects<br> 2.&nbsp;PyFunction&nbsp;calls&nbsp;that&nbsp;do&nbsp;not&nbsp;create&nbsp;an&nbsp;argument&nbsp;tuple<br> 3.&nbsp;PyFunction&nbsp;calls&nbsp;that&nbsp;do&nbsp;not&nbsp;create&nbsp;an&nbsp;argument&nbsp;tuple<br> &nbsp;&nbsp;&nbsp;and&nbsp;bypass&nbsp;PyEval_EvalCodeEx()<br> 4.&nbsp;PyMethod&nbsp;calls<br> 5.&nbsp;PyMethod&nbsp;calls&nbsp;on&nbsp;bound&nbsp;methods<br> 6.&nbsp;PyType&nbsp;calls<br> 7.&nbsp;PyCFunction&nbsp;calls<br> 8.&nbsp;generator&nbsp;calls<br> 9.&nbsp;All&nbsp;other&nbsp;calls<br> 10.&nbsp;Number&nbsp;of&nbsp;stack&nbsp;pops&nbsp;performed&nbsp;by&nbsp;call_function()</tt></dd></dl> <dl><dt><a name="-displayhook"><strong>displayhook</strong></a>(...)</dt><dd><tt><a href="#-displayhook">displayhook</a>(object)&nbsp;-&gt;&nbsp;None<br> &nbsp;<br> Print&nbsp;an&nbsp;object&nbsp;to&nbsp;sys.stdout&nbsp;and&nbsp;also&nbsp;save&nbsp;it&nbsp;in&nbsp;builtins.</tt></dd></dl> <dl><dt><a name="-exc_info"><strong>exc_info</strong></a>(...)</dt><dd><tt><a href="#-exc_info">exc_info</a>()&nbsp;-&gt;&nbsp;(type,&nbsp;value,&nbsp;traceback)<br> &nbsp;<br> Return&nbsp;information&nbsp;about&nbsp;the&nbsp;most&nbsp;recent&nbsp;exception&nbsp;caught&nbsp;by&nbsp;an&nbsp;except<br> clause&nbsp;in&nbsp;the&nbsp;current&nbsp;stack&nbsp;frame&nbsp;or&nbsp;in&nbsp;an&nbsp;older&nbsp;stack&nbsp;frame.</tt></dd></dl> <dl><dt><a name="-excepthook"><strong>excepthook</strong></a>(...)</dt><dd><tt><a href="#-excepthook">excepthook</a>(exctype,&nbsp;value,&nbsp;traceback)&nbsp;-&gt;&nbsp;None<br> &nbsp;<br> Handle&nbsp;an&nbsp;exception&nbsp;by&nbsp;displaying&nbsp;it&nbsp;with&nbsp;a&nbsp;traceback&nbsp;on&nbsp;sys.stderr.</tt></dd></dl> <dl><dt><a name="-exit"><strong>exit</strong></a>(...)</dt><dd><tt><a href="#-exit">exit</a>([status])<br> &nbsp;<br> Exit&nbsp;the&nbsp;interpreter&nbsp;by&nbsp;raising&nbsp;SystemExit(status).<br> If&nbsp;the&nbsp;status&nbsp;is&nbsp;omitted&nbsp;or&nbsp;None,&nbsp;it&nbsp;defaults&nbsp;to&nbsp;zero&nbsp;(i.e.,&nbsp;success).<br> If&nbsp;the&nbsp;status&nbsp;is&nbsp;numeric,&nbsp;it&nbsp;will&nbsp;be&nbsp;used&nbsp;as&nbsp;the&nbsp;system&nbsp;exit&nbsp;status.<br> If&nbsp;it&nbsp;is&nbsp;another&nbsp;kind&nbsp;of&nbsp;object,&nbsp;it&nbsp;will&nbsp;be&nbsp;printed&nbsp;and&nbsp;the&nbsp;system<br> exit&nbsp;status&nbsp;will&nbsp;be&nbsp;one&nbsp;(i.e.,&nbsp;failure).</tt></dd></dl> <dl><dt><a name="-getcheckinterval"><strong>getcheckinterval</strong></a>(...)</dt><dd><tt><a href="#-getcheckinterval">getcheckinterval</a>()&nbsp;-&gt;&nbsp;current&nbsp;check&nbsp;interval;&nbsp;see&nbsp;<a href="#-setcheckinterval">setcheckinterval</a>().</tt></dd></dl> <dl><dt><a name="-getdefaultencoding"><strong>getdefaultencoding</strong></a>(...)</dt><dd><tt><a href="#-getdefaultencoding">getdefaultencoding</a>()&nbsp;-&gt;&nbsp;string<br> &nbsp;<br> Return&nbsp;the&nbsp;current&nbsp;default&nbsp;string&nbsp;encoding&nbsp;used&nbsp;by&nbsp;the&nbsp;Unicode&nbsp;<br> implementation.</tt></dd></dl> <dl><dt><a name="-getdlopenflags"><strong>getdlopenflags</strong></a>(...)</dt><dd><tt><a href="#-getdlopenflags">getdlopenflags</a>()&nbsp;-&gt;&nbsp;int<br> &nbsp;<br> Return&nbsp;the&nbsp;current&nbsp;value&nbsp;of&nbsp;the&nbsp;flags&nbsp;that&nbsp;are&nbsp;used&nbsp;for&nbsp;dlopen&nbsp;calls.<br> The&nbsp;flag&nbsp;constants&nbsp;are&nbsp;defined&nbsp;in&nbsp;the&nbsp;ctypes&nbsp;and&nbsp;DLFCN&nbsp;modules.</tt></dd></dl> <dl><dt><a name="-getfilesystemencoding"><strong>getfilesystemencoding</strong></a>(...)</dt><dd><tt><a href="#-getfilesystemencoding">getfilesystemencoding</a>()&nbsp;-&gt;&nbsp;string<br> &nbsp;<br> Return&nbsp;the&nbsp;encoding&nbsp;used&nbsp;to&nbsp;convert&nbsp;Unicode&nbsp;filenames&nbsp;in<br> operating&nbsp;system&nbsp;filenames.</tt></dd></dl> <dl><dt><a name="-getprofile"><strong>getprofile</strong></a>(...)</dt><dd><tt><a href="#-getprofile">getprofile</a>()<br> &nbsp;<br> Return&nbsp;the&nbsp;profiling&nbsp;function&nbsp;set&nbsp;with&nbsp;sys.setprofile.<br> See&nbsp;the&nbsp;profiler&nbsp;chapter&nbsp;in&nbsp;the&nbsp;library&nbsp;manual.</tt></dd></dl> <dl><dt><a name="-getrecursionlimit"><strong>getrecursionlimit</strong></a>(...)</dt><dd><tt><a href="#-getrecursionlimit">getrecursionlimit</a>()<br> &nbsp;<br> Return&nbsp;the&nbsp;current&nbsp;value&nbsp;of&nbsp;the&nbsp;recursion&nbsp;limit,&nbsp;the&nbsp;maximum&nbsp;depth<br> of&nbsp;the&nbsp;Python&nbsp;interpreter&nbsp;stack.&nbsp;&nbsp;This&nbsp;limit&nbsp;prevents&nbsp;infinite<br> recursion&nbsp;from&nbsp;causing&nbsp;an&nbsp;overflow&nbsp;of&nbsp;the&nbsp;C&nbsp;stack&nbsp;and&nbsp;crashing&nbsp;Python.</tt></dd></dl> <dl><dt><a name="-getrefcount"><strong>getrefcount</strong></a>(...)</dt><dd><tt><a href="#-getrefcount">getrefcount</a>(object)&nbsp;-&gt;&nbsp;integer<br> &nbsp;<br> Return&nbsp;the&nbsp;reference&nbsp;count&nbsp;of&nbsp;object.&nbsp;&nbsp;The&nbsp;count&nbsp;returned&nbsp;is&nbsp;generally<br> one&nbsp;higher&nbsp;than&nbsp;you&nbsp;might&nbsp;expect,&nbsp;because&nbsp;it&nbsp;includes&nbsp;the&nbsp;(temporary)<br> reference&nbsp;as&nbsp;an&nbsp;argument&nbsp;to&nbsp;<a href="#-getrefcount">getrefcount</a>().</tt></dd></dl> <dl><dt><a name="-getsizeof"><strong>getsizeof</strong></a>(...)</dt><dd><tt><a href="#-getsizeof">getsizeof</a>(object,&nbsp;default)&nbsp;-&gt;&nbsp;int<br> &nbsp;<br> Return&nbsp;the&nbsp;size&nbsp;of&nbsp;object&nbsp;in&nbsp;bytes.</tt></dd></dl> <dl><dt><a name="-gettrace"><strong>gettrace</strong></a>(...)</dt><dd><tt><a href="#-gettrace">gettrace</a>()<br> &nbsp;<br> Return&nbsp;the&nbsp;global&nbsp;debug&nbsp;tracing&nbsp;function&nbsp;set&nbsp;with&nbsp;sys.settrace.<br> See&nbsp;the&nbsp;debugger&nbsp;chapter&nbsp;in&nbsp;the&nbsp;library&nbsp;manual.</tt></dd></dl> <dl><dt><a name="-intern"><strong>intern</strong></a>(...)</dt><dd><tt><a href="#-intern">intern</a>(string)&nbsp;-&gt;&nbsp;string<br> &nbsp;<br> ``Intern''&nbsp;the&nbsp;given&nbsp;string.&nbsp;&nbsp;This&nbsp;enters&nbsp;the&nbsp;string&nbsp;in&nbsp;the&nbsp;(global)<br> table&nbsp;of&nbsp;interned&nbsp;strings&nbsp;whose&nbsp;purpose&nbsp;is&nbsp;to&nbsp;speed&nbsp;up&nbsp;dictionary&nbsp;lookups.<br> Return&nbsp;the&nbsp;string&nbsp;itself&nbsp;or&nbsp;the&nbsp;previously&nbsp;interned&nbsp;string&nbsp;object&nbsp;with&nbsp;the<br> same&nbsp;value.</tt></dd></dl> <dl><dt><a name="-setcheckinterval"><strong>setcheckinterval</strong></a>(...)</dt><dd><tt><a href="#-setcheckinterval">setcheckinterval</a>(n)<br> &nbsp;<br> Tell&nbsp;the&nbsp;Python&nbsp;interpreter&nbsp;to&nbsp;check&nbsp;for&nbsp;asynchronous&nbsp;events&nbsp;every<br> n&nbsp;instructions.&nbsp;&nbsp;This&nbsp;also&nbsp;affects&nbsp;how&nbsp;often&nbsp;thread&nbsp;switches&nbsp;occur.</tt></dd></dl> <dl><dt><a name="-setdlopenflags"><strong>setdlopenflags</strong></a>(...)</dt><dd><tt><a href="#-setdlopenflags">setdlopenflags</a>(n)&nbsp;-&gt;&nbsp;None<br> &nbsp;<br> Set&nbsp;the&nbsp;flags&nbsp;used&nbsp;by&nbsp;the&nbsp;interpreter&nbsp;for&nbsp;dlopen&nbsp;calls,&nbsp;such&nbsp;as&nbsp;when&nbsp;the<br> interpreter&nbsp;loads&nbsp;extension&nbsp;modules.&nbsp;&nbsp;Among&nbsp;other&nbsp;things,&nbsp;this&nbsp;will&nbsp;enable<br> a&nbsp;lazy&nbsp;resolving&nbsp;of&nbsp;symbols&nbsp;when&nbsp;importing&nbsp;a&nbsp;module,&nbsp;if&nbsp;called&nbsp;as<br> sys.<a href="#-setdlopenflags">setdlopenflags</a>(0).&nbsp;&nbsp;To&nbsp;share&nbsp;symbols&nbsp;across&nbsp;extension&nbsp;modules,&nbsp;call&nbsp;as<br> sys.<a href="#-setdlopenflags">setdlopenflags</a>(ctypes.RTLD_GLOBAL).&nbsp;&nbsp;Symbolic&nbsp;names&nbsp;for&nbsp;the&nbsp;flag&nbsp;modules<br> can&nbsp;be&nbsp;either&nbsp;found&nbsp;in&nbsp;the&nbsp;ctypes&nbsp;module,&nbsp;or&nbsp;in&nbsp;the&nbsp;DLFCN&nbsp;module.&nbsp;If&nbsp;DLFCN<br> is&nbsp;not&nbsp;available,&nbsp;it&nbsp;can&nbsp;be&nbsp;generated&nbsp;from&nbsp;/usr/include/dlfcn.h&nbsp;using&nbsp;the<br> h2py&nbsp;script.</tt></dd></dl> <dl><dt><a name="-setfilesystemencoding"><strong>setfilesystemencoding</strong></a>(...)</dt><dd><tt><a href="#-setfilesystemencoding">setfilesystemencoding</a>(string)&nbsp;-&gt;&nbsp;None<br> &nbsp;<br> Set&nbsp;the&nbsp;encoding&nbsp;used&nbsp;to&nbsp;convert&nbsp;Unicode&nbsp;filenames&nbsp;in<br> operating&nbsp;system&nbsp;filenames.</tt></dd></dl> <dl><dt><a name="-setprofile"><strong>setprofile</strong></a>(...)</dt><dd><tt><a href="#-setprofile">setprofile</a>(function)<br> &nbsp;<br> Set&nbsp;the&nbsp;profiling&nbsp;function.&nbsp;&nbsp;It&nbsp;will&nbsp;be&nbsp;called&nbsp;on&nbsp;each&nbsp;function&nbsp;call<br> and&nbsp;return.&nbsp;&nbsp;See&nbsp;the&nbsp;profiler&nbsp;chapter&nbsp;in&nbsp;the&nbsp;library&nbsp;manual.</tt></dd></dl> <dl><dt><a name="-setrecursionlimit"><strong>setrecursionlimit</strong></a>(...)</dt><dd><tt><a href="#-setrecursionlimit">setrecursionlimit</a>(n)<br> &nbsp;<br> Set&nbsp;the&nbsp;maximum&nbsp;depth&nbsp;of&nbsp;the&nbsp;Python&nbsp;interpreter&nbsp;stack&nbsp;to&nbsp;n.&nbsp;&nbsp;This<br> limit&nbsp;prevents&nbsp;infinite&nbsp;recursion&nbsp;from&nbsp;causing&nbsp;an&nbsp;overflow&nbsp;of&nbsp;the&nbsp;C<br> stack&nbsp;and&nbsp;crashing&nbsp;Python.&nbsp;&nbsp;The&nbsp;highest&nbsp;possible&nbsp;limit&nbsp;is&nbsp;platform-<br> dependent.</tt></dd></dl> <dl><dt><a name="-settrace"><strong>settrace</strong></a>(...)</dt><dd><tt><a href="#-settrace">settrace</a>(function)<br> &nbsp;<br> Set&nbsp;the&nbsp;global&nbsp;debug&nbsp;tracing&nbsp;function.&nbsp;&nbsp;It&nbsp;will&nbsp;be&nbsp;called&nbsp;on&nbsp;each<br> function&nbsp;call.&nbsp;&nbsp;See&nbsp;the&nbsp;debugger&nbsp;chapter&nbsp;in&nbsp;the&nbsp;library&nbsp;manual.</tt></dd></dl> </td></tr></table><p> <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> <tr bgcolor="#55aa55"> <td colspan=3 valign=bottom>&nbsp;<br> <font color="#ffffff" face="helvetica, arial"><big><strong>Data</strong></big></font></td></tr> <tr><td bgcolor="#55aa55"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td> <td width="100%"><strong>__stderr__</strong> = &lt;_io.TextIOWrapper name='&lt;stderr&gt;' encoding='UTF-8'&gt;<br> <strong>__stdin__</strong> = &lt;_io.TextIOWrapper name='&lt;stdin&gt;' encoding='UTF-8'&gt;<br> <strong>__stdout__</strong> = &lt;_io.TextIOWrapper name='&lt;stdout&gt;' encoding='UTF-8'&gt;<br> <strong>api_version</strong> = 1013<br> <strong>argv</strong> = ['./make_doc.py']<br> <strong>builtin_module_names</strong> = ('__main__', '_ast', '_codecs', '_functools', '_io', '_locale', '_sre', '_symtable', '_thread', '_warnings', '_weakref', 'builtins', 'errno', 'gc', 'imp', 'marshal', 'posix', 'pwd', 'signal', 'sys', ...)<br> <strong>byteorder</strong> = 'little'<br> <strong>copyright</strong> = 'Copyright (c) 2001-2009 Python Software Foundati...ematisch Centrum, Amsterdam.<font color="#c040c0">\n</font>All Rights Reserved.'<br> <strong>dont_write_bytecode</strong> = False<br> <strong>exec_prefix</strong> = '/usr'<br> <strong>executable</strong> = '/usr/bin/python3'<br> <strong>flags</strong> = sys.flags(debug=0, division_warning=0, inspect=0...ignore_environment=0, verbose=0, bytes_warning=0)<br> <strong>float_info</strong> = sys.floatinfo(max=1.7976931348623157e+308, max_e...epsilon=2.220446049250313e-16, radix=2, rounds=1)<br> <strong>float_repr_style</strong> = 'short'<br> <strong>hexversion</strong> = 50397680<br> <strong>int_info</strong> = sys.int_info(bits_per_digit=30, sizeof_digit=4)<br> <strong>maxsize</strong> = 9223372036854775807<br> <strong>maxunicode</strong> = 1114111<br> <strong>meta_path</strong> = []<br> <strong>modules</strong> = {'__future__': &lt;module '__future__' from '/usr/lib/python3.1/__future__.py'&gt;, '__main__': &lt;module '__main__' from './make_doc.py'&gt;, '_abcoll': &lt;module '_abcoll' from '/usr/lib/python3.1/_abcoll.py'&gt;, '_bisect': &lt;module '_bisect' from '/usr/lib/python3.1/lib-dynload/_bisect.so'&gt;, '_codecs': &lt;module '_codecs' (built-in)&gt;, '_collections': &lt;module '_collections' from '/usr/lib/python3.1/lib-dynload/_collections.so'&gt;, '_compat_pickle': &lt;module '_compat_pickle' from '/usr/lib/python3.1/_compat_pickle.py'&gt;, '_curses': &lt;module '_curses' from '/usr/lib/python3.1/lib-dynload/_curses.so'&gt;, '_functools': &lt;module '_functools' (built-in)&gt;, '_heapq': &lt;module '_heapq' from '/usr/lib/python3.1/lib-dynload/_heapq.so'&gt;, ...}<br> <strong>path</strong> = ['/home/hut/work/ranger', '/usr/lib/python31.zip', '/usr/lib/python3.1', '/usr/lib/python3.1/plat-linux2', '/usr/lib/python3.1/lib-dynload', '/usr/lib/python3.1/site-packages', '/home/hut/.ranger']<br> <strong>path_hooks</strong> = [&lt;class 'zipimport.zipimporter'&gt;]<br> <strong>path_importer_cache</strong> = {'.': None, './make_doc.py': &lt;imp.NullImporter object at 0x7f28d26f79e0&gt;, '/home/hut/.ranger': None, '/home/hut/work/ranger': None, '/home/hut/work/ranger/ranger': None, '/home/hut/work/ranger/ranger/colorschemes': None, '/home/hut/work/ranger/ranger/container': None, '/home/hut/work/ranger/ranger/defaults': None, '/home/hut/work/ranger/ranger/ext': None, '/home/hut/work/ranger/ranger/fsobject': None, ...}<br> <strong>platform</strong> = 'linux2'<br> <strong>prefix</strong> = '/usr'<br> <strong>stderr</strong> = &lt;_io.TextIOWrapper name='&lt;stderr&gt;' encoding='UTF-8'&gt;<br> <strong>stdin</strong> = &lt;_io.TextIOWrapper name='&lt;stdin&gt;' encoding='UTF-8'&gt;<br> <strong>stdout</strong> = &lt;_io.TextIOWrapper name='&lt;stdout&gt;' encoding='UTF-8'&gt;<br> <strong>subversion</strong> = ('CPython', 'tags/r311', '74480')<br> <strong>version</strong> = '3.1.1 (r311:74480, Aug 27 2009, 04:56:37) <font color="#c040c0">\n</font>[GCC 4.4.1]'<br> <strong>version_info</strong> = sys.version_info(major=3, minor=1, micro=1, releaselevel='final', serial=0)<br> <strong>warnoptions</strong> = []</td></tr></table> </body></html>