@@ -320,25 +320,25 @@ program demo_logspace_rstart_cbase
320
320
321
321
end program demo_logspace_rstart_cbase
322
322
```
323
- ## ` arange `
323
+ ### ` arange `
324
324
325
- ### Status
325
+ #### Status
326
326
327
327
Experimental
328
328
329
- ### Class
329
+ #### Class
330
330
331
331
Pure function.
332
332
333
- ### Description
333
+ #### Description
334
334
335
335
Creates a one-dimensional ` array ` of the ` integer/real ` type with fixed-spaced values of given spacing, within a given interval.
336
336
337
- ### Syntax
337
+ #### Syntax
338
338
339
339
` result = [[stdlib_math(module):arange(interface)]](start [, end, step]) `
340
340
341
- ### Arguments
341
+ #### Arguments
342
342
343
343
All arguments should be the same type and kind.
344
344
@@ -354,18 +354,18 @@ The default `end` value is the inputted `start` value.
354
354
This is an ` intent(in) ` and ` optional ` argument.
355
355
The default ` step ` value is ` 1 ` .
356
356
357
- #### Warning
357
+ ##### Warning
358
358
If ` step = 0 ` , the ` step ` argument will be corrected to ` 1/1.0 ` by the internal process of the ` arange ` function.
359
359
If ` step < 0 ` , the ` step ` argument will be corrected to ` abs(step) ` by the internal process of the ` arange ` function.
360
360
361
- ### Return value
361
+ #### Return value
362
362
363
363
Returns a one-dimensional ` array ` of fixed-spaced values.
364
364
365
365
For ` integer ` type arguments, the length of the result vector is ` (end - start)/step + 1 ` .
366
366
For ` real ` type arguments, the length of the result vector is ` floor((end - start)/step) + 1 ` .
367
367
368
- ### Example
368
+ #### Example
369
369
370
370
``` fortran
371
371
program demo_math_arange
@@ -388,3 +388,143 @@ program demo_math_arange
388
388
389
389
end program demo_math_arange
390
390
```
391
+
392
+ ### ` is_close `
393
+
394
+ #### Description
395
+
396
+ Returns a boolean scalar/array where two scalars/arrays are element-wise equal within a tolerance.
397
+
398
+ ``` fortran
399
+ !> For `real` type
400
+ is_close(a, b, rel_tol, abs_tol) = abs(a - b) <= max(rel_tol*(abs(a), abs(b)), abs_tol)
401
+
402
+ !> and for `complex` type
403
+ is_close(a, b, rel_tol, abs_tol) = is_close(a%re, b%re, rel_tol, abs_tol) .and. &
404
+ is_close(a%im, b%im, rel_tol, abs_tol)
405
+ ```
406
+
407
+ #### Syntax
408
+
409
+ ` bool = [[stdlib_math(module):is_close(interface)]] (a, b [, rel_tol, abs_tol, equal_nan]) `
410
+
411
+ #### Status
412
+
413
+ Experimental.
414
+
415
+ #### Class
416
+
417
+ Elemental function.
418
+
419
+ #### Arguments
420
+
421
+ Note: All ` real/complex ` arguments must have same ` kind ` .
422
+ If the value of ` rel_tol/abs_tol ` is negative (not recommended),
423
+ it will be corrected to ` abs(rel_tol/abs_tol) ` by the internal process of ` is_close ` .
424
+
425
+ ` a ` : Shall be a ` real/complex ` scalar/array.
426
+ This argument is ` intent(in) ` .
427
+
428
+ ` b ` : Shall be a ` real/complex ` scalar/array.
429
+ This argument is ` intent(in) ` .
430
+
431
+ ` rel_tol ` : Shall be a ` real ` scalar/array.
432
+ This argument is ` intent(in) ` and ` optional ` , which is ` sqrt(epsilon(..)) ` by default.
433
+
434
+ ` abs_tol ` : Shall be a ` real ` scalar/array.
435
+ This argument is ` intent(in) ` and ` optional ` , which is ` 0.0 ` by default.
436
+
437
+ ` equal_nan ` : Shall be a ` logical ` scalar/array.
438
+ This argument is ` intent(in) ` and ` optional ` , which is ` .false. ` by default.
439
+ Whether to compare ` NaN ` values as equal. If ` .true. ` ,
440
+ ` NaN ` values in ` a ` will be considered equal to ` NaN ` values in ` b ` .
441
+
442
+ #### Result value
443
+
444
+ Returns a ` logical ` scalar/array.
445
+
446
+ #### Example
447
+
448
+ ``` fortran
449
+ program demo_math_is_close
450
+
451
+ use stdlib_math, only: is_close
452
+ use stdlib_error, only: check
453
+ real :: x(2) = [1, 2], y, NAN
454
+
455
+ y = -3
456
+ NAN = sqrt(y)
457
+
458
+ print *, is_close(x,[real :: 1, 2.1]) !! [T, F]
459
+ print *, is_close(2.0, 2.1, abs_tol=0.1) !! T
460
+ print *, NAN, is_close(2.0, NAN), is_close(2.0, NAN, equal_nan=.true.) !! NAN, F, F
461
+ print *, is_close(NAN, NAN), is_close(NAN, NAN, equal_nan=.true.) !! F, T
462
+
463
+ end program demo_math_is_close
464
+ ```
465
+
466
+ ### ` all_close `
467
+
468
+ #### Description
469
+
470
+ Returns a boolean scalar where two arrays are element-wise equal within a tolerance.
471
+
472
+ #### Syntax
473
+
474
+ ` bool = [[stdlib_math(module):all_close(interface)]] (a, b [, rel_tol, abs_tol, equal_nan]) `
475
+
476
+ #### Status
477
+
478
+ Experimental.
479
+
480
+ #### Class
481
+
482
+ Pure function.
483
+
484
+ #### Arguments
485
+
486
+ Note: All ` real/complex ` arguments must have same ` kind ` .
487
+ If the value of ` rel_tol/abs_tol ` is negative (not recommended),
488
+ it will be corrected to ` abs(rel_tol/abs_tol) ` by the internal process of ` all_close ` .
489
+
490
+ ` a ` : Shall be a ` real/complex ` array.
491
+ This argument is ` intent(in) ` .
492
+
493
+ ` b ` : Shall be a ` real/complex ` array.
494
+ This argument is ` intent(in) ` .
495
+
496
+ ` rel_tol ` : Shall be a ` real ` scalar.
497
+ This argument is ` intent(in) ` and ` optional ` , which is ` sqrt(epsilon(..)) ` by default.
498
+
499
+ ` abs_tol ` : Shall be a ` real ` scalar.
500
+ This argument is ` intent(in) ` and ` optional ` , which is ` 0.0 ` by default.
501
+
502
+ ` equal_nan ` : Shall be a ` logical ` scalar.
503
+ This argument is ` intent(in) ` and ` optional ` , which is ` .false. ` by default.
504
+ Whether to compare ` NaN ` values as equal. If ` .true. ` ,
505
+ ` NaN ` values in ` a ` will be considered equal to ` NaN ` values in ` b ` .
506
+
507
+ #### Result value
508
+
509
+ Returns a ` logical ` scalar.
510
+
511
+ #### Example
512
+
513
+ ``` fortran
514
+ program demo_math_all_close
515
+
516
+ use stdlib_math, only: all_close
517
+ use stdlib_error, only: check
518
+ real :: x(2) = [1, 2], y, NAN
519
+ complex :: z(4, 4)
520
+
521
+ y = -3
522
+ NAN = sqrt(y)
523
+ z = (1.0, 1.0)
524
+
525
+ print *, all_close(z+cmplx(1.0e-11, 1.0e-11), z) !! T
526
+ print *, NAN, all_close([NAN], [NAN]), all_close([NAN], [NAN], equal_nan=.true.)
527
+ !! NAN, F, T
528
+
529
+ end program demo_math_all_close
530
+ ```
0 commit comments