Skip to content

Commit 1b0d0a5

Browse files
committed
documented clip function in newly created stdlib_math.md file
1 parent 5d108de commit 1b0d0a5

File tree

1 file changed

+100
-0
lines changed

1 file changed

+100
-0
lines changed

doc/specs/stdlib_math.md

+100
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
---
2+
title: math
3+
---
4+
5+
# The `stdlib_math` module
6+
7+
[TOC]
8+
9+
## Introduction
10+
11+
`stdlib_math` module provides with general purpose mathematical functions.
12+
13+
14+
## Procedures and Methods provided
15+
16+
17+
<!-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -->
18+
### `clip` function
19+
20+
#### Description
21+
22+
Limits the input value `x` to the given interval [`xmin`, `xmax`] (interval is `xmin` and `xmax` inclusive). Returns a value which lies in the given interval and is closest to the input value `x`.
23+
If the input value `x` already lies in the given interval, then the output value will be equal to the input value.
24+
25+
Note: A valid input must **NOT** have `xmin` value greater than `xmax` value.
26+
27+
#### Syntax
28+
29+
`res = [[stdlib_math(module):clip(interface)]] (x, xmin, xmax)`
30+
31+
#### Status
32+
33+
Experimental
34+
35+
#### Class
36+
37+
Elemental function.
38+
39+
#### Argument(s)
40+
41+
`x`: scalar of either `integer` or `real`. This argument is `intent(in)`.
42+
`xmin`: scalar of either `integer` or `real`. This argument is `intent(in)`.
43+
`xmax`: scalar of either `integer` or `real`. This argument is `intent(in)`.
44+
All arguments must have same `type` and same `kind`.
45+
46+
#### Output value or Result value
47+
48+
Output is a scalar of either `integer` or `real` depending on the arguments. The output value will have `type` and `kind` same as to that of the arguments.
49+
50+
#### Example(s) of usage
51+
52+
##### Example 1:
53+
54+
Here inputs are of type `integer` and kind `int32`
55+
```fortran
56+
program demo
57+
use stdlib_math
58+
use iso_fortran_env
59+
implicit none
60+
integer(int32) :: x
61+
integer(int32) :: xmin
62+
integer(int32) :: xmax
63+
integer(int32) :: clipped_value
64+
65+
xmin = -5
66+
! xmin <- -5
67+
xmax = 5
68+
! xmax <- 5
69+
x = 12
70+
! x <- 12
71+
72+
clipped_value = clip(x, xmin, xmax)
73+
! clipped_value <- 5
74+
end program demo
75+
```
76+
77+
##### Example 2:
78+
79+
Here inputs are of type `real` and kind `real32` (or `sp`)
80+
```fortran
81+
program demo
82+
use stdlib_math
83+
use iso_fortran_env
84+
implicit none
85+
real(real32) :: x
86+
real(real32) :: xmin
87+
real(real32) :: xmax
88+
real(real32) :: clipped_value
89+
90+
xmin = -5.76999998
91+
! xmin <- -5.76999998
92+
xmax = 3.02500010
93+
! xmax <- 3.02500010
94+
x = 3.02500010
95+
! x <- 3.02500010
96+
97+
clipped_value = clip(x, xmin, xmax)
98+
! clipped_value <- 3.02500010
99+
end program demo
100+
```

0 commit comments

Comments
 (0)