ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Trig Problems (https://www.excelbanter.com/excel-programming/390029-trig-problems.html)

Jack Clift[_3_]

Trig Problems
 
Am having problems with the use of trig functions within in VBA.

sin(worksheetfunction.pi/2) = 1 //this is ok
cos(worksheetfunction.pi/2) = 6.12303176911189E-17 //this is causing me a
real headache... it should and needs to equal 0.

For reasons I wont go into I cannot fudge with the round() function.

I have tried using decimal type to define PI, but have not succeeded (not
sure that I am coding correctly, but VB 'truncates' anything over 15 sig.
figures in the programming environment, so I can't increase accuracy by
simple const definition.

any ideas?

Tom Ogilvy

Trig Problems
 
Looks like you might have to roll your own functions and operators if you
need more than 15 significant digits (including generating pi since it is
rounded to 15 digits).

?application.Pi
3.14159265358979

or look here
http://www.google.com/search?hl=en&q...oo gle+Search

--
Regards,
Tom Ogilvy



"Jack Clift" wrote in message
...
Am having problems with the use of trig functions within in VBA.

sin(worksheetfunction.pi/2) = 1 //this is ok
cos(worksheetfunction.pi/2) = 6.12303176911189E-17 //this is causing me a
real headache... it should and needs to equal 0.

For reasons I wont go into I cannot fudge with the round() function.

I have tried using decimal type to define PI, but have not succeeded (not
sure that I am coding correctly, but VB 'truncates' anything over 15 sig.
figures in the programming environment, so I can't increase accuracy by
simple const definition.

any ideas?




Rick Rothstein \(MVP - VB\)

Trig Problems
 
Am having problems with the use of trig functions within in VBA.

sin(worksheetfunction.pi/2) = 1 //this is ok
cos(worksheetfunction.pi/2) = 6.12303176911189E-17 //this is causing me a
real headache... it should and needs to equal 0.

For reasons I wont go into I cannot fudge with the round() function.

I have tried using decimal type to define PI, but have not succeeded (not
sure that I am coding correctly, but VB 'truncates' anything over 15 sig.
figures in the programming environment, so I can't increase accuracy by
simple const definition.


I don't think there is anything you can do about this (except to use some
kind of rounding operation)... these slight and minor discrepencies with
floating point numbers is a well-known problem... it is inherent in the
system used to store them. If this is new ground for you, perhaps these
links will help...

INFO: Visual Basic and Arithmetic Precision
http://support.microsoft.com/default...NoWebContent=1

(Complete) Tutorial to Understand IEEE Floating-Point Errors
http://support.microsoft.com/default...NoWebContent=1

Just out of curiosity, why are you opposed to using the Round function with,
say, 15 for the number of decimal places?

Rick


Jack Clift[_3_]

Trig Problems
 
Thanks both for replying to this thread - have fixed the problem in a
'better' way - I did a quick search on the web and issues with FP maths is
more fundamental than I previously understood; rounding to 15dp IS a viable
solution.

Thanks again.

"Rick Rothstein (MVP - VB)" wrote:

Am having problems with the use of trig functions within in VBA.

sin(worksheetfunction.pi/2) = 1 //this is ok
cos(worksheetfunction.pi/2) = 6.12303176911189E-17 //this is causing me a
real headache... it should and needs to equal 0.

For reasons I wont go into I cannot fudge with the round() function.

I have tried using decimal type to define PI, but have not succeeded (not
sure that I am coding correctly, but VB 'truncates' anything over 15 sig.
figures in the programming environment, so I can't increase accuracy by
simple const definition.


I don't think there is anything you can do about this (except to use some
kind of rounding operation)... these slight and minor discrepencies with
floating point numbers is a well-known problem... it is inherent in the
system used to store them. If this is new ground for you, perhaps these
links will help...

INFO: Visual Basic and Arithmetic Precision
http://support.microsoft.com/default...NoWebContent=1

(Complete) Tutorial to Understand IEEE Floating-Point Errors
http://support.microsoft.com/default...NoWebContent=1

Just out of curiosity, why are you opposed to using the Round function with,
say, 15 for the number of decimal places?

Rick




All times are GMT +1. The time now is 05:10 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com