1
1
module stdlib_stats_distribution_uniform
2
- use stdlib_kinds
2
+ use stdlib_kinds, only : sp, dp, xdp, qp, int8, int16, int32, int64
3
3
use stdlib_error, only : error_stop
4
4
use stdlib_random, only : dist_rand
5
5
@@ -798,28 +798,30 @@ end function pdf_unif_iint64
798
798
elemental function pdf_unif_rsp (x , loc , scale ) result(res)
799
799
800
800
real (sp), intent (in ) :: x, loc, scale
801
- real :: res
801
+ real (sp) :: res
802
+ real (sp), parameter :: zero = 0.0_sp , one = 1.0_sp
802
803
803
- if (scale == 0.0_sp ) then
804
- res = 0.0
804
+ if (scale == zero ) then
805
+ res = zero
805
806
else if (x < loc .or. x > (loc + scale)) then
806
- res = 0.0
807
+ res = zero
807
808
else
808
- res = 1.0 / scale
809
+ res = one / scale
809
810
end if
810
811
end function pdf_unif_rsp
811
812
812
813
elemental function pdf_unif_rdp (x , loc , scale ) result(res)
813
814
814
815
real (dp), intent (in ) :: x, loc, scale
815
- real :: res
816
+ real (dp) :: res
817
+ real (dp), parameter :: zero = 0.0_dp , one = 1.0_dp
816
818
817
- if (scale == 0.0_dp ) then
818
- res = 0.0
819
+ if (scale == zero ) then
820
+ res = zero
819
821
else if (x < loc .or. x > (loc + scale)) then
820
- res = 0.0
822
+ res = zero
821
823
else
822
- res = 1.0 / scale
824
+ res = one / scale
823
825
end if
824
826
end function pdf_unif_rdp
825
827
@@ -829,34 +831,34 @@ end function pdf_unif_rdp
829
831
elemental function pdf_unif_csp (x , loc , scale ) result(res)
830
832
831
833
complex (sp), intent (in ) :: x, loc, scale
832
- real :: res
833
- real (sp) :: tr, ti
834
+ real (sp) :: res, tr, ti
835
+ real (sp), parameter :: zero = 0.0_sp , one = 1.0_sp
834
836
835
837
tr = loc % re + scale % re; ti = loc % im + scale % im
836
- if (scale == (0.0_sp , 0.0_sp )) then
837
- res = 0.0
838
+ if (scale == (zero, zero )) then
839
+ res = zero
838
840
else if ((x % re >= loc % re .and. x % re <= tr) .and. &
839
841
(x % im >= loc % im .and. x % im <= ti)) then
840
- res = 1.0 / (scale % re * scale % im)
842
+ res = one / (scale % re * scale % im)
841
843
else
842
- res = 0.0
844
+ res = zero
843
845
end if
844
846
end function pdf_unif_csp
845
847
846
848
elemental function pdf_unif_cdp (x , loc , scale ) result(res)
847
849
848
850
complex (dp), intent (in ) :: x, loc, scale
849
- real :: res
850
- real (dp) :: tr, ti
851
+ real (dp) :: res, tr, ti
852
+ real (dp), parameter :: zero = 0.0_dp , one = 1.0_dp
851
853
852
854
tr = loc % re + scale % re; ti = loc % im + scale % im
853
- if (scale == (0.0_dp , 0.0_dp )) then
854
- res = 0.0
855
+ if (scale == (zero, zero )) then
856
+ res = zero
855
857
else if ((x % re >= loc % re .and. x % re <= tr) .and. &
856
858
(x % im >= loc % im .and. x % im <= ti)) then
857
- res = 1.0 / (scale % re * scale % im)
859
+ res = one / (scale % re * scale % im)
858
860
else
859
- res = 0.0
861
+ res = zero
860
862
end if
861
863
end function pdf_unif_cdp
862
864
@@ -933,32 +935,34 @@ end function cdf_unif_iint64
933
935
elemental function cdf_unif_rsp (x , loc , scale ) result(res)
934
936
935
937
real (sp), intent (in ) :: x, loc, scale
936
- real :: res
938
+ real (sp) :: res
939
+ real (sp), parameter :: zero = 0.0_sp , one = 1.0_sp
937
940
938
- if (scale == 0.0_sp ) then
939
- res = 0.0
941
+ if (scale == zero ) then
942
+ res = zero
940
943
else if (x < loc) then
941
- res = 0.0
944
+ res = zero
942
945
else if (x >= loc .and. x <= (loc + scale)) then
943
946
res = (x - loc) / scale
944
947
else
945
- res = 1.0
948
+ res = one
946
949
end if
947
950
end function cdf_unif_rsp
948
951
949
952
elemental function cdf_unif_rdp (x , loc , scale ) result(res)
950
953
951
954
real (dp), intent (in ) :: x, loc, scale
952
- real :: res
955
+ real (dp) :: res
956
+ real (dp), parameter :: zero = 0.0_dp , one = 1.0_dp
953
957
954
- if (scale == 0.0_dp ) then
955
- res = 0.0
958
+ if (scale == zero ) then
959
+ res = zero
956
960
else if (x < loc) then
957
- res = 0.0
961
+ res = zero
958
962
else if (x >= loc .and. x <= (loc + scale)) then
959
963
res = (x - loc) / scale
960
964
else
961
- res = 1.0
965
+ res = one
962
966
end if
963
967
end function cdf_unif_rdp
964
968
@@ -968,58 +972,60 @@ end function cdf_unif_rdp
968
972
elemental function cdf_unif_csp (x , loc , scale ) result(res)
969
973
970
974
complex (sp), intent (in ) :: x, loc, scale
971
- real :: res
975
+ real (sp) :: res
976
+ real (sp), parameter :: zero = 0.0_sp , one = 1.0_sp
972
977
logical :: r1, r2, i1, i2
973
978
974
- if (scale == (0.0_sp , 0.0_sp )) then
975
- res = 0.0
979
+ if (scale == (zero, zero )) then
980
+ res = zero
976
981
return
977
982
end if
978
983
r1 = x % re < loc % re
979
984
r2 = x % re > (loc % re + scale % re)
980
985
i1 = x % im < loc % im
981
986
i2 = x % im > (loc % im + scale % im)
982
987
if (r1 .or. i1) then
983
- res = 0.0
988
+ res = zero
984
989
else if ((.not. r1) .and. (.not. r2) .and. i2) then
985
990
res = (x % re - loc % re) / scale % re
986
991
else if ((.not. i1) .and. (.not. i2) .and. r2) then
987
992
res = (x % im - loc % im) / scale % im
988
993
else if ((.not. r1) .and. (.not. r2) .and. (.not. i1) .and. (.not. i2)) &
989
994
then
990
- res = (x % re - loc % re) * (x % im - loc % im) / &
991
- (scale % re * scale % im)
995
+ res = (( x % re - loc % re) / scale % re) * (( x % im - loc % im) / &
996
+ scale % im)
992
997
else if (r2 .and. i2)then
993
- res = 1.0
998
+ res = one
994
999
end if
995
1000
end function cdf_unif_csp
996
1001
997
1002
elemental function cdf_unif_cdp (x , loc , scale ) result(res)
998
1003
999
1004
complex (dp), intent (in ) :: x, loc, scale
1000
- real :: res
1005
+ real (dp) :: res
1006
+ real (dp), parameter :: zero = 0.0_dp , one = 1.0_dp
1001
1007
logical :: r1, r2, i1, i2
1002
1008
1003
- if (scale == (0.0_dp , 0.0_dp )) then
1004
- res = 0.0
1009
+ if (scale == (zero, zero )) then
1010
+ res = zero
1005
1011
return
1006
1012
end if
1007
1013
r1 = x % re < loc % re
1008
1014
r2 = x % re > (loc % re + scale % re)
1009
1015
i1 = x % im < loc % im
1010
1016
i2 = x % im > (loc % im + scale % im)
1011
1017
if (r1 .or. i1) then
1012
- res = 0.0
1018
+ res = zero
1013
1019
else if ((.not. r1) .and. (.not. r2) .and. i2) then
1014
1020
res = (x % re - loc % re) / scale % re
1015
1021
else if ((.not. i1) .and. (.not. i2) .and. r2) then
1016
1022
res = (x % im - loc % im) / scale % im
1017
1023
else if ((.not. r1) .and. (.not. r2) .and. (.not. i1) .and. (.not. i2)) &
1018
1024
then
1019
- res = (x % re - loc % re) * (x % im - loc % im) / &
1020
- (scale % re * scale % im)
1025
+ res = (( x % re - loc % re) / scale % re) * (( x % im - loc % im) / &
1026
+ scale % im)
1021
1027
else if (r2 .and. i2)then
1022
- res = 1.0
1028
+ res = one
1023
1029
end if
1024
1030
end function cdf_unif_cdp
1025
1031
0 commit comments