8
8
script_path = os .path .relpath (script_realpath , root_dir )
9
9
file_path = "src/common/math/Constant.h"
10
10
file_realpath = os .path .join (root_dir , file_path )
11
+ file_handle = open (file_realpath , "w" )
11
12
12
13
header = "// Generated with {}\n " .format (script_path )
13
14
header += "// Do not modify!"
@@ -264,6 +265,16 @@ class _long_double:
264
265
265
266
# types.append(_long_double)
266
267
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
+
267
278
keyword = "constexpr"
268
279
value = "0"
269
280
@@ -281,12 +292,6 @@ class _long_double:
281
292
operation_pad = len (operation_head )
282
293
gnu_pad = len (gnu_head )
283
294
284
- file_handle = open (file_realpath , "w" )
285
-
286
- def output (string = "" ):
287
- print (string )
288
- print (string , file = file_handle )
289
-
290
295
output (header )
291
296
output ()
292
297
output ("#ifndef {}" .format (header_id ))
@@ -330,9 +335,7 @@ def output(string=""):
330
335
else :
331
336
std = ""
332
337
333
- value = str (c .compute ()) + t .suffix
334
- if value .startswith ("0." ):
335
- value = value [1 :]
338
+ value = beautify (c .compute ()) + t .suffix
336
339
337
340
l = len (value )
338
341
if l > value_pad :
@@ -358,9 +361,7 @@ def output(string=""):
358
361
else :
359
362
std = ""
360
363
361
- value = str (c .compute ()) + t .suffix
362
- if value .startswith ("0." ):
363
- value = value [1 :]
364
+ value = beautify (c .compute ()) + t .suffix
364
365
365
366
fields = keyword , t .name , name , "=" , value , ";" , "//" , c .operation , gnu , std
366
367
output (string .format (* fields ).rstrip ())
0 commit comments