1+ #[ cfg( has_f128) ]
2+ use core:: f128;
13#[ cfg( has_f16) ]
24use core:: f16;
35use core:: mem:: size_of;
@@ -134,6 +136,15 @@ pub trait ToPrimitive {
134136None =>self . to_u64 ( ) . as_ref ( ) . and_then ( ToPrimitive :: to_f64) ,
135137}
136138}
139+
140+ /// Converts the value of `self` to an `f128`. Overflows may map to positive
141+ /// or negative inifinity, otherwise `None` is returned if the value cannot
142+ /// be represented by an `f128`.
143+ #[ cfg( has_f128) ]
144+ #[ inline]
145+ fn to_f128 ( & self ) ->Option < f128 > {
146+ self . to_f64 ( ) . as_ref ( ) . and_then ( ToPrimitive :: to_f128)
147+ }
137148}
138149
139150macro_rules! impl_to_primitive_int_to_int{
@@ -201,6 +212,11 @@ macro_rules! impl_to_primitive_int {
201212fn to_f64( & self ) ->Option <f64 >{
202213Some ( * self as f64 )
203214}
215+ #[ cfg( has_f128) ]
216+ #[ inline]
217+ fn to_f128( & self ) ->Option <f128>{
218+ Some ( * self as f128)
219+ }
204220}
205221} ;
206222}
@@ -276,6 +292,11 @@ macro_rules! impl_to_primitive_uint {
276292fn to_f64( & self ) ->Option <f64 >{
277293Some ( * self as f64 )
278294}
295+ #[ cfg( has_f128) ]
296+ #[ inline]
297+ fn to_f128( & self ) ->Option <f128>{
298+ Some ( * self as f128)
299+ }
279300}
280301} ;
281302}
@@ -390,6 +411,8 @@ macro_rules! impl_to_primitive_float {
390411fn to_f16 -> f16;
391412fn to_f32 ->f32 ;
392413fn to_f64 ->f64 ;
414+ #[ cfg( has_f128) ]
415+ fn to_f128 -> f128;
393416}
394417}
395418} ;
@@ -399,6 +422,8 @@ macro_rules! impl_to_primitive_float {
399422impl_to_primitive_float ! ( f16) ;
400423impl_to_primitive_float ! ( f32 ) ;
401424impl_to_primitive_float ! ( f64 ) ;
425+ #[ cfg( has_f128) ]
426+ impl_to_primitive_float ! ( f128) ;
402427
403428/// A generic trait for converting a number to a value.
404429///
@@ -523,6 +548,14 @@ pub trait FromPrimitive: Sized {
523548None => n. to_u64 ( ) . and_then ( FromPrimitive :: from_u64) ,
524549}
525550}
551+
552+ /// Converts a `f128` to return an optional value of this type. If the
553+ /// value cannot be represented by this type, then `None` is returned.
554+ #[ cfg( has_f128) ]
555+ #[ inline]
556+ fn from_f128 ( n : f128 ) ->Option < Self > {
557+ FromPrimitive :: from_f64 ( nas f64 )
558+ }
526559}
527560
528561macro_rules! impl_from_primitive{
@@ -592,6 +625,11 @@ macro_rules! impl_from_primitive {
592625fn from_f64( n: f64 ) ->Option <$T>{
593626 n. $to_ty( )
594627}
628+ #[ cfg( has_f128) ]
629+ #[ inline]
630+ fn from_f128( n: f128) ->Option <$T>{
631+ n. $to_ty( )
632+ }
595633}
596634} ;
597635}
@@ -612,6 +650,8 @@ impl_from_primitive!(u128, to_u128);
612650impl_from_primitive ! ( f16, to_f16) ;
613651impl_from_primitive ! ( f32 , to_f32) ;
614652impl_from_primitive ! ( f64 , to_f64) ;
653+ #[ cfg( has_f128) ]
654+ impl_from_primitive ! ( f128, to_f128) ;
615655
616656macro_rules! impl_to_primitive_wrapping{
617657( $( $( #[ $cfg: meta] ) * fn $method: ident -> $i: ident; ) * ) =>{ $(
@@ -643,6 +683,8 @@ impl<T: ToPrimitive> ToPrimitive for Wrapping<T> {
643683fn to_f16 -> f16;
644684fn to_f32 ->f32 ;
645685fn to_f64 ->f64 ;
686+ #[ cfg( has_f128) ]
687+ fn to_f128 -> f128;
646688}
647689}
648690
@@ -676,6 +718,8 @@ impl<T: FromPrimitive> FromPrimitive for Wrapping<T> {
676718fn from_f16( f16) ;
677719fn from_f32( f32 ) ;
678720fn from_f64( f64 ) ;
721+ #[ cfg( has_f128) ]
722+ fn from_f128( f128) ;
679723}
680724}
681725
@@ -741,6 +785,8 @@ impl_num_cast!(isize, to_isize);
741785impl_num_cast ! ( f16, to_f16) ;
742786impl_num_cast ! ( f32 , to_f32) ;
743787impl_num_cast ! ( f64 , to_f64) ;
788+ #[ cfg( has_f128) ]
789+ impl_num_cast ! ( f128, to_f128) ;
744790
745791impl < T : NumCast > NumCast for Wrapping < T > {
746792fn from < U : ToPrimitive > ( n : U ) ->Option < Self > {
@@ -799,21 +845,23 @@ macro_rules! impl_as_primitive {
799845} ;
800846}
801847
802- impl_as_primitive ! ( u8 =>{ char , #[ cfg( has_f16) ] f16, f32 , f64 } ) ;
803- impl_as_primitive ! ( i8 =>{ #[ cfg( has_f16) ] f16, f32 , f64 } ) ;
804- impl_as_primitive ! ( u16 =>{ #[ cfg( has_f16) ] f16, f32 , f64 } ) ;
805- impl_as_primitive ! ( i16 =>{ #[ cfg( has_f16) ] f16, f32 , f64 } ) ;
806- impl_as_primitive ! ( u32 =>{ #[ cfg( has_f16) ] f16, f32 , f64 } ) ;
807- impl_as_primitive ! ( i32 =>{ #[ cfg( has_f16) ] f16, f32 , f64 } ) ;
808- impl_as_primitive ! ( u64 =>{ #[ cfg( has_f16) ] f16, f32 , f64 } ) ;
809- impl_as_primitive ! ( i64 =>{ #[ cfg( has_f16) ] f16, f32 , f64 } ) ;
810- impl_as_primitive ! ( u128 =>{ #[ cfg( has_f16) ] f16, f32 , f64 } ) ;
811- impl_as_primitive ! ( i128 =>{ #[ cfg( has_f16) ] f16, f32 , f64 } ) ;
812- impl_as_primitive ! ( usize =>{ #[ cfg( has_f16) ] f16, f32 , f64 } ) ;
813- impl_as_primitive ! ( isize =>{ #[ cfg( has_f16) ] f16, f32 , f64 } ) ;
848+ impl_as_primitive ! ( u8 =>{ char , #[ cfg( has_f16) ] f16, f32 , f64 , # [ cfg ( has_f128 ) ] f128 } ) ;
849+ impl_as_primitive ! ( i8 =>{ #[ cfg( has_f16) ] f16, f32 , f64 , # [ cfg ( has_f128 ) ] f128 } ) ;
850+ impl_as_primitive ! ( u16 =>{ #[ cfg( has_f16) ] f16, f32 , f64 , # [ cfg ( has_f128 ) ] f128 } ) ;
851+ impl_as_primitive ! ( i16 =>{ #[ cfg( has_f16) ] f16, f32 , f64 , # [ cfg ( has_f128 ) ] f128 } ) ;
852+ impl_as_primitive ! ( u32 =>{ #[ cfg( has_f16) ] f16, f32 , f64 , # [ cfg ( has_f128 ) ] f128 } ) ;
853+ impl_as_primitive ! ( i32 =>{ #[ cfg( has_f16) ] f16, f32 , f64 , # [ cfg ( has_f128 ) ] f128 } ) ;
854+ impl_as_primitive ! ( u64 =>{ #[ cfg( has_f16) ] f16, f32 , f64 , # [ cfg ( has_f128 ) ] f128 } ) ;
855+ impl_as_primitive ! ( i64 =>{ #[ cfg( has_f16) ] f16, f32 , f64 , # [ cfg ( has_f128 ) ] f128 } ) ;
856+ impl_as_primitive ! ( u128 =>{ #[ cfg( has_f16) ] f16, f32 , f64 , # [ cfg ( has_f128 ) ] f128 } ) ;
857+ impl_as_primitive ! ( i128 =>{ #[ cfg( has_f16) ] f16, f32 , f64 , # [ cfg ( has_f128 ) ] f128 } ) ;
858+ impl_as_primitive ! ( usize =>{ #[ cfg( has_f16) ] f16, f32 , f64 , # [ cfg ( has_f128 ) ] f128 } ) ;
859+ impl_as_primitive ! ( isize =>{ #[ cfg( has_f16) ] f16, f32 , f64 , # [ cfg ( has_f128 ) ] f128 } ) ;
814860#[ cfg( has_f16) ]
815- impl_as_primitive ! ( f16 =>{ f16, f32 , f64 } ) ;
816- impl_as_primitive ! ( f32 =>{ #[ cfg( has_f16) ] f16, f32 , f64 } ) ;
817- impl_as_primitive ! ( f64 =>{ #[ cfg( has_f16) ] f16, f32 , f64 } ) ;
861+ impl_as_primitive ! ( f16 =>{ f16, f32 , f64 , #[ cfg( has_f128) ] f128} ) ;
862+ impl_as_primitive ! ( f32 =>{ #[ cfg( has_f16) ] f16, f32 , f64 , #[ cfg( has_f128) ] f128} ) ;
863+ impl_as_primitive ! ( f64 =>{ #[ cfg( has_f16) ] f16, f32 , f64 , #[ cfg( has_f128) ] f128} ) ;
864+ #[ cfg( has_f128) ]
865+ impl_as_primitive ! ( f128 =>{ #[ cfg( has_f16) ] f16, f32 , f64 , f128} ) ;
818866impl_as_primitive ! ( char =>{ char } ) ;
819867impl_as_primitive ! ( bool =>{ } ) ;