Skip to content

Commit

Permalink
Merge pull request OpenMathLib#4235 from angsch/develop
Browse files Browse the repository at this point in the history
Fix division by zero in [z]rotg
  • Loading branch information
martin-frbg authored Oct 9, 2023
2 parents 617294b + db3a43c commit 4a0f863
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 12 deletions.
9 changes: 2 additions & 7 deletions interface/rotg.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,8 @@ void CNAME(FLOAT *DA, FLOAT *DB, FLOAT *C, FLOAT *S){
c = da / r;
s = db / r;
z = ONE;
if (da != ZERO) {
if (ada > adb){
z = s;
} else {
z = ONE / c;
}
}
if (ada > adb) z = s;
if ((ada <= adb) && (c != ZERO)) z = ONE / c;

*C = c;
*S = s;
Expand Down
10 changes: 5 additions & 5 deletions interface/zrotg.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,16 @@ void CNAME(void *VDA, void *VDB, FLOAT *C, void *VS) {
*(S1 + 0) = *(DB + 0);
*(S1 + 1) = *(DB + 1) *-1;
if (da_r == ZERO && da_i == ZERO) {
*C = ZERO;
*C = ZERO;
if (db_r == ZERO) {
(*DA) = fabsl(db_i);
*S = *S1 /da_r;
*(S+1) = *(S1+1) /da_r;
*S = *S1 /(*DA);
*(S+1) = *(S1+1) /(*DA);
return;
} else if ( db_i == ZERO) {
*DA = fabsl(db_r);
*S = *S1 /da_r;
*(S+1) = *(S1+1) /da_r;
*S = *S1 /(*DA);
*(S+1) = *(S1+1) /(*DA);
return;
} else {
long double g1 = MAX( fabsl(db_r), fabsl(db_i));
Expand Down

0 comments on commit 4a0f863

Please sign in to comment.