I am working on a program which produces assembler code from expressions. One of the functions required is tan(x) which currently works using the following sequence of code (the addresses are filled in at run time):
fld [0x00C01288];
fld st(0);
fsin;
fld st(1);
fcos;
fdivp;
fst [0x0030FA8C];
However, I would like to use the FPTAN opcode instead, so I tried using the following code:
fld [0x00C01288];
fptan;
fincstp;
fst [0x0030FA8C];
The test program uses printf to show the result stored at 0x30FA8C, but for the second sequence the result is displayed as -1.#IND (the first using cos and sin works fine). If I try examining the value at the memory address, or on top of the floating point stack, in the debugger, it appears as the correct number.
So, my question is: Why is printf showing -1.#IND and how can I fix it?
The value at 0x00C01288 is double precision 0.5 The result in both cases is ~0.5463024898
My first thought was that the value being stored was a different representation of the same number, but inspecting the value stored at 0x0030FA8C shows it to be 0x3FE17B4F5BF3474A in both cases.
I do not understand why identical inputs to the printf function could produce different output...
Any help or suggestions would be greatly appreciated.
Edit: Source where printf is called:
#include "FridgeScript.h"
#include <stdio.h>
#include <math.h>
char test[] = "a=tan(0.5);";
int main(int c, char** s)
{
unsigned int SC = FSCreateContext();
double a = 0.0;
FSRegisterVariable(SC, "a", &a);
unsigned int CH = FSCompile(SC, test);
if(CH) FSExecute(SC, CH);
printf("a: %.10g\r\n", a);
printf("hex a: %I64X", a);
FSDestroyContext(SC);
return 0;
}