Skip to content

Commit 0649148

Browse files
committed
working
1 parent 41163f3 commit 0649148

File tree

2 files changed

+224
-93
lines changed

2 files changed

+224
-93
lines changed

check_constants.c

+91
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
#include <stdio.h>
2+
#include <stdint.h>
3+
#include <string.h> // For memcpy
4+
#include <math.h> // For M_PI if needed, though PI is defined below
5+
6+
// Function to print the bit representation of a double
7+
void print_double_bits(const char *name, double val) {
8+
uint64_t bits;
9+
// Use memcpy to safely copy the bits, avoiding potential strict-aliasing issues
10+
memcpy(&bits, &val, sizeof(double));
11+
printf("%s = %.17g (0x%016lx)\n", name, val, bits);
12+
}
13+
14+
int main() {
15+
// Constants from gamma.rs
16+
const double PI = 3.141592653589793238462643383279502884197;
17+
const double LOG_PI = 1.144729885849400174143427351353058711647;
18+
const double LANCZOS_G = 6.024680040776729583740234375;
19+
const double LANCZOS_G_MINUS_HALF = 5.524680040776729583740234375;
20+
21+
const int LANCZOS_N = 13;
22+
const double LANCZOS_NUM_COEFFS[LANCZOS_N] = {
23+
23531376880.410759688572007674451636754734846804940,
24+
42919803642.649098768957899047001988850926355848959,
25+
35711959237.355668049440185451547166705960488635843,
26+
17921034426.037209699919755754458931112671403265390,
27+
6039542586.3520280050642916443072979210699388420708,
28+
1439720407.3117216736632230727949123939715485786772,
29+
248874557.86205415651146038641322942321632125127801,
30+
31426415.585400194380614231628318205362874684987640,
31+
2876370.6289353724412254090516208496135991145378768,
32+
186056.26539522349504029498971604569928220784236328,
33+
8071.6720023658162106380029022722506138218516325024,
34+
210.82427775157934587250973392071336271166969580291,
35+
2.5066282746310002701649081771338373386264310793408,
36+
};
37+
const double LANCZOS_DEN_COEFFS[LANCZOS_N] = {
38+
0.0,
39+
39916800.0,
40+
120543840.0,
41+
150917976.0,
42+
105258076.0,
43+
45995730.0,
44+
13339535.0,
45+
2637558.0,
46+
357423.0,
47+
32670.0,
48+
1925.0,
49+
66.0,
50+
1.0,
51+
};
52+
53+
const int NGAMMA_INTEGRAL = 23;
54+
const double GAMMA_INTEGRAL[NGAMMA_INTEGRAL] = {
55+
1.0, 1.0, 2.0, 6.0, 24.0, 120.0, 720.0, 5040.0, 40320.0,
56+
362880.0, 3628800.0, 39916800.0, 479001600.0, 6227020800.0,
57+
87178291200.0, 1307674368000.0, 20922789888000.0,
58+
355687428096000.0, 6402373705728000.0, 121645100408832000.0,
59+
2432902008176640000.0, 51090942171709440000.0,
60+
1124000727777607680000.0,
61+
};
62+
63+
printf("--- Single Constants ---\n");
64+
print_double_bits("PI", PI); // Added PI for completeness
65+
print_double_bits("LOG_PI", LOG_PI);
66+
print_double_bits("LANCZOS_G", LANCZOS_G);
67+
print_double_bits("LANCZOS_G_MINUS_HALF", LANCZOS_G_MINUS_HALF);
68+
69+
printf("\n--- LANCZOS_NUM_COEFFS ---\n");
70+
for (int i = 0; i < LANCZOS_N; ++i) {
71+
char name[32];
72+
snprintf(name, sizeof(name), "LANCZOS_NUM_COEFFS[%d]", i);
73+
print_double_bits(name, LANCZOS_NUM_COEFFS[i]);
74+
}
75+
76+
printf("\n--- LANCZOS_DEN_COEFFS ---\n");
77+
for (int i = 0; i < LANCZOS_N; ++i) {
78+
char name[32];
79+
snprintf(name, sizeof(name), "LANCZOS_DEN_COEFFS[%d]", i);
80+
print_double_bits(name, LANCZOS_DEN_COEFFS[i]);
81+
}
82+
83+
printf("\n--- GAMMA_INTEGRAL ---\n");
84+
for (int i = 0; i < NGAMMA_INTEGRAL; ++i) {
85+
char name[32];
86+
snprintf(name, sizeof(name), "GAMMA_INTEGRAL[%d]", i);
87+
print_double_bits(name, GAMMA_INTEGRAL[i]);
88+
}
89+
90+
return 0;
91+
}

0 commit comments

Comments
 (0)