Last active
December 14, 2015 00:14
-
-
Save t-nissie/3f894e3292b617d75cb3 to your computer and use it in GitHub Desktop.
FFTの係数の準備をするときに、必ずしもsin(π/2)=1, cos(π/2)=0, sin(π/4)=cos(π/4)とかではないので、0<=θ<=π/4のsinθ, cosθを使うべき
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
! sincos.F | |
! You cannot say "sin(pi/2)=1, cos(pi/2)=0, sin(pi/4)=cos(pi/4)". | |
! Time-stamp: <2015-12-14 08:12:49 takeshi> | |
! Author: Takeshi NISHIMATSU | |
! Ref1: http://notabs.org/fpuaccuracy/index.htm | |
! Ref2: http://tomeapp.jp/archives/1282 | |
! Ref3: https://sourceware.org/ml/libc-alpha/2015-12/msg00205.html | |
! Ref4: https://twitter.com/takehiro_t/status/676006684259540992 | |
!! | |
#if defined(__PGI) || defined(__sparc) | |
# define command_argument_count iargc | |
# define get_command_argument getarg | |
#endif | |
program sincos | |
implicit none | |
integer i, N, command_argument_count | |
real*8 :: inv_N | |
complex*16 :: e(0:1023) | |
complex*16,parameter :: itwopi = (0.0d0,1.0d0)*6.28318530717958647693d0 | |
character(len=100) :: str | |
if (command_argument_count().eq.1) then | |
call get_command_argument(1,str) | |
read(str,*) N | |
else | |
N=32 | |
end if | |
inv_N = 1.0d0/N | |
do i=0,N/4 | |
e(i) = exp(itwopi*inv_N*i) | |
end do | |
do i=0,N/4 | |
write(6,'(i7,2f22.18)') i,e(i) | |
end do | |
end program sincos | |
! | |
! Results: | |
! 0 1.000000000000000000 0.000000000000000000 | |
! 1 0.980785280403230431 0.195090322016128248 | |
! 2 0.923879532511286738 0.382683432365089782 | |
! 3 0.831469612302545236 0.555570233019602178 | |
! 4 0.707106781186547573 0.707106781186547462 | |
! 5 0.555570233019602289 0.831469612302545236 | |
! 6 0.382683432365089782 0.923879532511286738 | |
! 7 0.195090322016128304 0.980785280403230431 | |
! 8 0.000000000000000061 1.000000000000000000 | |
! | |
!Local variables: | |
! compile-command: "gfortran -Wall -ffree-form -o sincos sincos.F && ./sincos" | |
!End: |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment