[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Tinycc-devel] libtcc bug when evaluating math expressions
From: |
David Wallin |
Subject: |
[Tinycc-devel] libtcc bug when evaluating math expressions |
Date: |
Thu, 27 Nov 2003 13:28:45 +0000 |
Hi
I suspect there is a bug somewhere regarding math evaluations in
libtcc.
Evaluating the following : ((-1.0 * x) > v * fabs(v))
when x &v are declared as:
double int x = -0.65;
double int v = 0.4;
gives different answers if evaluated by gcc or if I dynamically
compile it using libtcc.
ans1 = 0.000000 (libtcc)
ans2 = 1.000000 (gcc)
The following program shows this, and it has been tried with both
0.9.19 and 0.9.20:
8<---------------------------------------BEGIN
#include <libtcc.h>
#include <math.h>
//#define TCC19
#define TCC20
int main() {
char *eval_me = "double evaluate_me(double x, double v) { return
(double) ((-1.0 * x) > v * fabs(v)); }\0" ;
double x = -0.65 ;
double v = 0.4 ;
double ans1, ans2, ans3;
#ifdef TCC20
double (*evaluate_me)(double, double);
unsigned long val;
#endif
TCCState *tcc_state;
tcc_state = tcc_new();
tcc_set_output_type(tcc_state, TCC_OUTPUT_MEMORY);
tcc_add_library(tcc_state, "m");
tcc_compile_string(tcc_state, eval_me);
tcc_relocate(tcc_state);
#ifdef TCC19
double (*evaluate_me)(double, double) = (double (*)(double,
double))tcc_get_symbol(tcc_state, "evaluate_me");
#endif
#ifdef TCC20
tcc_get_symbol(tcc_state, &val, "evaluate_me");
evaluate_me = (void *)val;
#endif
ans1 = evaluate_me(x,v) ;
ans2 = ((-1.0 * x) > v * fabs(v)) ;
if(ans1 != ans2) {
printf("x=%f; v=%f\n", x, v);
printf("ans1 = %f\n", ans1);
printf("ans2 = %f\n", ans2);
}
return 0;
}
8<-----------------------------------------------------END
cheers,
--david
- [Tinycc-devel] libtcc bug when evaluating math expressions,
David Wallin <=