Skip to content

Commit c430ebd

Browse files
committed
fixup: constant generation: do not strip precision
1 parent dd52bb4 commit c430ebd

File tree

2 files changed

+67
-64
lines changed

2 files changed

+67
-64
lines changed

src/common/math/Constant.h

Lines changed: 50 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -5,57 +5,57 @@
55
#define COMMON_CONSTANT_H_
66

77
namespace Math {
8-
// Type Name Value Operation GNU std::numbers
9-
constexpr float phi_f = 1.61803399f; // φ phif
10-
constexpr float egamma_f = 1.56746826f; // Γe egammaf
11-
constexpr float ln2_f = .693147181f; // ln(2) M_LN2f ln2f
12-
constexpr float ln10_f = 2.30258509f; // ln(10) M_LN10f ln10f
13-
constexpr float log2e_f = 1.44269504f; // log2(e) M_LOG2Ef log2ef
14-
constexpr float log10e_f = .434294482f; // log10(e) M_LOG10Ef log10ef
15-
constexpr float pi_f = 3.14159265f; // π M_PIf pif
16-
constexpr float mul2_pi_f = 6.28318531f; //
17-
constexpr float inv_pi_f = .318309886f; // 1÷π M_1_PIf inv_pif
18-
constexpr float inv_mul2_pi_f = .159154943f; // 1÷2π
19-
constexpr float div2_pi_f = .636619772f; // 2÷π M_2_PIf
20-
constexpr float div180_pi_f = 57.2957795f; // 180÷π
21-
constexpr float divpi_2_f = 1.57079633f; // π÷2 M_PI_2f
22-
constexpr float divpi_4_f = .785398163f; // π÷4 M_PI_4f
23-
constexpr float divpi_90_f = .034906585f; // π÷90
24-
constexpr float divpi_180_f = .017453292f; // π÷180
25-
constexpr float divpi_360_f = .008726646f; // π÷360
26-
constexpr float sqrtpi_f = 1.77245385f; // √π sqrtpif
27-
constexpr float sqrt2_f = 1.41421356f; // √2 M_SQRT2f sqrt2f
28-
constexpr float sqrt3_f = 1.73205081f; // √3 sqrt3f
29-
constexpr float inv_sqrtpi_f = 1.77245385f; // 1÷√π inv_sqrtpif
30-
constexpr float inv_sqrt2_f = .707106781f; // 1÷√2 M_SQRT1_2f inv_sqrt2f
31-
constexpr float div2_sqrtpi_f = 1.12837917f; // 2÷√π M_2_SQRTPIf
32-
constexpr float inv_sqrt3_f = .577350269f; // 1÷√3 inv_sqrt3f
8+
// Type Name Value Operation GNU std::numbers
9+
constexpr float phi_f = 1.61803399f; // φ phif
10+
constexpr float egamma_f = 1.56746826f; // Γe egammaf
11+
constexpr float ln2_f = .693147181f; // ln(2) M_LN2f ln2f
12+
constexpr float ln10_f = 2.30258509f; // ln(10) M_LN10f ln10f
13+
constexpr float log2e_f = 1.44269504f; // log2(e) M_LOG2Ef log2ef
14+
constexpr float log10e_f = .434294482f; // log10(e) M_LOG10Ef log10ef
15+
constexpr float pi_f = 3.14159265f; // π M_PIf pif
16+
constexpr float mul2_pi_f = 6.28318531f; //
17+
constexpr float inv_pi_f = .318309886f; // 1÷π M_1_PIf inv_pif
18+
constexpr float inv_mul2_pi_f = .159154943f; // 1÷2π
19+
constexpr float div2_pi_f = .636619772f; // 2÷π M_2_PIf
20+
constexpr float div180_pi_f = 57.2957795f; // 180÷π
21+
constexpr float divpi_2_f = 1.57079633f; // π÷2 M_PI_2f
22+
constexpr float divpi_4_f = .785398163f; // π÷4 M_PI_4f
23+
constexpr float divpi_90_f = .034906585f; // π÷90
24+
constexpr float divpi_180_f = .0174532925f; // π÷180
25+
constexpr float divpi_360_f = .00872664626f; // π÷360
26+
constexpr float sqrtpi_f = 1.77245385f; // √π sqrtpif
27+
constexpr float sqrt2_f = 1.41421356f; // √2 M_SQRT2f sqrt2f
28+
constexpr float sqrt3_f = 1.73205081f; // √3 sqrt3f
29+
constexpr float inv_sqrtpi_f = 1.77245385f; // 1÷√π inv_sqrtpif
30+
constexpr float inv_sqrt2_f = .707106781f; // 1÷√2 M_SQRT1_2f inv_sqrt2f
31+
constexpr float div2_sqrtpi_f = 1.12837917f; // 2÷√π M_2_SQRTPIf
32+
constexpr float inv_sqrt3_f = .577350269f; // 1÷√3 inv_sqrt3f
3333

34-
// Type Name Value Operation GNU std::numbers
35-
constexpr double phi_d = 1.6180339887498948482; // φ phi
36-
constexpr double egamma_d = 1.5674682557740530749; // Γe egamma
37-
constexpr double ln2_d = .69314718055994530942; // ln(2) M_LN2 ln2
38-
constexpr double ln10_d = 2.3025850929940456840; // ln(10) M_LN10 ln10
39-
constexpr double log2e_d = 1.4426950408889634074; // log2(e) M_LOG2E log2e
40-
constexpr double log10e_d = .43429448190325182765; // log10(e) M_LOG10E log10e
41-
constexpr double pi_d = 3.1415926535897932385; // π M_PI pi
42-
constexpr double mul2_pi_d = 6.2831853071795864769; //
43-
constexpr double inv_pi_d = .31830988618379067154; // 1÷π M_1_PI inv_pi
44-
constexpr double inv_mul2_pi_d = .15915494309189533577; // 1÷2π
45-
constexpr double div2_pi_d = .63661977236758134308; // 2÷π M_2_PI
46-
constexpr double div180_pi_d = 57.295779513082320877; // 180÷π
47-
constexpr double divpi_2_d = 1.5707963267948966192; // π÷2 M_PI_2
48-
constexpr double divpi_4_d = .78539816339744830962; // π÷4 M_PI_4
49-
constexpr double divpi_90_d = .03490658503988659153; // π÷90
50-
constexpr double divpi_180_d = .01745329251994329576; // π÷180
51-
constexpr double divpi_360_d = .00872664625997164788; // π÷360
52-
constexpr double sqrtpi_d = 1.7724538509055160273; // √π sqrtpi
53-
constexpr double sqrt2_d = 1.4142135623730950488; // √2 M_SQRT2 sqrt2
54-
constexpr double sqrt3_d = 1.7320508075688772935; // √3 sqrt3
55-
constexpr double inv_sqrtpi_d = 1.7724538509055160273; // 1÷√π inv_sqrtpi
56-
constexpr double inv_sqrt2_d = .70710678118654752440; // 1÷√2 M_SQRT1_2 inv_sqrt2
57-
constexpr double div2_sqrtpi_d = 1.1283791670955125739; // 2÷√π M_2_SQRTPI
58-
constexpr double inv_sqrt3_d = .57735026918962576451; // 1÷√3 inv_sqrt3
34+
// Type Name Value Operation GNU std::numbers
35+
constexpr double phi_d = 1.6180339887498948482; // φ phi
36+
constexpr double egamma_d = 1.5674682557740530749; // Γe egamma
37+
constexpr double ln2_d = .69314718055994530942; // ln(2) M_LN2 ln2
38+
constexpr double ln10_d = 2.302585092994045684; // ln(10) M_LN10 ln10
39+
constexpr double log2e_d = 1.4426950408889634074; // log2(e) M_LOG2E log2e
40+
constexpr double log10e_d = .43429448190325182765; // log10(e) M_LOG10E log10e
41+
constexpr double pi_d = 3.1415926535897932385; // π M_PI pi
42+
constexpr double mul2_pi_d = 6.2831853071795864769; //
43+
constexpr double inv_pi_d = .31830988618379067154; // 1÷π M_1_PI inv_pi
44+
constexpr double inv_mul2_pi_d = .15915494309189533577; // 1÷2π
45+
constexpr double div2_pi_d = .63661977236758134308; // 2÷π M_2_PI
46+
constexpr double div180_pi_d = 57.295779513082320877; // 180÷π
47+
constexpr double divpi_2_d = 1.5707963267948966192; // π÷2 M_PI_2
48+
constexpr double divpi_4_d = .78539816339744830962; // π÷4 M_PI_4
49+
constexpr double divpi_90_d = .034906585039886591538; // π÷90
50+
constexpr double divpi_180_d = .017453292519943295769; // π÷180
51+
constexpr double divpi_360_d = .0087266462599716478846; // π÷360
52+
constexpr double sqrtpi_d = 1.7724538509055160273; // √π sqrtpi
53+
constexpr double sqrt2_d = 1.4142135623730950488; // √2 M_SQRT2 sqrt2
54+
constexpr double sqrt3_d = 1.7320508075688772935; // √3 sqrt3
55+
constexpr double inv_sqrtpi_d = 1.7724538509055160273; // 1÷√π inv_sqrtpi
56+
constexpr double inv_sqrt2_d = .7071067811865475244; // 1÷√2 M_SQRT1_2 inv_sqrt2
57+
constexpr double div2_sqrtpi_d = 1.1283791670955125739; // 2÷√π M_2_SQRTPI
58+
constexpr double inv_sqrt3_d = .57735026918962576451; // 1÷√3 inv_sqrt3
5959
}
6060

6161
#endif // COMMON_CONSTANT_H_

tools/math-constant/math-constant.py

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -263,8 +263,10 @@ class _long_double:
263263
# types.append(_long_double)
264264

265265
keyword = "constexpr"
266+
value = "0"
266267

267268
keyword_pad = len(keyword)
269+
value_pad = len(value)
268270

269271
type_head = "Type"
270272
name_head = "Name"
@@ -301,8 +303,6 @@ def output(string=""):
301303
mp.dps = t.precision
302304

303305
type_pad = len(t.name)
304-
value_pad = len(str(_pi.compute()))
305-
suffix_pad = len(t.suffix)
306306

307307
for c in constants:
308308
name = c.name + t.slug
@@ -328,10 +328,18 @@ def output(string=""):
328328
else:
329329
std = ""
330330

331-
sizes = keyword_pad, type_pad, name_pad, value_pad, suffix_pad, operation_pad, gnu_pad
332-
string = "\t{:<%s} {:<%s} {:<%s} {} {:<%s}{:<%s}{} {} {:<%s} {:<%s} {}" % sizes
331+
value = str(c.compute()) + t.suffix
332+
if value.startswith("0."):
333+
value = value[1:]
333334

334-
fields = "//", type_head, name_head, " ", value_head, "", " ", " ", operation_head, gnu_head, std
335+
l = len(value)
336+
if l > value_pad:
337+
value_pad = l
338+
339+
sizes = keyword_pad, type_pad, name_pad, value_pad, operation_pad, gnu_pad
340+
string = "\t{:<%s} {:<%s} {:<%s} {} {:>%s}{} {} {:<%s} {:<%s} {}" % sizes
341+
342+
fields = "//", type_head, name_head, " ", value_head, " ", " ", operation_head, gnu_head, std
335343
output(string.format(*fields).rstrip())
336344

337345
for c in constants:
@@ -348,16 +356,11 @@ def output(string=""):
348356
else:
349357
std = ""
350358

351-
v = str(c.compute())
352-
if v.startswith("0."):
353-
v = v[1:]
354-
355-
v = v[:t.precision + 1]
356-
357-
if "." in v:
358-
v = v.ljust(t.precision + 1, "0")
359+
value = str(c.compute()) + t.suffix
360+
if value.startswith("0."):
361+
value = value[1:]
359362

360-
fields = keyword, t.name, name, "=", v, t.suffix, ";", "//", c.operation, gnu, std
363+
fields = keyword, t.name, name, "=", value, ";", "//", c.operation, gnu, std
361364
output(string.format(*fields).rstrip())
362365

363366
output("}")

0 commit comments

Comments
 (0)