You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: doc/specs/stdlib_math.md
+188-3
Original file line number
Diff line number
Diff line change
@@ -19,7 +19,7 @@ title: math
19
19
20
20
#### Description
21
21
22
-
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`.
22
+
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`.
23
23
24
24
#### Syntax
25
25
@@ -35,8 +35,8 @@ Elemental function.
35
35
36
36
#### Argument(s)
37
37
38
-
`x`: scalar of either `integer` or `real` type. This argument is `intent(in)`.
39
-
`xmin`: scalar of either `integer` or `real` type. This argument is `intent(in)`.
38
+
`x`: scalar of either `integer` or `real` type. This argument is `intent(in)`.
39
+
`xmin`: scalar of either `integer` or `real` type. This argument is `intent(in)`.
40
40
`xmax`: scalar of either `integer` or `real` type, which must be greater than or equal to `xmin`. This argument is `intent(in)`.
41
41
42
42
Note: All arguments must have same `type` and same `kind`.
@@ -90,3 +90,188 @@ program demo_clip_real
90
90
! clipped_value <- 3.02500010
91
91
end program demo_clip_real
92
92
```
93
+
94
+
### `linspace` - Create a linearly spaced rank one array
95
+
96
+
#### Description
97
+
98
+
Returns a linearly spaced rank 1 array from [`start`, `end`]. Optionally, you can specify the length of the returned array by passing `n`.
99
+
100
+
#### Syntax
101
+
102
+
`res = [[stdlib_math(module):linspace(interface)]] (start, end [, n])`
103
+
104
+
#### Status
105
+
106
+
Experimental
107
+
108
+
#### Class
109
+
110
+
Function.
111
+
112
+
#### Argument(s)
113
+
114
+
`start`: Shall be scalar of any numeric type or kind. This argument is `intent(in)`.
115
+
`end`: Shall be the same `type` and `kind` as `start`. This argument is `intent(in)`.
116
+
`n`: Shall be an integer specifying the length of the output. This argument is `optional` and `intent(in)`.
117
+
118
+
#### Output value or Result value
119
+
120
+
The output is a rank 1 array whose length is either 100 (default value) or `n`.
121
+
122
+
If `n` == 1, return a rank 1 array whose only element is `end`.
123
+
If `n` <= 0, return a rank 1 array with length 0.
124
+
125
+
If `start`/`end` are `real` or `complex` types, the `result` will be of the same type and kind as `start`/`end`.
126
+
If `start`/`end` are `integer` types, the `result` will default to a `real(dp)` array.
127
+
128
+
#### Examples
129
+
130
+
##### Example 1:
131
+
132
+
Here inputs are of type `complex` and kind `dp`
133
+
```fortran
134
+
program demo_linspace_complex
135
+
use stdlib_math, only: linspace
136
+
use stdlib_kinds, only: dp
137
+
implicit none
138
+
139
+
complex(dp) :: start = complex(10.0_dp, 5.0_dp)
140
+
complex(dp) :: end = complex(-10.0_dp, 15.0_dp)
141
+
142
+
complex(dp) :: z(11)
143
+
144
+
z = linspace(start, end, 11)
145
+
end program demo_linspace_complex
146
+
```
147
+
148
+
##### Example 2:
149
+
150
+
Here inputs are of type `integer` and kind `int16`, with the result defaulting to `real(dp)`.
151
+
```fortran
152
+
program demo_linspace_int16
153
+
use stdlib_math, only: linspace
154
+
use stdlib_kinds, only: int16, dp
155
+
implicit none
156
+
157
+
integer(int16) :: start = 10_int16
158
+
integer(int16) :: end = 23_int16
159
+
160
+
real(dp) :: r(15)
161
+
162
+
r = linspace(start, end, 15)
163
+
end program demo_linspace_int16
164
+
```
165
+
166
+
### `logspace` - Create a logarithmically spaced rank one array
167
+
168
+
#### Description
169
+
170
+
Returns a logarithmically spaced rank 1 array from [`base`^`start`, `base`^`end`]. The default size of the array is 50. Optionally, you can specify the length of the returned array by passing `n`. You can also specify the `base` used to compute the range (default 10).
171
+
172
+
#### Syntax
173
+
174
+
`res = [[stdlib_math(module):logspace(interface)]] (start, end [, n [, base]])`
175
+
176
+
#### Status
177
+
178
+
Experimental
179
+
180
+
#### Class
181
+
182
+
Function.
183
+
184
+
#### Argument(s)
185
+
186
+
`start`: Shall be a scalar of any numeric type. All kinds are supported for real and complex arguments. For integers, only the default kind is currently implemented. This argument is `intent(in)`.
187
+
`end`: Shall be the same `type` and `kind` as `start`. This argument is `intent(in)`.
188
+
`n`: Shall be an integer specifying the length of the output. This argument is `optional` and `intent(in)`.
189
+
`base` : Shall be a scalar of any numeric type. All kinds are supported for real and complex arguments. For integers, only the default kind is currently implemented. This argument is `optional` and `intent(in)`.
190
+
191
+
#### Output value or Result value
192
+
193
+
The output is a rank 1 array whose length is either 50 (default value) or `n`.
194
+
195
+
If `n` == 1, return a rank 1 array whose only element is `base`^`end`.
196
+
If `n` <= 0, return a rank 1 array with length 0
197
+
198
+
The `type` and `kind` of the output is dependent on the `type` and `kind` of the passed parameters.
199
+
200
+
For function calls where the `base` is not specified: `logspace(start, end)`/`logspace(start, end, n)`, the `type` and `kind` of
201
+
the output follows the same scheme as above for `linspace`.
202
+
>If `start`/`end` are `real` or `complex` types, the `result` will be the same type and kind as `start`/`end`.
203
+
>If `start`/`end` are integer types, the `result` will default to a `real(dp)` array.
204
+
205
+
For function calls where the `base` is specified, the `type` and `kind` of the result is in accordance with the following table:
0 commit comments