Jump to content

Real constants and functions: Difference between revisions

→‎{{header|Fortran}}: Details, details...
(→‎{{header|Fortran}}: Details, details...)
Line 647:
 
=={{header|Fortran}}==
<lang fortran>e ! Not available. Can be calculated EXP(1)
e ! Not available. Can be calculated EXP(1.0)
pi ! Not available. Can be calculated 4.0*ATAN(1.0)
SQRT(x) ! square root
Line 657 ⟶ 658:
CEILING(x) ! ceiling - Fortran 90 or later only
x**y ! x raised to the y power</lang>
 
4*ATAN(1.0) will be calculated in single precision, likewise EXP(1.0) (not EXP(1), because 1 is an integer) and although double precision functions can be named explicitly, 4*DATAN(1.0) will be rejected because 1.0 is in single precision and DATAN expects double. Thus, 4*DATAN(1.0D0) or 4*DATAN(1D0) will do, as the D in the exponent form specifies double precision. Whereupon, the generic names can be returned to: 4*ATAN(1D0). Some systems go further and offer quadruple precision. Others allow that all constants will be deemed double precision as a compiler option.
 
The 4 need not be named as 4.0, or 4D0, as 4 the integer will be converted by the compiler to double precision, because it is to meet a known double precision value in simple multiplication and so will be promoted. Hopefully, at compile time.
 
=={{header|Frink}}==
1,220

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.