Fortran Fortran intrinsic functions source code

AI Thread Summary
To view the source code for intrinsic functions in Fortran 90/95, such as sqrt, users can explore the libraries of open-source compilers like g95 and gfortran. While the compiler generates the code, the actual implementations of these functions are often based on complex mathematical algorithms and may not be straightforward to understand without a strong background in numerical analysis. For gfortran, users noted difficulty in locating the source code despite its open-source nature. Additionally, many intrinsic functions are implemented as hardware floating-point instructions, which may involve proprietary algorithms and internal tables for efficiency. Accessing this information can be challenging, as it is typically not publicly available.
issacnewton
Messages
1,035
Reaction score
37
Hi

How can I see the source codes used for defining intrinsic functions in Fortran 90/95 ?
e.g. what is the actual program for sqrt ?

thanks
 
Technology news on Phys.org
The code is generated by the compiler. If the compiler has an option to output assembly code, you can look at the assembly code output by the compiler. Otherwise, you'll need to use a debugger using it's dissassembly mode in order to look at the generated code.
 
Well I meant the programs written for intrinsic functions like sin and cos and sqrt. These programs are based on some mathematical algorithms. For example, sqrt might be exploiting some mathematical algorithm to find the square root. Somebody must have written these
programs long ago. How can I see it ?
 
Thanks Alephzero, I think even gfortran is open source too. Are their source codes open for download too ?
 
Well, if "open source" doesn't mean "the source is available", something's wrong somewhere :smile:

FWIW gfortran was the first place I looked for a link but I couldn't find one (but my attention span looking for it was only about 30 seconds).
 
IssacNewton said:
Well I meant the programs written for intrinsic functions like sin and cos and sqrt.
Much of those functions are implemented as floating point instructions in hardware. The hardware has internal algorithms, some of which include tables to produce initial values to speed up the algorithms. I'm not sure where you could get this information, as it is probably proprietary.
 

Similar threads

Replies
2
Views
1K
Replies
2
Views
1K
Replies
20
Views
3K
Replies
12
Views
2K
Replies
3
Views
2K
Replies
6
Views
2K
Back
Top