- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I have been playing around with the atan2 function in the Visual and Intel compilers and I run into this problem:
write(*,*) cos(atan2(1d0,0d0))
gives: 6.123031769111886E-017 when it should be 0d0
but
write(*,*) cosd(atan2d(1d0,0d0))
gives: 0d0
For some reason I always thought that atan2 was more accurate than atan2d but in any case I think that there is an issue with the implementation of the atan2 function.
I have tried the same in C with the math.h library and I get the correct answer, however in some implementations of Matlab I have seen the same problem.
Although you might think that 1d-17 is small, I'm multiplying it by huge numbers so I running into problems.
Is there any setting in the compiler that can solve this problem?
Thanks!!!
Juan
I have been playing around with the atan2 function in the Visual and Intel compilers and I run into this problem:
write(*,*) cos(atan2(1d0,0d0))
gives: 6.123031769111886E-017 when it should be 0d0
but
write(*,*) cosd(atan2d(1d0,0d0))
gives: 0d0
For some reason I always thought that atan2 was more accurate than atan2d but in any case I think that there is an issue with the implementation of the atan2 function.
I have tried the same in C with the math.h library and I get the correct answer, however in some implementations of Matlab I have seen the same problem.
Although you might think that 1d-17 is small, I'm multiplying it by huge numbers so I running into problems.
Is there any setting in the compiler that can solve this problem?
Thanks!!!
Juan
Link Copied
1 Reply
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
If you got your "correct" answer with a C compiler, you most likely were using a compilation mode which invoked the built-in x87 functions with extra precision. CVF included a system call which would set x87 precision mode to 64 bits, in case that is what you want. I haven't tried it with ifort, to check whether it is still implemented, should you desire to forgo SSE2 optimizations. Microsoft has specified the default 53-bit precision mode for years.
Otherwise, you would have to give more specifics. C math.h does not specify a library; it only supplies the definitions, equivalent to those built in to Fortran.
An algorithm which intentionally magnifies uncertainties of the order of EPSILON(x) has to be questionable, at least without a lot of justification.
Otherwise, you would have to give more specifics. C math.h does not specify a library; it only supplies the definitions, equivalent to those built in to Fortran.
An algorithm which intentionally magnifies uncertainties of the order of EPSILON(x) has to be questionable, at least without a lot of justification.

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page