Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

My_sin function

JohnNichols
Valued Contributor III
330 Views

Dear Intel Guru:

The manual sample for function my_sin is not really good Fortran practice,  here is a suggestion tacked onto the bsearch suggestion, it can be pulled apart, I do not want to put in any more time

 

USE IFPORT
    INTEGER(4) array(10), length
    INTEGER(4) result, target
    double precision res, input
    length = SIZE(array)
    do i = 1,length
        array(i) = i
    end do
    target = 8
    write(*,100)length,array,target
100 Format("Array length :: ",i4,/,"Array Elements :: ",10i5,/,"Target number :: ",i5)
    result = BSEARCHQQ(LOC(target),LOC(array),length,SRT$INTEGER4)
    write(*,*)"Location :: ", result
    
    
    input = 3.0*3.0
    res = my_sin(input)
    write(*,*)"Res :: ", res
    contains
    DOUBLE PRECISION FUNCTION MY_SIN(X)
    implicit none
    double precision X
    integer(4) N,I
    MY_SIN = X - X**3/FACTOR(3) + X**5/FACTOR(5)                    &
        &          - X**7/FACTOR(7)
    
    END FUNCTION MY_SIN
    
    INTEGER FUNCTION FACTOR(N)
    implicit none
    integer(4) N, I
    FACTOR = 1
    DO 10 I = N, 1, -1
10  FACTOR = FACTOR * I
    END FUNCTION FACTOR
    End
0 Kudos
1 Reply
Barbara_P_Intel
Employee
282 Views

IMHO that example serves its purpose regarding fixed and free source forms. AND it compiles!

 

0 Kudos
Reply