What is the standard for precision specification in Fortran? [duplicate] - fortran

This question already has answers here:
Fortran: integer*4 vs integer(4) vs integer(kind=4)
(3 answers)
why change "complex*16" to "complex(16)" cause the runtime increased unreasonably in fortran?
(1 answer)
Fortran 90 kind parameter
(6 answers)
Closed 3 years ago.
Let's say if I want a double-precision real, what is the correct way to set the precision of the variable? But not just limited to double precision. I am trying to teach myself Fortran. I have been looking at books, websites and codes. And everywhere I look, I see contradicting stuff, which might indicate that the websites have not been updated.
I have seen:
real*8 :: var
real(8) :: var
real(kind=dp) :: var
All of these seem to do the same thing (I might be wrong). Which is the standard way of doing this for any type of variable (real, integer, complex, logical, etc.)?
Like for complex numbers:
complex(16) :: var
complex(kind(0d0)) :: var
which also seem to be the same (I might be wrong again), but do appear differently in different resources.

Related

How can we calculate a large number in fortran 95 [duplicate]

This question already has answers here:
How do I do big integers in Fortran?
(1 answer)
Fortran: integer*4 vs integer(4) vs integer(kind=4)
(3 answers)
Fortran 90 kind parameter
(6 answers)
Closed 1 year ago.
I'm using silverfrost 95 to coding fortran. I want to calculate large numbers for example 5^5432854
but it errors "integer overflow", I tried kind 8 but it errors "error 600 - The KIND number should be 1, 2, 3, 4, or 7" and also it's not working with kind 7.
What can I do?

expm1 for GNU gfortran [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 7 years ago.
Improve this question
Is there any way to call a fast implementation of expm1 from GNU Fortran?
Ideally, it would be great to have a function to calculate (exp(x)-1)/x directly to avoid extra check for zero argument.
Elemental version of expm1 would be especially helpful.
This is how it's called from libm:
use, intrinsic :: iso_c_binding, only: c_double
implicit none
interface
real(c_double) function expm1(x) bind(c, name='expm1')
import c_double
real(c_double), intent(in), value :: x
end function expm1
end interface
print*, expm1(3.4d0)
end program
If the glibc source code for the function does not look too discouraging then you might wish to translate it into Fortran in order to make it elemental (if by elemental you meant the Fortran keyword).

How to increase the size of the int [duplicate]

This question already has answers here:
BigInteger in C?
(4 answers)
Closed 8 years ago.
I'm looking for a way so that I can get big numbers.
I want to calculate 38^n for n>4000
So is there any way to do this?
Kindly help me.
Look for a BigInt library like this one if the unsigned long long (64-bit integer) does not fit your needs.
Since 38^4000 =
13626567354997617056329313518572669871071170880583693359544272980041303981882434734538430960058767177295025923983566648755876881186325460368486197224167007060233768247052629486933889789012295518920202064862370213656621579461608833913900821509100620666110600996588831934295625624174881269739475099253543291971949351958375909705904924125614847402331728307491174234130043557765333856587852136763450074228033057943275251763474040244718003871446278851718437538753553972738188449864081284199350852720967506441771879828977604092893701331872025324453791540567000401652841385183230548306942426747811381344952202704995790135045091236882434632638273097622784399474964071260288840973524580293683712707126132726032058096115050808212994474874887195248086357178602097170972380906461711265125678088349923203375968414475787300592583696065816150079128755226670110739203817178406747936072376786260989121289233458431976862204647875012437031767751018704749869460607366074818959142212892198396374773980500350327658780222474479129859007194457457829138631699788091425513210781560184664312254850195910716334354324281366251167877851974205334475355985568256387781089509361002196647952275789359155111023451749451415734405096655278295174255960345304122475081165484445003142760913586534250626764015379905517010658444442626228678332925600616931303695695506161883152099899363859336729182377570281814058896416875807664402882868124355445335565905063833617714010822965856571393423962785717867701811630985000479945840574458836679738068978432208205049488474929993540051593774645379459275410621407737459680323962561140718740797900009352381301734433124145413190718954715078693891773766465543820020118333909425037946747920952112324716580163881088322718499979305631739834146130913408498900815005646996682256912339033205133816486824614258926495495812784036447453990264570960357479488597566262100857318557132063094971671138328081636423205300001440991841875093227157189180046979201235997836871115178473793331951908545162574227413951298558070125899512700390047047940487152449438682512124512374465180907633872133729735427824770312681013603101057078687642650433926086042263469811785972516780935001257979167301396531650578909144617556401661596286655000890845598227443074432224649650421444669509917690850588828467680365214374983571440413011029311538006314308009334022145676697106884765702897820392205002104976510511690662873648924905859206045090301538364495227369714240000327397892685270724477432224051710235161915341380166322505403047479921207485985826617144630062427543646106264207676267960138097995365712065699367252327692166917027162817512355112577817759333185119496357726652263574955692412766427791636621561003248143162088338810765811925034175243098253477183777981530119336600325069531470597361199726340530012493284901312472359938906404036536403970381273042347532022592036037374925652036435508211829648726060002645001171965651585268749073280713101532058063840348319740158848595441587678957522413199351039043113142029907129705744137232342011968704198807114940460676009450036521225461344010852618106239118154966331660057415602614793721826584529397251289749725656538096388399695143315928518563068548192735206544682378537520506418007926073285706849973274222076317373033059304200101911951067149937028894562722109537797411167898225856420348308410350603384055632474339567057703010340688068370821291318903177717596801407315734010878564418695310254546381520276678538725157608043309023441709322160712160377986536483006949768428055070012131321307517369398293559849470345086292046748890778373027131007888477361435703338650286281943866790521895536089587012314596482938225348353910513764482608946308253045592163757729525262326745493201953185303485264102739959029696399931572287438132772357749175882967079565029225741296582036140259021566923027054743911617278986639492312193679025969190891540930024189366778105054430929215092236023487686440492543667079519662985565417362492072592025055258819162704173072662013949276074302392094104918002731442385963738154377544394436144830710895941012427657480393526992952298836599116927265835864794883149357772532128926114623377650330127681469398680908197842808781573649462943403899309504315010053951097502630531047921616001572581816853481632903644705002543359747980637999901147726746920478281033260422246532219801930828506609799922586505464736354853965408705166237575268884142550705915838361403803760633861291439873689266312094985645627825768264532068068383940009347237832839084518620736293338032805140684318825609037052029320710069076942327055511619384729507413979366221173731875081583527606225142331708054058056316566268463694297799208229967327456031980737573803309723678915050699869715272912792497268191176053411510542893000088350086703903267923064151320399321810627158761446660416500169785103732189707448149719408203646028631800570100383545558186048239744484408082627734589940230907845416949939893008652775458505691974437891034384581573026445318317396853368414228897325531497788743229729964241347151442038312944349207021462075732646443668171786595400861104506016915734670330338318506940647492024589840270503991235013262662584958056139456884168786647861529375426433055592755996647363095606998572938173742273727647855395827384610580791486231441743966364638926656177574517783395990477645234920662029069130520169839954328852889679297698894440289360920229577366598674693945253544348773443008431294122902200275761539883366488016392721682618754525310713687607682663191813572550150753228158785842023491267134367643177590897108661282968536031908401081453990449167116430269199694437799218382709284611544863462398344387527482864615346690281888178491568067973361859477877403761036289855293359103434207477896715048195648273965669239199756276403324120343903889368419203819744433704771664793914154135622085625251617910720554457686952006577578494073537754699513783351789231152535131897837873522492614650699226752457363727673079692328753548477123197857803197559269831202493927130425819248457221653733937060671839872590344351995222910813966529070591698808960588220021008665427193485211880949161819748058663187983592657186472030052147851033490886803897240924656263389646409848702846770248392608384734172415681411506756891468425081693839740848739676180437868697906407065835441491240347225077345140389966302714596712069918261923483301431653997283019346596069376
You definitely need some kind of big int library. You can find one quite easily on Google or even (if you plan only specific operations), write one on your own. For instance, the above result comes from my own calculator, which supports big integer evaluations.

What does DIST=AMAX1(0.,DI-DJ) means in Fortran? [duplicate]

This question already has an answer here:
What is meant by . usage after a number in Fortran?
(1 answer)
Closed 3 years ago.
I'm trying to understand a code in fortran language and i don't understand what does
DIST=AMAX1(0.,DI-DJ) means.
I am really confused with the dot(.) next to 0 .
Any help would be appreciated.
Thanks in advance
MAria
AMAX1 is a function for obtaining the maximum value of two or more (single precision) floating point values. The . is there to indicate that the argument is a floating point value and not an integer. 0. is short for 0.0, FORTRAN allows you to omit the decimal zero.
There are lots of FORTRAN references on the Internet. Here is a quick list of intrinsic functions, for example.

Listing the contents of a directory in Fortran [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
How do I get the contents of a directory in Fortran 95?
shure if we have all the files in the 'inFiles' folder, we first find out how many are there and then we read their names into an array, check this out:
real :: r
integer :: i,reason,NstationFiles,iStation
character(LEN=100), dimension(:), allocatable :: stationFileNames
! get the files
call system('ls ./inFiles > fileContents.txt')
open(31,FILE='fileContents.txt',action="read")
!how many
i = 0
do
read(31,FMT='(a)',iostat=reason) r
if (reason/=0) EXIT
i = i+1
end do
NstationFiles = i
write(verb,'(a,I0)') "Number of station files: " , NstationFiles
allocate(stationFileNames(NstationFiles))
rewind(31)
do i = 1,NstationFiles
read(31,'(a)') stationFileNames(i)
! write(verb,'(a)') trim(stationFileNames(i))
end do
close(31)
To be pedantic, you don't. There's no intrinsic or such in Fortran 95 that helps you.
On a POSIX system and a recent Fortran compiler, you can use ISO_C_BINDING to create interfaces to the POSIX opendir() and readdir() functions (or readdir_r() if you need thread safety), which allow you to iterate over the directory entries.
There is no concept of a directory in Fortran, as such. It reads files. (There are some processors that don't even have a concept of directory).
With that being said, the easiest way would be with SYSTEM. Depends on what you want with that after ...