M_constants(3f) - [M_constants:INTRO] Useful constants
Synopsis
Description
Universal Constants
Physical Constants
Notes
Example
use M_constants, only : uc ! real128 constants uc%qp%pi uc%qp%gamma uc%qp%e uc%qp%golden_ratio uc%qp%euler! real64 constants uc%dp%pi uc%dp%gamma uc%dp%e uc%dp%golden_ratio uc%dp%euler
! real32 constants uc%sp%pi uc%sp%gamma uc%sp%e uc%sp%golden_ratio uc%sp%euler
use M_constants, only : fmt ! formats fmt%all fmt%commas
use M_constants, | |||||
only : lets
! ASCII character set strings
lets%upper
lets%lower
lets%hexadecimal
lets%digits
| |||||
Useful universal constants, physical constants, formats, ...
e The base of the natural logarithm system. "e" was named in honor of Euler, but is known as Napiers constant. "euler" gamma The Euler-Mascheroni constant is often denoted by a lower-case Gamma. golden_ratio In mathematics, two quantities are in the golden ratio if their ratio is the same as the ratio of their sum to the larger of the two quantities. so for a > b > 0, (a + b)/ a = a/b where the Greek letter phi often denotes the golden ratio. pi The ratio of the circumference of a circle to the diameter of the circle
"deg_per_rad" "rad_per_deg"
c__m_per_sec Speed of light in a vacuum c__ft_per_sec Speed of light in a vacuum
Gamma is defined as
Gamma = limit ( M -> Infinity ) ( Sum ( 1 <= N <= M ) 1 / N ) - Log ( M )
Sample program:
program demo_M_constants use, intrinsic :: iso_fortran_env, only : stdout=>OUTPUT_UNIT use M_constants, only : uc, fmt, lets, calen implicit none ! give a local name to a constant: ! universal constant, single-precision, e real,parameter :: e=uc%sp%e character(len=*),parameter :: all=fmt%all integer :: iResults:! or just use full name ! universal constant, quad-precision, gamma print fmt%all, gamma=,uc%qp%gamma print all, e=,e ! ! or rename it with ASSOCIATE associate (gamma => uc%dp%gamma) print all,gamma=,gamma end associate ! ! string constants: ! ! strings of letter sets print all,lets%upper=,lets%upper print all,lets%lower=,lets%lower print all,lets%hexadecimal=,lets%hexadecimal print all,lets%digits=,lets%digits ! ! English civil calendar names print fmt%commas,calen%months=,new_line(a),(calen%months(i:i+2) & & ,new_line(a),i=1,size(calen%months),3) print fmt%commas,calen%mths=,calen%mths print fmt%commas,calen%weekdays=,& & (trim(calen%weekdays(i)),i=1,size(calen%weekdays)) print fmt%commas,calen%wkds=,calen%wkds
end program demo_M_constants
> gamma= 0.577215664901532860606512090082402471 > e= 2.71828175 > gamma= 0.57721566490153287 > lets%upper= ABCDEFGHIJKLMNOPQRSTUVWXYZ > lets%lower= abcdefghijklmnopqrstuvwxyz > lets%hexadecimal= ABCDEFabcdef0123456789 > lets%digits= 0123456789 > calen%months=, > ,January ,February ,March , > ,April ,May ,June , > ,July ,August ,September, > ,October ,November ,December , > > calen%mths=,Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec > calen%weekdays=,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday,Sunday > calen%wkds=,Mon,Tue,Wed,Thu,Fri,Sat,Sun
Nemo Release 3.1 | M_constants (3) | February 23, 2025 |