Code: Select all
EnableExplicit
Macro IIFn(_Expression_, _TruePart_, _FalsePart_)
; Bool(Not _Expression_) * _FalsePart_ + Bool(_Expression_) * _TruePart_
Bool(_Expression_) * _TruePart_ + Bool(Not _Expression_) * _FalsePart_
EndMacro
Debug IIFn(1=0, 11.1, 10) ; should be 10, gives 0.0!
Define res.d
res = IIFn(1=0, 11.1, 10) ; should be 10, gives 0.0!
Debug res
Define.d a=11.1, b=10
res = IIFn(a=b, a, b) ; should be 10, gives 0.0!
Debug res
The result is different!
here is the C-Output.
You can see that the Compiler precalculate the result and set it to 0.0 - that's wrong.
The last (a=b, a, b) with variables is processed correct.
So the bug is in the precalculation of the expression in the compiler!
Code: Select all
SYS_InitPureBasic();
// EnableExplicit
//
// Macro IIFn(_Expression_, _TruePart_, _FalsePart_)
// Bool(Not _Expression_) * _FalsePart_ + Bool(_Expression_) * _TruePart_
//
// EndMacro
//
// Debug IIFn(1=0, 11.1, 10)
//
// Define res.d;
//
// res = IIFn(1=0, 11.1, 10)
v_res=0.0; ; here the compiler sets a 0.0 what is impossible!
// Debug res
//
// Define.d a=11.1, b=10
v_a=11.0999999999999996447286321199499070644378662109375;
v_b=10.0;
//
// res = IIFn(a=b, a, b)
int r0=((!((v_a==v_b)))?1:0);
int r1=(((v_a==v_b))?1:0);
v_res=((double)((double)r0*v_b)+((double)r1*v_a));
// Debug res
//
SYS_Quit();
}