Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Tighter tests for arg/argd/argpi.
  • Loading branch information
zoziha committed Sep 19, 2021
commit feca677eba8d88a2c5a14b020878330c6672380c
6 changes: 3 additions & 3 deletions doc/specs/stdlib_math.md
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ Elemental function.

### Description

`arg` computes the phase angle (radian version) of `complex` scalar in the interval [-π,π].
`arg` computes the phase angle (radian version) of `complex` scalar in the interval (-π,π].
The angles in `theta` are such that `z = abs(z)*exp((0.0, theta))`.

### Syntax
Expand Down Expand Up @@ -399,7 +399,7 @@ Elemental function.

### Description

`argd` computes the phase angle (degree version) of `complex` scalar in the interval [-180.0,180.0].
`argd` computes the phase angle (degree version) of `complex` scalar in the interval (-180.0,180.0].
The angles in `theta` are such that `z = abs(z)*exp((0.0, theta*π/180.0))`.

### Syntax
Expand Down Expand Up @@ -442,7 +442,7 @@ Elemental function.

### Description

`argpi` computes the phase angle (circular version) of `complex` scalar in the interval [-1.0,1.0].
`argpi` computes the phase angle (circular version) of `complex` scalar in the interval (-1.0,1.0].
The angles in `theta` are such that `z = abs(z)*exp((0.0, theta*π))`.

### Syntax
Expand Down
36 changes: 23 additions & 13 deletions src/tests/math/test_math_arg.f90
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
program tester

real :: tol = 1.0e-3
real :: tol = epsilon(1.0)
call test_math_arg_complex
call test_math_argd_complex
call test_math_argpi_complex
Expand All @@ -9,32 +9,42 @@ program tester
contains

subroutine test_math_arg_complex
use stdlib_math, only: arg
use stdlib_math, only: arg
use stdlib_error, only: check

call check(abs(arg(2.0*exp((0.0e0, 0.5))) - 0.5) < tol, msg="arg(2.0*exp((0.0, 0.5))) failed.")
call check(abs(arg((1.7552, 0.9589)) - 0.5) < tol, msg="arg((1.7552, 0.9589)) failed.")
call check(abs(arg((0.0, 0.0)) - 0.0) < tol, msg="arg((0.0, 0.0)) failed.")
print *, 2.0*exp((0.0e0, 0.5)) !! (1.75516510, 0.958851099)

call check(abs(arg(2.0*exp((0.0e0, 0.5))) - 0.5) < tol, msg="arg(2.0*exp((0.0e0, 0.5))) - 0.5) failed.")
call check(abs(arg((1.75516510, 0.958851099)) - 0.5) < tol, msg="arg((1.75516510, 0.958851099)) - 0.5) failed.")
call check(abs(arg((0.0, 0.0)) - 0.0) < tol, msg="arg((0.0, 0.0)) failed.")

end subroutine test_math_arg_complex

subroutine test_math_argd_complex
use stdlib_math, only: argd
use stdlib_math, only: argd
use stdlib_error, only: check

call check(abs(argd(2.0*exp((0.0, 0.5))) - 28.648) < tol, msg="argd(2.0*exp((0.0, 0.5))) failed.")
call check(abs(argd((1.7552, 0.9589)) - 28.648) < tol, msg="argd((1.7552, 0.9589)) failed.")
call check(abs(argd((0.0, 0.0)) - 0.0) < tol, msg="argd((0.0, 0.0)) failed.")
call check(abs(argd(2.0*exp((0.0, 0.5))) - 28.6478882) < tol, msg="argd(2.0*exp((0.0, 0.5))) - 28.6478882) failed.")
call check(abs(argd((1.75516510, 0.958851099)) - 28.6478882) < tol, &
msg="argd((1.75516510, 0.958851099)) - 28.6478882) failed.")
call check(abs(argd((0.0, 0.0)) - 0.0) < tol, msg="argd((0.0, 0.0)) failed.")

end subroutine test_math_argd_complex

subroutine test_math_argpi_complex
use stdlib_math, only: argpi
use stdlib_math, only: argpi
use stdlib_error, only: check
real, parameter :: PI = 4*atan(1.0)

!> Power exponent calculation will introduce calculation errors: 2.0*exp((0.0, PI)) /= (-2.0, 0.0).
print *, 2.0*exp((0.0, PI)), 2.0*exp(cmplx(0.0, -PI)) !! (-2.00000000,-1.748455531E-07), (-2.00000000,1.748455531E-07)
print *, argpi(2.0*exp((0.0, PI))), argpi(2.0*exp(cmplx(0.0, -PI))) !! -0.999999940, 0.999999940

call check(abs(argpi(2.0*exp((0.0, PI))) - (- 1.0)) < tol, msg="argpi(2.0*exp((0.0, PI))) - (- 1.0)) failed.")
call check(abs(argpi(2.0*exp(cmplx(0.0, -PI))) - 1.0) < tol, msg="argpi(2.0*exp(cmplx(0.0, -PI))) - 1.0) failed.")

call check(abs(argpi(2.0*exp((0.0, 0.5))) - 0.159) < tol, msg="argpi(2.0*exp((0.0, 0.5))) failed.")
call check(abs(argpi((1.7552, 0.9589)) - 0.159) < tol, msg="argpi((1.7552, 0.9589)) failed.")
call check(abs(argpi((0.0, 0.0)) - 0.0) < tol, msg="argpi((0.0, 0.0)) failed.")
call check(abs(argpi((-2.0, 0.0)) - 1.0) < tol, msg="argpi((-2.0, 0.0)) - 1.0) failed.") !! (-1.0, 1.0]
call check(abs(argpi(( 0.0, 0.0)) - 0.0) < tol, msg="argpi((0.0, 0.0)) failed.")

end subroutine test_math_argpi_complex

Expand Down