Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
function "_ARCSEC()" is wrong?
#13
It goes to show how much people use these extended functions in QB64 -- they're completely backwards!

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.)
Reply


Messages In This Thread
function "_ARCSEC()" is wrong? - by BSpinoza - 10-28-2023, 05:44 AM
RE: function "_ARCSEC()" is wrong? - by bplus - 10-28-2023, 01:40 PM
RE: function "_ARCSEC()" is wrong? - by SMcNeill - 10-28-2023, 01:53 PM
RE: function "_ARCSEC()" is wrong? - by bplus - 10-28-2023, 02:42 PM
RE: function "_ARCSEC()" is wrong? - by bplus - 10-28-2023, 02:56 PM
RE: function "_ARCSEC()" is wrong? - by bplus - 10-28-2023, 04:42 PM
RE: function "_ARCSEC()" is wrong? - by BSpinoza - 10-29-2023, 06:04 AM
RE: function "_ARCSEC()" is wrong? - by BSpinoza - 10-30-2023, 09:22 AM
RE: function "_ARCSEC()" is wrong? - by SMcNeill - 10-30-2023, 10:24 AM
RE: function "_ARCSEC()" is wrong? - by SMcNeill - 10-30-2023, 02:42 PM
RE: function "_ARCSEC()" is wrong? - by SMcNeill - 10-31-2023, 04:23 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Function Pointers? BlameTroi 5 268 02-20-2026, 05:55 PM
Last Post: BlameTroi
  TYPE and CONST within SUB/FUNCTION TerryRitchie 9 1,998 07-11-2023, 01:22 AM
Last Post: bplus
  Query to function _InputBox$ Petr 10 2,097 03-31-2023, 09:53 PM
Last Post: mnrvovrfc
  instr function in reverse ??? doppler 3 786 02-10-2023, 02:33 PM
Last Post: doppler
  Variable as a reference or value to a function Kernelpanic 22 4,377 08-08-2022, 07:41 PM
Last Post: bplus

Forum Jump:


Users browsing this thread: 1 Guest(s)