Skip to content

Commit bf60ba1

Browse files
authored
Merge pull request #624 from zoziha/minor_update
[stdlib_math] Minor update to `stdlib_math` module and document
2 parents 6957436 + 4ef8650 commit bf60ba1

8 files changed

+156
-145
lines changed

API-doc-FORD-file.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
project: Fortran-lang/stdlib
33
summary: A community driven standard library for (modern) Fortran
44
src_dir: src
5+
include: src
56
exclude_dir: src/tests
67
output_dir: API-doc
78
page_dir: doc

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ Changes to existing modules
5252
- change in module `stdlib_io`
5353
- Modified format constants, and made public
5454
[#617](https://github.com/fortran-lang/stdlib/pull/617)
55+
- change in module `stdlib_math`
56+
- Minor update to `stdlib_math` module and document
57+
[#624](https://github.com/fortran-lang/stdlib/pull/624)
5558

5659

5760
# Version 0.1.0

doc/specs/stdlib_math.md

Lines changed: 46 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ program demo_logspace_rstart_cbase
320320
321321
end program demo_logspace_rstart_cbase
322322
```
323-
### `arange`
323+
### `arange` function
324324

325325
#### Status
326326

@@ -332,7 +332,7 @@ Pure function.
332332

333333
#### Description
334334

335-
Creates a one-dimensional `array` of the `integer/real` type with fixed-spaced values of given spacing, within a given interval.
335+
Creates a rank-1 `array` of the `integer/real` type with fixed-spaced values of given spacing, within a given interval.
336336

337337
#### Syntax
338338

@@ -360,7 +360,7 @@ If `step < 0`, the `step` argument will be corrected to `abs(step)` by the inter
360360

361361
#### Return value
362362

363-
Returns a one-dimensional `array` of fixed-spaced values.
363+
Returns a rank-1 `array` of fixed-spaced values.
364364

365365
For `integer` type arguments, the length of the result vector is `(end - start)/step + 1`.
366366
For `real` type arguments, the length of the result vector is `floor((end - start)/step) + 1`.
@@ -371,25 +371,25 @@ For `real` type arguments, the length of the result vector is `floor((end - star
371371
program demo_math_arange
372372
use stdlib_math, only: arange
373373
374-
print *, arange(3) !! [1,2,3]
375-
print *, arange(-1) !! [1,0,-1]
376-
print *, arange(0,2) !! [0,1,2]
377-
print *, arange(1,-1) !! [1,0,-1]
378-
print *, arange(0, 2, 2) !! [0,2]
374+
print *, arange(3) ! [1,2,3]
375+
print *, arange(-1) ! [1,0,-1]
376+
print *, arange(0,2) ! [0,1,2]
377+
print *, arange(1,-1) ! [1,0,-1]
378+
print *, arange(0, 2, 2) ! [0,2]
379379
380-
print *, arange(3.0) !! [1.0,2.0,3.0]
381-
print *, arange(0.0,5.0) !! [0.0,1.0,2.0,3.0,4.0,5.0]
382-
print *, arange(0.0,6.0,2.5) !! [0.0,2.5,5.0]
380+
print *, arange(3.0) ! [1.0,2.0,3.0]
381+
print *, arange(0.0,5.0) ! [0.0,1.0,2.0,3.0,4.0,5.0]
382+
print *, arange(0.0,6.0,2.5) ! [0.0,2.5,5.0]
383383
384-
print *, (1.0,1.0)*arange(3) !! [(1.0,1.0),(2.0,2.0),[3.0,3.0]]
384+
print *, (1.0,1.0)*arange(3) ! [(1.0,1.0),(2.0,2.0),[3.0,3.0]]
385385
386-
print *, arange(0.0,2.0,-2.0) !! [0.0,2.0]. Not recommended: `step` argument is negative!
387-
print *, arange(0.0,2.0,0.0) !! [0.0,1.0,2.0]. Not recommended: `step` argument is zero!
386+
print *, arange(0.0,2.0,-2.0) ! [0.0,2.0]. Not recommended: `step` argument is negative!
387+
print *, arange(0.0,2.0,0.0) ! [0.0,1.0,2.0]. Not recommended: `step` argument is zero!
388388
389389
end program demo_math_arange
390390
```
391391

392-
### `arg` - Computes the phase angle in radian of a complex scalar
392+
### `arg` function
393393

394394
#### Status
395395

@@ -424,13 +424,14 @@ Notes: Although the angle of the complex number `0` is undefined, `arg((0,0))` r
424424
```fortran
425425
program demo_math_arg
426426
use stdlib_math, only: arg
427-
print *, arg((0.0, 0.0)) !! 0.0
428-
print *, arg((3.0, 4.0)) !! 0.927
429-
print *, arg(2.0*exp((0.0, 0.5))) !! 0.5
427+
print *, arg((0.0, 0.0)) ! 0.0
428+
print *, arg((3.0, 4.0)) ! 0.927
429+
print *, arg(2.0*exp((0.0, 0.5))) ! 0.5
430+
print *, arg([(0.0, 1.0), (1.0, 0.0), (0.0, -1.0), (-1.0, 0.0)]) ! [π/2, 0.0, -π/2, π]
430431
end program demo_math_arg
431432
```
432433

433-
### `argd` - Computes the phase angle in degree of a complex scalar
434+
### `argd` function
434435

435436
#### Status
436437

@@ -465,13 +466,14 @@ Notes: Although the angle of the complex number `0` is undefined, `argd((0,0))`
465466
```fortran
466467
program demo_math_argd
467468
use stdlib_math, only: argd
468-
print *, argd((0.0, 0.0)) !! 0.0
469-
print *, argd((3.0, 4.0)) !! 53.1°
470-
print *, argd(2.0*exp((0.0, 0.5))) !! 28.64°
469+
print *, argd((0.0, 0.0)) ! 0.0°
470+
print *, argd((3.0, 4.0)) ! 53.1°
471+
print *, argd(2.0*exp((0.0, 0.5))) ! 28.64°
472+
print *, argd([(0.0, 1.0), (1.0, 0.0), (0.0, -1.0), (-1.0, 0.0)]) ! [90°, 0°, -90°, 180°]
471473
end program demo_math_argd
472474
```
473475

474-
### `argpi` - Computes the phase angle in circular of a complex scalar
476+
### `argpi` function
475477

476478
#### Status
477479

@@ -506,13 +508,14 @@ Notes: Although the angle of the complex number `0` is undefined, `argpi((0,0))`
506508
```fortran
507509
program demo_math_argpi
508510
use stdlib_math, only: argpi
509-
print *, argpi((0.0, 0.0)) !! 0.0
510-
print *, argpi((3.0, 4.0)) !! 0.295
511-
print *, argpi(2.0*exp((0.0, 0.5))) !! 0.159
511+
print *, argpi((0.0, 0.0)) ! 0.0
512+
print *, argpi((3.0, 4.0)) ! 0.295
513+
print *, argpi(2.0*exp((0.0, 0.5))) ! 0.159
514+
print *, argpi([(0.0, 1.0), (1.0, 0.0), (0.0, -1.0), (-1.0, 0.0)]) ! [0.5, 0.0, -0.5, 1.0]
512515
end program demo_math_argpi
513516
```
514517

515-
### `is_close`
518+
### `is_close` function
516519

517520
#### Description
518521

@@ -577,15 +580,15 @@ program demo_math_is_close
577580
y = -3
578581
NAN = sqrt(y)
579582
580-
print *, is_close(x,[real :: 1, 2.1]) !! [T, F]
581-
print *, is_close(2.0, 2.1, abs_tol=0.1) !! T
582-
print *, NAN, is_close(2.0, NAN), is_close(2.0, NAN, equal_nan=.true.) !! NAN, F, F
583-
print *, is_close(NAN, NAN), is_close(NAN, NAN, equal_nan=.true.) !! F, T
583+
print *, is_close(x,[real :: 1, 2.1]) ! [T, F]
584+
print *, is_close(2.0, 2.1, abs_tol=0.1) ! T
585+
print *, NAN, is_close(2.0, NAN), is_close(2.0, NAN, equal_nan=.true.) ! NAN, F, F
586+
print *, is_close(NAN, NAN), is_close(NAN, NAN, equal_nan=.true.) ! F, T
584587
585588
end program demo_math_is_close
586589
```
587590

588-
### `all_close`
591+
### `all_close` function
589592

590593
#### Description
591594

@@ -643,29 +646,26 @@ program demo_math_all_close
643646
NAN = sqrt(y)
644647
z = (1.0, 1.0)
645648
646-
print *, all_close(z+cmplx(1.0e-11, 1.0e-11), z) !! T
649+
print *, all_close(z+cmplx(1.0e-11, 1.0e-11), z) ! T
647650
print *, NAN, all_close([NAN], [NAN]), all_close([NAN], [NAN], equal_nan=.true.)
648-
!! NAN, F, T
651+
! NAN, F, T
649652
650653
end program demo_math_all_close
651654
```
652655

653-
### `diff`
656+
### `diff` function
654657

655658
#### Description
656659

657660
Computes differences between adjacent elements of an array.
658661

659662
#### Syntax
660663

661-
For a rank-1 array
662-
```fortran
663-
y = [[stdlib_math(module):diff(interface)]](x [, n, prepend, append])
664-
```
665-
and for a rank-2 array
666-
```fortran
667-
y = [[stdlib_math(module):diff(interface)]](x [, n, dim, prepend, append])
668-
```
664+
For a rank-1 array:
665+
`y = [[stdlib_math(module):diff(interface)]](x [, n, prepend, append])`
666+
667+
and for a rank-2 array:
668+
`y = [[stdlib_math(module):diff(interface)]](x [, n, dim, prepend, append])`
669669

670670
#### Status
671671

@@ -696,8 +696,9 @@ Shall be a `real/integer` and `rank-1/rank-2` array.
696696
This argument is `intent(in)` and `optional`, which is no value by default.
697697

698698
Note:
699-
- The `x`, `prepend` and `append` arguments must have the same `type`, `kind` and `rank`.
700-
- If the value of `n` is less than or equal to `0` (which is not recommended), the return value of `diff` is `x`.
699+
700+
- The `x`, `prepend` and `append` arguments must have the same `type`, `kind` and `rank`.
701+
- If the value of `n` is less than or equal to `0` (which is not recommended), the return value of `diff` is `x`.
701702
- If the value of `dim` is not equal to `1` or `2` (which is not recommended),
702703
`1` will be used by the internal process of `diff`.
703704

src/stdlib_math.fypp

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ module stdlib_math
287287
!>
288288
!> `arange` creates a one-dimensional `array` of the `integer/real` type
289289
!> with fixed-spaced values of given spacing, within a given interval.
290-
!> ([Specification](../page/specs/stdlib_math.html#arange))
290+
!> ([Specification](../page/specs/stdlib_math.html#arange-function))
291291
interface arange
292292
#:set RI_KINDS_TYPES = REAL_KINDS_TYPES + INT_KINDS_TYPES
293293
#:for k1, t1 in RI_KINDS_TYPES
@@ -302,7 +302,7 @@ module stdlib_math
302302
!> Version: experimental
303303
!>
304304
!> `arg` computes the phase angle in the interval (-π,π].
305-
!> ([Specification](../page/specs/stdlib_math.html#arg))
305+
!> ([Specification](../page/specs/stdlib_math.html#arg-function))
306306
interface arg
307307
#:for k1 in CMPLX_KINDS
308308
procedure :: arg_${k1}$
@@ -312,7 +312,7 @@ module stdlib_math
312312
!> Version: experimental
313313
!>
314314
!> `argd` computes the phase angle of degree version in the interval (-180.0,180.0].
315-
!> ([Specification](../page/specs/stdlib_math.html#argd))
315+
!> ([Specification](../page/specs/stdlib_math.html#argd-function))
316316
interface argd
317317
#:for k1 in CMPLX_KINDS
318318
procedure :: argd_${k1}$
@@ -322,15 +322,15 @@ module stdlib_math
322322
!> Version: experimental
323323
!>
324324
!> `argpi` computes the phase angle of circular version in the interval (-1.0,1.0].
325-
!> ([Specification](../page/specs/stdlib_math.html#argpi))
325+
!> ([Specification](../page/specs/stdlib_math.html#argpi-function))
326326
interface argpi
327327
#:for k1 in CMPLX_KINDS
328328
procedure :: argpi_${k1}$
329329
#:endfor
330330
end interface argpi
331331

332332
!> Returns a boolean scalar/array where two scalar/arrays are element-wise equal within a tolerance.
333-
!> ([Specification](../page/specs/stdlib_math.html#is_close))
333+
!> ([Specification](../page/specs/stdlib_math.html#is_close-function))
334334
interface is_close
335335
#:set RC_KINDS_TYPES = REAL_KINDS_TYPES + CMPLX_KINDS_TYPES
336336
#:for k1, t1 in RC_KINDS_TYPES
@@ -345,7 +345,7 @@ module stdlib_math
345345
!> Version: experimental
346346
!>
347347
!> Returns a boolean scalar where two arrays are element-wise equal within a tolerance.
348-
!> ([Specification](../page/specs/stdlib_math.html#all_close))
348+
!> ([Specification](../page/specs/stdlib_math.html#all_close-function))
349349
interface all_close
350350
#:set RC_KINDS_TYPES = REAL_KINDS_TYPES + CMPLX_KINDS_TYPES
351351
#:set RANKS = range(1, MAXRANK + 1)
@@ -363,7 +363,7 @@ module stdlib_math
363363
!> Version: experimental
364364
!>
365365
!> Computes differences between adjacent elements of an array.
366-
!> ([Specification](../page/specs/stdlib_math.html#diff))
366+
!> ([Specification](../page/specs/stdlib_math.html#diff-function))
367367
interface diff
368368
#:set RI_KINDS_TYPES = REAL_KINDS_TYPES + INT_KINDS_TYPES
369369
#:for k1, t1 in RI_KINDS_TYPES
@@ -409,17 +409,18 @@ contains
409409
${t1}$, intent(in) :: z
410410
real(${k1}$) :: result
411411

412-
result = merge(0.0_${k1}$, atan2(z%im, z%re), z == (0.0_${k1}$, 0.0_${k1}$)) &
413-
*180.0_${k1}$/PI_${k1}$
412+
result = merge(0.0_${k1}$, atan2(z%im, z%re)*180.0_${k1}$/PI_${k1}$, &
413+
z == (0.0_${k1}$, 0.0_${k1}$))
414414

415415
end function argd_${k1}$
416416

417417
elemental function argpi_${k1}$(z) result(result)
418418
${t1}$, intent(in) :: z
419419
real(${k1}$) :: result
420420

421-
result = merge(0.0_${k1}$, atan2(z%im, z%re), z == (0.0_${k1}$, 0.0_${k1}$)) &
422-
/PI_${k1}$
421+
result = merge(0.0_${k1}$, atan2(z%im, z%re)/PI_${k1}$, &
422+
z == (0.0_${k1}$, 0.0_${k1}$))
423+
423424

424425
end function argpi_${k1}$
425426
#:endfor

src/tests/math/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,3 @@ fypp_f90("${fyppFlags}" "${fppFiles}" outFiles)
77
ADDTEST(stdlib_math)
88
ADDTEST(linspace)
99
ADDTEST(logspace)
10-
ADDTEST(math_arange)

src/tests/math/Makefile.manual

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ SRCFYPP = \
33
SRCGEN = $(SRCFYPP:.fypp=.f90)
44

55
PROGS_SRC = test_linspace.f90 test_logspace.f90 \
6-
test_math_arange.f90 \
76
$(SRCGEN)
87

98
$(SRCGEN): %.f90: %.fypp ../../common.fypp

src/tests/math/test_math_arange.f90

Lines changed: 0 additions & 86 deletions
This file was deleted.

0 commit comments

Comments
 (0)