fortran_fortran simple math - wikibooks, open books for an open world

Post on 16-Nov-2015

213 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

  • 3/23/2015 Fortran/FortranSimplemathWikibooks,openbooksforanopenworld

    http://en.wikibooks.org/wiki/Fortran/Fortran_Simple_math 1/2

    Fortran/FortranSimplemath

    PartoftheFortranWikiBook

    Fortranhasthefollowingarithmeticoperators:

    +additionsubtraction*multiplication/division**exponentiation(associatesrighttoleft)

    Herearesomeexamplesoftheiruse:

    i=2+3!setsiequalto5i=2*3!setsiequalto6i=2/3!setsiequalto0,since2/3isroundeddowntotheinteger0,seemixedmodex=2/3.0!setsxapproximatelyequalto2/3or0.666667i=2**3!setsiequalto2*2*2=8

    Fortranhasawiderangeoffunctionsusefulinnumericalwork,suchassin,exp,andlog.Theargumentofafunctionmusthavethepropertype,anditisenclosedinparentheses:

    x=sin(3.14159)!setsxequaltosin(pi),whichiszero

    TheintrinsicmathfunctionsofFortranareelemental,meaningthattheycantakearraysaswellasscalarsasargumentsandreturnascalaroranarrayofthesameshape:

    real::x(2),pi=3.14159x=sin((/pi,pi/2/))

    Theaboveprogramfragmentsetsthetwoelementsofarrayx,x(1)andx(2),equaltosin(pi)andsin(pi/2)respectively.

    Retrievedfrom"http://en.wikibooks.org/w/index.php?title=Fortran/Fortran_Simple_math&oldid=2050329"

    Thispagewaslastmodifiedon19February2011,at01:34.TextisavailableundertheCreativeCommonsAttributionShareAlikeLicense.additionaltermsmayapply.Byusingthissite,youagreetotheTermsofUseandPrivacyPolicy.

    http://en.wikibooks.org/w/index.php?title=Fortran/Fortran_Simple_math&oldid=2050329http://creativecommons.org/licenses/by-sa/3.0/http://wikimediafoundation.org/wiki/Privacy_policyhttp://wikimediafoundation.org/wiki/Terms_of_Usehttp://en.wikibooks.org/wiki/Fortran

  • 3/23/2015 Fortran/FortranSimplemathWikibooks,openbooksforanopenworld

    http://en.wikibooks.org/wiki/Fortran/Fortran_Simple_math 2/2

top related