Skip to content

Commit fee5127

Browse files
committed
fixup: rework the script a bit
1 parent 1ec96e9 commit fee5127

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

tools/math-constant/math-constant.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
script_path = os.path.relpath(script_realpath, root_dir)
99
file_path = "src/common/math/Constant.h"
1010
file_realpath = os.path.join(root_dir, file_path)
11+
file_handle = open(file_realpath, "w")
1112

1213
header = "// Generated with {}\n".format(script_path)
1314
header += "// Do not modify!"
@@ -264,6 +265,16 @@ class _long_double:
264265

265266
# types.append(_long_double)
266267

268+
def beautify(v):
269+
value = str(v);
270+
if value.startswith("0."):
271+
value = value[1:]
272+
return value
273+
274+
def output(string=""):
275+
print(string)
276+
print(string, file=file_handle)
277+
267278
keyword = "constexpr"
268279
value = "0"
269280

@@ -281,12 +292,6 @@ class _long_double:
281292
operation_pad = len(operation_head)
282293
gnu_pad = len(gnu_head)
283294

284-
file_handle = open(file_realpath, "w")
285-
286-
def output(string=""):
287-
print(string)
288-
print(string, file=file_handle)
289-
290295
output(header)
291296
output()
292297
output("#ifndef {}".format(header_id))
@@ -330,9 +335,7 @@ def output(string=""):
330335
else:
331336
std = ""
332337

333-
value = str(c.compute()) + t.suffix
334-
if value.startswith("0."):
335-
value = value[1:]
338+
value = beautify(c.compute()) + t.suffix
336339

337340
l = len(value)
338341
if l > value_pad:
@@ -358,9 +361,7 @@ def output(string=""):
358361
else:
359362
std = ""
360363

361-
value = str(c.compute()) + t.suffix
362-
if value.startswith("0."):
363-
value = value[1:]
364+
value = beautify(c.compute()) + t.suffix
364365

365366
fields = keyword, t.name, name, "=", value, ";", "//", c.operation, gnu, std
366367
output(string.format(*fields).rstrip())

0 commit comments

Comments
 (0)