first functional code
authorLaurent Mazet <mazet@softndesign.org>
Tue, 7 Oct 2025 21:57:54 +0000 (23:57 +0200)
committerLaurent Mazet <mazet@softndesign.org>
Tue, 7 Oct 2025 21:57:54 +0000 (23:57 +0200)
load.c

diff --git a/load.c b/load.c
index f2a2d0fe163fdfe752f78cceb76c354f3a5264eb..3726d33e4240b07f9c5f92b80c3073d44078adad 100644 (file)
--- a/load.c
+++ b/load.c
@@ -3,19 +3,14 @@
 /* linker: */
 
 #include <assert.h>
+//#include <math.h>
 #include <stdio.h>
 #include <stdlib.h>
 
 /* constants */
 
-#define MAXSIZE 16;
-
-/* types */
-
-typedef struct {
-    int n;
-    double *mat;
-} matrix_t;
+//#define N 32
+#define N 10
 
 /* static variables */
 
@@ -24,6 +19,13 @@ char *version = "0.1";
 
 int nb_threads = 1;
 
+/* types */
+
+typedef struct {
+    int n;
+    double *mat;
+} matrix_t;
+
 /* usage function */
 
 int usage (int ret)
@@ -108,10 +110,22 @@ double determinant (matrix_t *matrix)
         get_matrix (matrix, 0, l, &val);
         det += sign * val * determinant (comatrix);
     }
+    free_matrix (comatrix);
 
     return det;
 }
 
+void generate_matrix (matrix_t *matrix)
+{
+    double base = 10 * drand48 () - 5;
+    for (int i = 0; i < matrix->n; i++) {
+        for (int j = 0; j < matrix->n; j++) {
+            double val = base * (rand () - RAND_MAX / 2) / (double)RAND_MAX;
+            set_matrix (matrix, i, j, val);
+        }
+    }
+}
+
 /* main function */
 
 int main (int argc, char *argv[])
@@ -155,6 +169,12 @@ int main (int argc, char *argv[])
     }
 
     /* main process */
+    while (1) {
+        matrix_t *matrix = alloc_matrix (N);
+        generate_matrix (matrix);
+        double det = determinant (matrix);
+        printf ("det: %g\n", det);
+    }
 
     return 0;
 }