@@ -7,7 +7,7 @@ for f in (:sin, :cos, :tan, :asin, :acos, :acosh, :atanh, :log, :log2, :log10,
7
7
($ f)(x:: Float64 ) = ccall (($ (string (f)),Base. Math. libm), Float64, (Float64,), x)
8
8
($ f)(x:: Float32 ) = ccall (($ (string (f," f" )),Base. Math. libm), Float32, (Float32,), x)
9
9
($ f)(x:: Real ) = ($ f)(float (x))
10
- function ($ f){T <: Number } (x:: AbstractArray{T} )
10
+ function ($ f)(x:: AbstractArray{T} ) where T <: Number
11
11
Base. depwarn (" $f {T<:Number}(x::AbstractArray{T}) is deprecated, use $f .(x) instead." , $ f)
12
12
return ($ f). (x)
13
13
end
@@ -38,7 +38,7 @@ using NaNMath as nm
38
38
nm.sum([1., 2., NaN]) # result: 3.0
39
39
```
40
40
"""
41
- function sum {T<:AbstractFloat} (x:: AbstractArray{T} )
41
+ function sum (x:: AbstractArray{T} ) where T <: AbstractFloat
42
42
if length (x) == 0
43
43
result = zero (eltype (x))
44
44
else
@@ -75,7 +75,7 @@ using NaNMath as nm
75
75
nm.maximum([1., 2., NaN]) # result: 2.0
76
76
```
77
77
"""
78
- function maximum {T<:AbstractFloat} (x:: AbstractArray{T} )
78
+ function maximum (x:: AbstractArray{T} ) where T <: AbstractFloat
79
79
result = convert (eltype (x), NaN )
80
80
for i in x
81
81
if ! isnan (i)
@@ -102,7 +102,7 @@ using NaNMath as nm
102
102
nm.minimum([1., 2., NaN]) # result: 1.0
103
103
```
104
104
"""
105
- function minimum {T<:AbstractFloat} (x:: AbstractArray{T} )
105
+ function minimum (x:: AbstractArray{T} ) where T <: AbstractFloat
106
106
result = convert (eltype (x), NaN )
107
107
for i in x
108
108
if ! isnan (i)
@@ -129,7 +129,7 @@ using NaNMath as nm
129
129
nm.extrema([1., 2., NaN]) # result: 1.0, 2.0
130
130
```
131
131
"""
132
- function extrema {T<:AbstractFloat} (x:: AbstractArray{T} )
132
+ function extrema (x:: AbstractArray{T} ) where T <: AbstractFloat
133
133
resultmin, resultmax = convert (eltype (x), NaN ), convert (eltype (x), NaN )
134
134
for i in x
135
135
if ! isnan (i)
@@ -159,15 +159,15 @@ using NaNMath as nm
159
159
nm.mean([1., 2., NaN]) # result: 1.5
160
160
```
161
161
"""
162
- function mean {T<:AbstractFloat} (x:: AbstractArray{T} )
162
+ function mean (x:: AbstractArray{T} ) where T <: AbstractFloat
163
163
return mean_count (x)[1 ]
164
164
end
165
165
166
166
"""
167
167
Returns a tuple of the arithmetic mean of all elements in the array, ignoring NaN's,
168
168
and the number of non-NaN values in the array.
169
169
"""
170
- function mean_count {T<:AbstractFloat} (x:: AbstractArray{T} )
170
+ function mean_count (x:: AbstractArray{T} ) where T <: AbstractFloat
171
171
sum = convert (eltype (x), NaN )
172
172
count = 0
173
173
for i in x
@@ -204,7 +204,7 @@ using NaNMath as nm
204
204
nm.var([1., 2., NaN]) # result: 0.5
205
205
```
206
206
"""
207
- function var {T<:AbstractFloat} (x:: Vector{T} )
207
+ function var (x:: Vector{T} ) where T <: AbstractFloat
208
208
mean_val, n = mean_count (x)
209
209
if ! isnan (mean_val)
210
210
sum_square = zero (eltype (x))
@@ -238,7 +238,7 @@ using NaNMath as nm
238
238
nm.std([1., 2., NaN]) # result: 0.7071067811865476
239
239
```
240
240
"""
241
- function std {T<:AbstractFloat} (x:: Vector{T} )
241
+ function std (x:: Vector{T} ) where T <: AbstractFloat
242
242
return sqrt (var (x))
243
243
end
244
244
@@ -259,7 +259,7 @@ julia> NaNMath.min(1, 2)
259
259
1
260
260
```
261
261
"""
262
- min {T<:AbstractFloat} (x:: T , y:: T ) = ifelse ((y < x) | (signbit (y) > signbit (x)),
262
+ min (x:: T , y:: T ) where {T <: AbstractFloat } = ifelse ((y < x) | (signbit (y) > signbit (x)),
263
263
ifelse (isnan (y), x, y),
264
264
ifelse (isnan (x), y, x))
265
265
@@ -280,7 +280,7 @@ julia> NaNMath.max(1, 2)
280
280
2
281
281
```
282
282
"""
283
- max {T<:AbstractFloat} (x:: T , y:: T ) = ifelse ((y > x) | (signbit (y) < signbit (x)),
283
+ max (x:: T , y:: T ) where {T <: AbstractFloat } = ifelse ((y > x) | (signbit (y) < signbit (x)),
284
284
ifelse (isnan (y), x, y),
285
285
ifelse (isnan (x), y, x))
286
286
0 commit comments