Skip to content

Commit 243ac91

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

File tree

1 file changed

+101
-0
lines changed

1 file changed

+101
-0
lines changed

doc/specs/stdlib_math.md

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
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+
45+
Note: All arguments must have same `type` and same `kind`.
46+
47+
#### Output value or Result value
48+
49+
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.
50+
51+
#### Example(s) of usage
52+
53+
##### Example 1:
54+
55+
Here inputs are of type `integer` and kind `int32`
56+
```fortran
57+
program demo
58+
use stdlib_math
59+
use iso_fortran_env
60+
implicit none
61+
integer(int32) :: x
62+
integer(int32) :: xmin
63+
integer(int32) :: xmax
64+
integer(int32) :: clipped_value
65+
66+
xmin = -5
67+
! xmin <- -5
68+
xmax = 5
69+
! xmax <- 5
70+
x = 12
71+
! x <- 12
72+
73+
clipped_value = clip(x, xmin, xmax)
74+
! clipped_value <- 5
75+
end program demo
76+
```
77+
78+
##### Example 2:
79+
80+
Here inputs are of type `real` and kind `real32` (or `sp`)
81+
```fortran
82+
program demo
83+
use stdlib_math
84+
use iso_fortran_env
85+
implicit none
86+
real(real32) :: x
87+
real(real32) :: xmin
88+
real(real32) :: xmax
89+
real(real32) :: clipped_value
90+
91+
xmin = -5.76999998
92+
! xmin <- -5.76999998
93+
xmax = 3.02500010
94+
! xmax <- 3.02500010
95+
x = 3.02500010
96+
! x <- 3.02500010
97+
98+
clipped_value = clip(x, xmin, xmax)
99+
! clipped_value <- 3.02500010
100+
end program demo
101+
```

0 commit comments

Comments
 (0)