@@ -480,6 +480,12 @@ MagickExport MagickBooleanType GaussJordanElimination(double **matrix,
480
480
double * * vectors ,const size_t rank ,const size_t number_vectors )
481
481
{
482
482
#define GaussJordanSwap (x ,y ) \
483
+ { \
484
+ double temp = (x); \
485
+ (x)=(y); \
486
+ (y)=temp; \
487
+ }
488
+ #define GaussJordanSwapLD (x ,y ) \
483
489
{ \
484
490
long double temp = (x); \
485
491
(x)=(y); \
@@ -559,21 +565,19 @@ MagickExport MagickBooleanType GaussJordanElimination(double **matrix,
559
565
row = j ;
560
566
column = k ;
561
567
}
562
- if ((column == -1 ) || (row == -1 ) ||
563
- ((fabsl (max ) > 0.0L ) && (fabsl (max ) <= LDBL_MIN )))
568
+ if ((column == -1 ) || (row == -1 ) || (fabsl (max ) < LDBL_MIN ))
564
569
ThrowGaussJordanException (); /* Singular or nearly singular matrix */
565
570
pivots [column ]++ ;
566
571
if (row != column )
567
572
{
568
573
for (k = 0 ; k < (ssize_t ) rank ; k ++ )
569
- GaussJordanSwap (hp_matrix [row ][k ],hp_matrix [column ][k ]);
574
+ GaussJordanSwapLD (hp_matrix [row ][k ],hp_matrix [column ][k ]);
570
575
for (k = 0 ; k < (ssize_t ) number_vectors ; k ++ )
571
576
GaussJordanSwap (vectors [k ][row ],vectors [k ][column ]);
572
577
}
573
578
rows [i ]= row ;
574
579
columns [i ]= column ;
575
- if ((fabsl (hp_matrix [column ][column ]) > 0.0L ) &&
576
- (fabsl (hp_matrix [column ][column ]) <= LDBL_MIN ))
580
+ if (fabsl (hp_matrix [column ][column ]) < LDBL_MIN )
577
581
ThrowGaussJordanException (); /* Singular matrix */
578
582
scale = 1.0L /hp_matrix [column ][column ];
579
583
hp_matrix [column ][column ]= 1.0 ;
@@ -595,7 +599,7 @@ MagickExport MagickBooleanType GaussJordanElimination(double **matrix,
595
599
for (j = (ssize_t ) rank - 1 ; j >= 0 ; j -- )
596
600
if (columns [j ] != rows [j ])
597
601
for (i = 0 ; i < (ssize_t ) rank ; i ++ )
598
- GaussJordanSwap (hp_matrix [i ][columns [j ]],hp_matrix [i ][rows [j ]]);
602
+ GaussJordanSwapLD (hp_matrix [i ][columns [j ]],hp_matrix [i ][rows [j ]]);
599
603
/*
600
604
Copy back the result to the original matrix.
601
605
*/
0 commit comments