@@ -752,6 +752,29 @@ fpinttype(::Type{Float16}) = UInt16
752
752
# maximum float exponent without bias
753
753
@pure exponent_raw_max {T<:AbstractFloat} (:: Type{T} ) = Int (exponent_mask (T) >> significand_bits (T))
754
754
755
+ # # TwicePrecision utilities
756
+ # The numeric constants are half the number of bits in the mantissa
757
+ for (F, T, n) in ((Float16, UInt16, 5 ), (Float32, UInt32, 12 ), (Float64, UInt64, 26 ))
758
+ @eval begin
759
+ function truncbits (x:: $F , nb)
760
+ @_inline_meta
761
+ truncmask (x, typemax ($ T) << nb)
762
+ end
763
+ function truncmask (x:: $F , mask)
764
+ @_inline_meta
765
+ reinterpret ($ F, mask & reinterpret ($ T, x))
766
+ end
767
+ function splitprec (x:: $F )
768
+ @_inline_meta
769
+ hi = truncmask (x, typemax ($ T) << $ n)
770
+ hi, x- hi
771
+ end
772
+ end
773
+ end
774
+
775
+ truncbits (x, nb) = x
776
+ truncmask (x, mask) = x
777
+
755
778
# # Array operations on floating point numbers ##
756
779
757
780
float {T<:AbstractFloat} (A:: AbstractArray{T} ) = A
@@ -763,26 +786,19 @@ function float{T}(A::AbstractArray{T})
763
786
convert (AbstractArray{typeof (float (zero (T)))}, A)
764
787
end
765
788
766
- for fn in (:float ,)
767
- @eval begin
768
- $ fn (r:: StepRange ) = $ fn (r. start): $ fn (r. step): $ fn (last (r))
769
- $ fn (r:: UnitRange ) = $ fn (r. start): $ fn (last (r))
770
- $ fn (r:: FloatRange ) = FloatRange ($ fn (r. start), $ fn (r. step), r. len, $ fn (r. divisor))
771
- function $fn (r:: LinSpace )
772
- new_len = $ fn (r. len)
773
- new_len == r. len || error (string (r, " : too long for " , $ fn))
774
- LinSpace ($ fn (r. start), $ fn (r. stop), new_len, $ fn (r. divisor))
775
- end
776
- end
789
+ float (r:: StepRange ) = float (r. start): float (r. step): float (last (r))
790
+ float (r:: UnitRange ) = float (r. start): float (last (r))
791
+ float (r:: StepRangeLen ) = StepRangeLen (float (r. ref), float (r. step), length (r), r. offset)
792
+ function float (r:: LinSpace )
793
+ LinSpace (float (r. start), float (r. stop), length (r))
777
794
end
778
795
779
796
# big, broadcast over arrays
780
797
# TODO : do the definitions below primarily pertaining to integers belong in float.jl?
781
798
function big end # no prior definitions of big in sysimg.jl, necessitating this
782
799
broadcast (:: typeof (big), r:: UnitRange ) = big (r. start): big (last (r))
783
800
broadcast (:: typeof (big), r:: StepRange ) = big (r. start): big (r. step): big (last (r))
784
- broadcast (:: typeof (big), r:: FloatRange ) = FloatRange (big (r. start ), big (r. step), r . len, big (r . divisor) )
801
+ broadcast (:: typeof (big), r:: StepRangeLen ) = StepRangeLen (big (r. ref ), big (r. step), length (r), r . offset )
785
802
function broadcast (:: typeof (big), r:: LinSpace )
786
- big (r. len) == r. len || throw (ArgumentError (string (r, " : too long for " , big)))
787
- LinSpace (big (r. start), big (r. stop), big (r. len), big (r. divisor))
803
+ LinSpace (big (r. start), big (r. stop), length (r))
788
804
end
0 commit comments