@@ -33,42 +33,42 @@ rawone(v) = reinterpret(one(v))
3333
3434# Conversions
3535convert {T<:Unsigned,f} (:: Type{Normed{T,f}} , x:: Normed{T,f} ) = x
36- convert {T1<:Unsigned,T2<:Unsigned,f} (:: Type{Normed{T1,f}} , x:: Normed{T2,f} ) = Normed {T1,f} (convert (T1, x. i), 0 )
37- function convert {T<:Unsigned,T2<:Unsigned,f} (:: Type{Normed{T,f}} , x:: Normed{T2} )
36+ @inline convert {T1<:Unsigned,T2<:Unsigned,f} (:: Type{Normed{T1,f}} , x:: Normed{T2,f} ) = Normed {T1,f} (convert (T1, x. i), 0 )
37+ @inline function convert {T<:Unsigned,T2<:Unsigned,f} (:: Type{Normed{T,f}} , x:: Normed{T2} )
3838 U = Normed{T,f}
3939 y = round ((rawone (U)/ rawone (x))* reinterpret (x))
4040 (0 <= y) & (y <= typemax (T)) || throw_converterror (U, x)
4141 reinterpret (U, _unsafe_trunc (T, y))
4242end
43- convert {U<:Normed} (:: Type{U} , x:: Real ) = _convert (U, rawtype (U), x)
43+ @inline convert {U<:Normed} (:: Type{U} , x:: Real ) = _convert (U, rawtype (U), x)
4444
45- convert (:: Type{N0f16} , x:: N0f8 ) = reinterpret (N0f16, convert (UInt16, 0x0101 * reinterpret (x)))
46- function _convert {U<:Normed,T} (:: Type{U} , :: Type{T} , x)
47- y = round (widen1 (rawone (U))* x)
45+ @inline convert (:: Type{N0f16} , x:: N0f8 ) = reinterpret (N0f16, convert (UInt16, 0x0101 * reinterpret (x)))
46+ @inline function _convert {U<:Normed,T} (:: Type{U} , :: Type{T} , x)
47+ y = @fastmath round (widen1 (rawone (U))* x)
4848 (0 <= y) & (y <= typemax (T)) || throw_converterror (U, x)
4949 U (_unsafe_trunc (T, y), 0 )
5050end
51- function _convert {U<:Normed} (:: Type{U} , :: Type{UInt128} , x)
51+ @inline function _convert {U<:Normed} (:: Type{U} , :: Type{UInt128} , x)
5252 y = round (rawone (U)* x) # for UInt128, we can't widen
5353 (0 <= y) & (y <= typemax (UInt128)) & (x <= Float64 (typemax (U))) || throw_converterror (U, x)
5454 U (_unsafe_trunc (UInt128, y), 0 )
5555end
5656
5757rem {T<:Normed} (x:: T , :: Type{T} ) = x
58- rem {T<:Normed} (x:: Normed , :: Type{T} ) = reinterpret (T, _unsafe_trunc (rawtype (T), round ((rawone (T)/ rawone (x))* reinterpret (x))))
59- rem {T<:Normed} (x:: Real , :: Type{T} ) = reinterpret (T, _unsafe_trunc (rawtype (T), round (rawone (T)* x)))
58+ @inline rem {T<:Normed} (x:: Normed , :: Type{T} ) = reinterpret (T, _unsafe_trunc (rawtype (T), round ((rawone (T)/ rawone (x))* reinterpret (x))))
59+ @inline rem {T<:Normed} (x:: Real , :: Type{T} ) = reinterpret (T, _unsafe_trunc (rawtype (T), round (rawone (T)* x)))
6060
6161# convert(::Type{AbstractFloat}, x::Normed) = convert(floattype(x), x)
6262float (x:: Normed ) = convert (floattype (x), x)
6363
6464convert (:: Type{BigFloat} , x:: Normed ) = reinterpret (x)* (1 / BigFloat (rawone (x)))
65- function convert {T<:AbstractFloat} (:: Type{T} , x:: Normed )
66- y = reinterpret (x)* (one (rawtype (x))/ convert (T, rawone (x)))
65+ @inline function convert {T<:AbstractFloat} (:: Type{T} , x:: Normed )
66+ y = @fastmath reinterpret (x)* (one (rawtype (x))/ convert (T, rawone (x)))
6767 convert (T, y) # needed for types like Float16 which promote arithmetic to Float32
6868end
6969convert (:: Type{Bool} , x:: Normed ) = x == zero (x) ? false : true
70- convert {T<:Integer} (:: Type{T} , x:: Normed ) = convert (T, x* (1 / one (T)))
71- convert {Ti<:Integer} (:: Type{Rational{Ti}} , x:: Normed ) = convert (Ti, reinterpret (x))// convert (Ti, rawone (x))
70+ @inline convert {T<:Integer} (:: Type{T} , x:: Normed ) = convert (T, x* (1 / one (T)))
71+ @inline convert {Ti<:Integer} (:: Type{Rational{Ti}} , x:: Normed ) = convert (Ti, reinterpret (x))// convert (Ti, rawone (x))
7272convert (:: Type{Rational} , x:: Normed ) = reinterpret (x)// rawone (x)
7373
7474# Traits
0 commit comments