Hello,
Thank you very much for your e-mail.
Normally C++ compiled code should return deterministic values (same output for same input).
As you can see AmiBroker shows deterministic/stable behavior in both single and double arithmetic.
I don't know what you are doing in your DLL so it is not stable, but here are few things to look for:
a) did you turn on aggressive optimizations in the compiler (sometimes compilers produce wrong code @ certain optimization levels)?
b) do you use settings to enable SSE2/64-bit code generation (they are known to be slightly less precise than old x87 code)
c) do you change default FPU rounding mode (don't do that)
d) does your code produce denormals?
Best regards,
Tomasz Janeczko
amibroker.com
've tracked down an interesting discrepancy between an AFL formula inputted division from AFL and that same formula inputted division in a C++ plugin function.
The AFL formula receiving the input in both cases is essentially computing the length of a line,
length = sqrt((x1 - x2)^2 + (y1 - y2)^2))
The input into this formula is the result of a division, eg., num/denom.
Here's the interesting part. The output of this formula is slightly different depending on whether this division is done by a C++ plugin using the C++ / operator versus whether it is done using the AmiBroker / operator. I've traced out the inputs to the function in both cases and they are the same to at least 5 decimal places. Also, the results if I use AFL all the way through are the same everytime I run it, while the results if I do C++ can be slightly different from run to run (even though the inputs print out as the same every run).
I'm pretty sure at this point I'm seeing a floating point error. I'm not sure what kind though. With floating point error, I'd expect the same output error every time. I've found the following paper online and know I can rewrite the formula to make it less sensitive to floating point differences:
What Every Computer Scientist Should Know About Floating-Point Arithmetic
My question is whether I can be doing something more silver bullet-like to avoid these kinds of problems? For example, should I be using double precision in C++ for the arithmetic and then convert to float before passing results back to AmiBroker? Is AmiBroker doing something special which allows it to produce stable results when I use AFL's / operator while I get slightly different results if I produce the input using the C++ / operator? If so, can I mirror AB's arithmetic strategy in my plugin to avoid any problems?
Posted by: Tomasz Janeczko <groups@amibroker.com>
Reply via web post | • | Reply to sender | • | Reply to group | • | Start a New Topic | • | Messages in this topic (2) |
This group is for the discussion between users only.
This is *NOT* technical support channel.
TO GET TECHNICAL SUPPORT send an e-mail directly to
SUPPORT {at} amibroker.com
TO SUBMIT SUGGESTIONS please use FEEDBACK CENTER at
http://www.amibroker.com/feedback/
(submissions sent via other channels won't be considered)
For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/
EmoticonEmoticon