View Single Post
Old 25 July 2018, 15:31   #1
deimos
Registered User

 
Join Date: Jul 2018
Location: Londonish / UK
Posts: 134
VBCC - What's going on here?

I'm having a weird problem. The code below shows it. Sometimes cos(M_PI / 2) is giving 0.0 instead of 1.0. Or, more specifically, the assignment of the function call's result seems to be wrong, as if I call the function by itself it's fine.

I'm either doing something really silly, or I've broken my system somehow, or I've hit a compiler bug.

Can anybody help?

Code:
#include <math.h>
#include <stdio.h>

int main(int argc, char const *argv[]) {
    double a = M_PI / 2;
    double x = cos(a);
    double y = sin(a);
    printf("%f: %f, %f\n", a, x, y);
    printf("%f\n", cos(M_PI / 2));
    printf("%f\n", sin(M_PI / 2));
    return 0;
}
When I run this on an (emulated) Amiga I get:

1.570796: 0.000000, 0.000000
0.000000
1.000000

When I run it on a Linux machine I get the correct result:

1.570796: 0.000000, 1.000000
0.000000
1.000000

Last edited by deimos; 25 July 2018 at 16:06.
deimos is offline  
 
Page generated in 0.07077 seconds with 11 queries