Fortran intrinsic functions source code

Click For Summary

Discussion Overview

The discussion revolves around the inquiry into the source code for intrinsic functions in Fortran 90/95, specifically how to access the underlying implementations of functions like sqrt, sin, and cos. Participants explore the nature of these functions, their implementation, and the availability of source code.

Discussion Character

  • Exploratory
  • Technical explanation
  • Debate/contested

Main Points Raised

  • One participant asks how to view the source code for intrinsic functions in Fortran, specifically for sqrt.
  • Another participant suggests that the code is generated by the compiler and can be viewed through assembly code output or a debugger's disassembly mode.
  • A participant clarifies that they are interested in the mathematical algorithms behind intrinsic functions, indicating that these functions are based on specific algorithms for computation.
  • It is mentioned that library source code for open-source compilers, such as g95, may be accessible, but understanding it requires knowledge of numerical analysis.
  • A participant expresses interest in the source code for gfortran, noting its open-source status.
  • Another participant humorously remarks on the potential confusion between "open source" and actual availability of source code, sharing their difficulty in finding a link to gfortran's source code.
  • One participant points out that many intrinsic functions are implemented as hardware floating-point instructions, suggesting that the algorithms used may be proprietary and not publicly available.

Areas of Agreement / Disagreement

Participants express differing views on the availability and nature of the source code for intrinsic functions. While some suggest that open-source compilers may provide access to the source code, others highlight the proprietary nature of hardware implementations, indicating a lack of consensus on the accessibility of the underlying algorithms.

Contextual Notes

Participants note that understanding the source code may require a solid background in numerical analysis, and there is uncertainty regarding the proprietary nature of hardware algorithms used in intrinsic functions.

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
64
Views
11K
  • · Replies 5 ·
Replies
5
Views
5K
  • · Replies 2 ·
Replies
2
Views
1K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 20 ·
Replies
20
Views
4K
  • · Replies 12 ·
Replies
12
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 5 ·
Replies
5
Views
2K