Re: An interesting Problem

Jeremy Fitzhardinge (jeremy@nospam.sour.sw.oz.au)
Fri, 10 Feb 1995 18:27:16 +1100 (EST)

> I have a problem. My computer (or more accuratly, Sydney Uni's computer)
> can't do maths (and before you ask, it's *not* a pentium, it's a Sparc1000
> running Solarius). I have a rather complex piece of C++ code with the
> following line in it:
>
> double angletheta = acos(LookAxis.dot(LookDirection));
>
> This line didn't seem to be working, and after quite an amount of mucking
> around I suspected it *might* be the acos function. I added this:
>
> double tmp = acos(0.0);
> assert(tmp!=0.0);
>
> Now it always fails the assertion. I check it in a debugger, and it does
> set tmp to zero. I check what the result shoud be (~1.5) on a calculator.

Make sure you've got a prototype for acos() in scope (ie, you're including
math.h). That's all I can think of for the moment. Does compiling with -Wall
tell you anything?

: suede:8; cat x.c
#include <stdio.h>

int main(int argc, char *argv[])
{
double x = acos(0.0);

printf("acos(0.0) = %f\n", x);

exit(1);
}
: suede:8; gcc -Wall -o x x.c -lm
x.c: In function `main':
x.c:5: warning: implicit declaration of function `acos'
: suede:8; ./x
acos(0.0) = 0.000000
: suede:8; cat x1.c
#include <stdio.h>
#include <math.h>

int main(int argc, char *argv[])
{
double x = acos(0.0);

printf("acos(0.0) = %f\n", x);

exit(1);
}
: suede:8; gcc -Wall -o x x1.c -lm
: suede:8; ./x
acos(0.0) = 1.570796

J