all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
blob 3d1ed4243c048eff4e586820ec49eab2f07f91a1 2825 bytes (raw)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
 
From 9cc12d0377dd634b1b97954d076b715f982853b7 Mon Sep 17 00:00:00 2001
From: Patrick Alken <alken@colorado.edu>
Date: Fri, 4 Apr 2014 13:36:16 -0600
Subject: [PATCH] bug fix in sorting of complex numbers (bug #39055)

---
 poly/test.c | 49 ++++++++++++++++++++++++++++++-------------------
 1 file changed, 30 insertions(+), 19 deletions(-)

diff --git a/poly/test.c b/poly/test.c
index 9c147f6..d090802 100644
--- a/poly/test.c
+++ b/poly/test.c
@@ -25,11 +25,21 @@
 #include <gsl/gsl_poly.h>
 #include <gsl/gsl_heapsort.h>
 
+/* sort by Re(z) then by Im(z) */
 static int
 cmp_cplx(const double *a, const double *b)
 {
-	double t = (a[0] * a[0] + a[1] * a[1]) - (b[0] * b[0] + b[1] * b[1]);
-	return t < 0.0 ? -1 : t > 0.0 ? 1 : 0;
+  double r = a[0] - b[0];
+
+  if (r == 0.0)
+    {
+      double t = a[1] - b[1];
+	    return t < 0.0 ? -1 : t > 0.0 ? 1 : 0;
+    }
+  else if (r < 0.0)
+    return -1;
+  else
+    return 1;
 }
 
 int
@@ -534,25 +544,26 @@ main (void)
        Problem reported by Munagala Ramanath (bug #39055)
     */
 
-    double a[16] = { 32, -48, -8, 28, -8, 16, -16, 12, -16, 6, 10, -17, 10, 2, -4, 1 };
+    double a[16] = { 32, -48, -8, 28, -8, 16, -16, 12,
+                    -16, 6, 10, -17, 10, 2, -4, 1 };
     double z[16*2];
 
-    double expected[16*20] = {
-	   1.0000000000000000,  0.00000000000000000,
-	   1.0000000000000000,  0.00000000000000000,
-	  -1.0000000000000000,  0.00000000000000000,
-	 -0.65893856175240950,  0.83459757287426684,
-	 -0.65893856175240950, -0.83459757287426684,
-	-0.070891117403341281,  -1.1359249087587791,
-	-0.070891117403341281,   1.1359249087587791,
-	   1.1142366961812986, -0.48083981203389980,
-	   1.1142366961812986,  0.48083981203389980,
-	  -1.3066982484920768,  0.00000000000000000,
-	  0.57284747839410854,   1.1987808988289705,
-	  0.57284747839410854,  -1.1987808988289705,
-	  -1.6078107423472359,  0.00000000000000000,
-	   2.0000000000000000,  0.00000000000000000,
-	   2.0000000000000000,  0.00000000000000000 };
+    double expected[16*2] = {
+     -1.6078107423472359,    0.00000000000000000,
+     -1.3066982484920768,    0.00000000000000000,
+     -1.0000000000000000,    0.00000000000000000,
+     -0.65893856175240950,  -0.83459757287426684,
+     -0.65893856175240950,   0.83459757287426684,
+     -0.070891117403341281, -1.1359249087587791,
+     -0.070891117403341281,  1.1359249087587791,
+      0.57284747839410854,  -1.1987808988289705,
+      0.57284747839410854,   1.1987808988289705,
+      1.0000000000000000,    0.00000000000000000,
+      1.0000000000000000,    0.00000000000000000,
+      1.1142366961812986,   -0.48083981203389980,
+      1.1142366961812986,    0.48083981203389980,
+      2.0000000000000000,    0.00000000000000000,
+      2.0000000000000000,    0.00000000000000000 };
 
     int i;
 
-- 
2.4.3


debug log:

solving 3d1ed42 ...
found 3d1ed42 in https://git.savannah.gnu.org/cgit/guix.git

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/guix.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.