title |
---|
math |
[TOC]
stdlib_math
module provides general purpose mathematical functions.
Returns a value which lies in the given interval [xmin
, xmax
] (interval is xmin
and xmax
inclusive) and is closest to the input value x
.
res = [[stdlib_math(module):clip(interface)]] (x, xmin, xmax)
Experimental
Elemental function.
x
: scalar of either integer
or real
type. This argument is intent(in)
.
xmin
: scalar of either integer
or real
type. This argument is intent(in)
.
xmax
: scalar of either integer
or real
type, which must be greater than or equal to xmin
. This argument is intent(in)
.
Note: All arguments must have same type
and same kind
.
The output is a scalar of type
and kind
same as to that of the arguments.
Here inputs are of type integer
and kind int32
program demo_clip_integer
use stdlib_math, only: clip
use stdlib_kinds, only: int32
implicit none
integer(int32) :: x
integer(int32) :: xmin
integer(int32) :: xmax
integer(int32) :: clipped_value
xmin = -5_int32
xmax = 5_int32
x = 12_int32
clipped_value = clip(x, xmin, xmax)
! clipped_value <- 5
end program demo_clip_integer
Here inputs are of type real
and kind sp
program demo_clip_real
use stdlib_math, only: clip
use stdlib_kinds, only: sp
implicit none
real(sp) :: x
real(sp) :: xmin
real(sp) :: xmax
real(sp) :: clipped_value
xmin = -5.769_sp
xmax = 3.025_sp
x = 3.025_sp
clipped_value = clip(x, xmin, xmax)
! clipped_value <- 3.02500010
end program demo_clip_real
Returns a linearly spaced rank 1 array from [start
, end
]. Optionally, you can specify the length of the returned array by passing n
.
res = [[stdlib_math(module):linspace(interface)]] (start, end [, n])
Experimental
function.
start
: Shall be scalar of any numeric type. This argument is intent(in)
.
end
: Shall be the same type
and kind
as start
. This argument is intent(in)
.
n
: Shall be an integer specifying the length of the output. This argument is intent(in)
.
The output is a rank 1 array of type
and kind
, whose length is either 100 (default value) or n
.
If n
== 1, return a rank 1 array whose only element is end
.
If n
<= 0, return a rank 1 array with length 0
Here inputs are of type complex
and kind dp
program demo_linspace_complex
use stdlib_math, only: linspace
use stdlib_kinds, only: dp
implicit none
complex(dp) :: start = complex(10.0_dp, 5.0_dp)
complex(dp) :: end = complex(-10.0_dp, 15.0_dp)
complex(dp) :: z(11)
z = linspace(start, end, 11)
end program demo_linspace_complex
Here inputs are of type integer
and kind int16
program demo_linspace_int16
use stdlib_math, only: linspace
use stdlib_kinds, only: int16
implicit none
integer(int16) :: start = 10_int16
integer(int16) :: end = 23_int16
integer(int16) :: r(15)
r = linspace(start, end, 15)
end program demo_linspace_int16
Returns a logarithmically spaced rank 1 array from [base
^start
, base
^end
]. Optionally, you can specify the length of the returned array by passing n
.
res = [[stdlib_math(module):logspace(interface)]] (start, end [, n [, base]])
Experimental
function.
start
: Shall be scalar of any numeric type. This argument is intent(in)
.
end
: Shall be the same type
and kind
as start
. This argument is intent(in)
.
n
: Shall be an integer specifying the length of the output. This argument is intent(in)
.
base
: Shall be a scalar of any numeric type. This argument is intent(in)
The output is a rank 1 array of type
and kind
, whose length is either 50 (default value) or n
.
If n
== 1, return a rank 1 array whose only element is base
^end
.
If n
<= 0, return a rank 1 array with length 0
Here inputs are of type complex
and kind dp
program demo_logspace_complex
use stdlib_math, only: logspace
use stdlib_kinds, only: dp
implicit none
complex(dp) :: start = complex(10.0_dp, 5.0_dp)
complex(dp) :: end = complex(-10.0_dp, 15.0_dp)
complex(dp) :: z(11)
z = logspace(start, end, 11)
end program demo_logspace_complex
Here inputs are of type integer
and kind int16
program demo_logspace_int16
use stdlib_math, only: logspace
use stdlib_kinds, only: int16
implicit none
integer(int16) :: start = 10_int16
integer(int16) :: end = 23_int16
integer(int16) :: r(15)
r = logspace(start, end, 15)
end program demo_logspace_int16