10-30-2023, 10:24 AM
It goes to show how much people use these extended functions in QB64 -- they're completely backwards!
If you look in libqb.cpp, you'll find the code above. Take a moment to look at it and you'll see that the logic here is completely reversed! We're tossing errors in the range where we should give valid results, and we're giving valid results in the range where we should be tossing errors!
Fix is rather simple though -- just go into libqb.cpp and down around line 33925, change the above to the following:
Save and you should be good to go. (If not, then in the QB64PE menu, click DEBUG and then PURGE C++ LIBRARIES. That should rebuild the c-side of things and correct the issue after you've saved the changes above.)
Code: (Select All)
double func_arcsec(double num) {
int sign = (num > 0) - (num < 0);
if (num < -1 || num > 1) {
error(5);
return 0;
}
return std::atan(num / std::sqrt(1 - num * num)) + (sign - 1) * (2 * std::atan(1));
}
double func_arccsc(double num) {
int sign = (num > 0) - (num < 0);
if (num < -1 || num > 1) {
error(5);
return 0;
}
return std::atan(num / std::sqrt(1 - num * num)) + (sign - 1) * (2 * std::atan(1));
}
If you look in libqb.cpp, you'll find the code above. Take a moment to look at it and you'll see that the logic here is completely reversed! We're tossing errors in the range where we should give valid results, and we're giving valid results in the range where we should be tossing errors!
Fix is rather simple though -- just go into libqb.cpp and down around line 33925, change the above to the following:
Code: (Select All)
double func_arcsec(double num) {
int sign = (num > 0) - (num < 0);
if (std::abs(num) < 1) {
error(5);
return 0;
}
return std::atan(num / std::sqrt(1 - num * num)) + (sign - 1) * (2 * std::atan(1));
}
double func_arccsc(double num) {
int sign = (num > 0) - (num < 0);
if (std::abs(num) < 1) {
error(5);
return 0;
}
return std::atan(num / std::sqrt(1 - num * num)) + (sign - 1) * (2 * std::atan(1));
}
Save and you should be good to go. (If not, then in the QB64PE menu, click DEBUG and then PURGE C++ LIBRARIES. That should rebuild the c-side of things and correct the issue after you've saved the changes above.)