パスワードを忘れた? アカウント作成
477859 journal

t-nissieの日記: Fortran

日記 by t-nissie

$ cat power.f
! power.f -*-f90-*-
! Time-stamp: <2007-12-10 14:51:55 t-nissie>
!!
recursive real*8 function power(x,n) result(pow)
  implicit none
  real*8,  intent(in) :: x
  integer, intent(in) :: n
  if (n<=0) then
        pow = 1.0d0
  else
     if (mod(n,2).eq.0) then
        pow = power(x*x, n/2)
     else
        pow = x * power(x, n-1)
     end if
  end if
end function power
 
program power_test
  implicit none
  integer argn,n
  real*8 x, power
  character (len=100) :: str
 
  argn = command_argument_count()
  if (argn.ne.2) stop 'usage: power x n'
 
  call get_command_argument(1,str)
  read(str,*) x
 
  call get_command_argument(2,str)
  read(str,*) n
 
  write(6,*) power(x,n)
end program power_test
$ cat Makefile
#-*-Makefile-*- for power
# Time-stamp: <2007-12-10 14:55:25 t-nissie>
##
 
## gfortran (GNU Fortran in GCC)
FC=gfortran
FFLAGS=-O3 -Wall -ffree-form
 
all: power.s power
 
power.s: power.f
        $(FC) -S $(FFLAGS) $< -o $@
 
clean:
        rm -f core *.s power
$ ./power 1.00000001 1000000000

アセンブラ power.s、call power_が14箇所もあるんだが。

この議論は賞味期限が切れたので、アーカイブ化されています。 新たにコメントを付けることはできません。
typodupeerror

クラックを法規制強化で止められると思ってる奴は頭がおかしい -- あるアレゲ人

読み込み中...