acos function & errno

qnx 6.2., x86, selfhosted

The help entry for acos says:
If an error occurs, these functions return 0, but this is also a valid
mathematical result. If you want to check for errors, set errno to 0, call
the function, and then check errno again. These functions don’t change
errno if no errors occurred.

A test program demonstrates that this is not happening:

#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <errno.h>

int main( void )
{
double a = 0;
errno = 0;
a = acos(1.5);
if (errno == 0) {
printf( “%f\n”, a );
}
else {
printf(“invalid\n”);
}

return EXIT_SUCCESS;
}

compiled via:
cc -g -p -lm test_acos.c -o test_acos

Output is some value (0.070737) and not the expected “invalid”

This behaviour is different in 6.3.0, so it looks like a bug
that was found & fixed for 6.3.0.
Apart from checking the argument to acos oneself, what
would be the work around for 6.2.1B?


Using Opera’s revolutionary e-mail client: http://www.opera.com/m2/

Hi Alex,

This behaviour is different in 6.3.0, so it looks like a bug
that was found & fixed for 6.3.0.
Apart from checking the argument to acos oneself, what
would be the work around for 6.2.1B?

I’ve tried your test sample on a couple of 6.2.1B boxes and a 6.2.0
machine here, and I see the same behaviour that I see in 6.3
(‘invalid’). I’m using the same command line that you’ve provided. Can
you post the output of your compile with a few -v’s thrown in? Have you
tried this on more than one 6.2.1 machine?


Cheers,
-Barry

On Mon, 08 Nov 2004 10:56:19 +0000, Barry <bbeldam@theusual.qnx.com> wrote:


I’ve tried your test sample on a couple of 6.2.1B boxes and a 6.2.0
machine here, and I see the same behaviour that I see in 6.3
(‘invalid’). I’m using the same command line that you’ve provided. Can
you post the output of your compile with a few -v’s thrown in? Have you
tried this on more than one 6.2.1 machine?

No I only tried it on the one here (vmware).

I’ve attached the output of cc, the .c file & executable.

uname -a:
QNX qnx621-VM 6.2.1 2003/01/18-02:12:22est x86pc x86


Using Opera’s revolutionary e-mail client: http://www.opera.com/m2/

Alex/Systems 104 wrote:

qnx 6.2., x86, selfhosted

The help entry for acos says:
If an error occurs, these functions return 0, but this is also a valid
mathematical result. If you want to check for errors, set errno to 0,
call the function, and then check errno again. These functions don’t
change errno if no errors occurred.

This may be related to the bug I previously reported, that
“NAN” is defined as 1 in QNX. “_Nan.Float” (see ymath.h)
seems to be 0. But " _FNan._Float" seems to be OK.

NAN is broken on 6.21NC and PE.

If any of the trig functions use NAN internally for
out of range values, this may be the cause of the acos problem.

John Nagle
Team Overbot.

On Mon, 08 Nov 2004 23:32:56 -0800, John Nagle <nagle@overbot.com> wrote:

Alex/Systems 104 wrote:
qnx 6.2., x86, selfhosted
The help entry for acos says:
If an error occurs, these functions return 0, but this is also a valid
mathematical result. If you want to check for errors, set errno to 0,
call the function, and then check errno again. These functions don’t
change errno if no errors occurred.

This may be related to the bug I previously reported, that
“NAN” is defined as 1 in QNX. “_Nan.Float” (see ymath.h)
seems to be 0. But " _FNan._Float" seems to be OK.

NAN is broken on 6.21NC and PE.

If any of the trig functions use NAN internally for
out of range values, this may be the cause of the acos problem.

I think you may be right.
If I print out the value of acos (1.5) in 6.2.1B,
you get a valid value. With 6.3, nan…

\

Using Opera’s revolutionary e-mail client: http://www.opera.com/m2/