Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Floating point accuracy in VBA 1

Status
Not open for further replies.

phudgens

Technical User
Jul 8, 2004
117
US
I am getting slightly different results from code used by C++ to do Eigen vector calculations compared to what the same code in VBA gives me using the same input data. I am wondering if my conversion of the hypot and atan2 methods (available in C++, Matlab, Perl, etc) are not capturing the same floating point accuracy as is standard in C++. For hypot I am using: Sqr((A1 * A1) + (A2 * A2)). And for atan2 I am using: Application.WorksheetFunction.Atan2(HypotA1A2, A3)). Does anyone have experience with using advanced methods like these in Excel VBA, in particular as they relate to floating point accuracy?
 
Hi,

Lots of hypothetical info, but nothing specific.

Are you refereing to accuracy or precision?

Can you give some specific examples?

Please answer BOTH questions clearly, concisely and completely.

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
How much difference are you getting? There shouldn't be any difference up to the 14th significant figure.

Was "Application.WorksheetFunction.Atan2(HypotA1A2, A3) a typo? It should be Atan2(adjacent, opposite)

If you are using multiple copies of this function you will find a significant performance hit from using the Worksheetfunction call.

You can download a worksheet file with VBA trig functions (including ATan2) from:

Or VBA functions calling a Fortran Dll from:



Doug Jenkins
 
DougAJ4,

Your mention of the ATan2 function prompted me to do a web search and I found some good information on Wikipedia. It turns out that some computer programs reverse the order of the parameters. Reversing the paramenters in my VBA code solved the problem - we are now getting exact answers.

Thanks very much,
Paul Hudgens
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top