@@ -39,19 +39,9 @@ trait Addo: AddSub
39
39
where
40
40
<Self as Int >:: UnsignedInt : UAddSub ,
41
41
{
42
- fn addo ( self , other : Self , overflow : & mut i32 ) -> Self {
43
- * overflow = 0 ;
44
- let result = AddSub :: add ( self , other) ;
45
- if other >= Self :: ZERO {
46
- if result < self {
47
- * overflow = 1 ;
48
- }
49
- } else {
50
- if result >= self {
51
- * overflow = 1 ;
52
- }
53
- }
54
- result
42
+ fn addo ( self , other : Self ) -> ( Self , bool ) {
43
+ let sum = AddSub :: add ( self , other) ;
44
+ ( sum, ( other < Self :: ZERO ) != ( sum < self ) )
55
45
}
56
46
}
57
47
@@ -62,19 +52,9 @@ trait Subo: AddSub
62
52
where
63
53
<Self as Int >:: UnsignedInt : UAddSub ,
64
54
{
65
- fn subo ( self , other : Self , overflow : & mut i32 ) -> Self {
66
- * overflow = 0 ;
67
- let result = AddSub :: sub ( self , other) ;
68
- if other >= Self :: ZERO {
69
- if result > self {
70
- * overflow = 1 ;
71
- }
72
- } else {
73
- if result <= self {
74
- * overflow = 1 ;
75
- }
76
- }
77
- result
55
+ fn subo ( self , other : Self ) -> ( Self , bool ) {
56
+ let sum = AddSub :: sub ( self , other) ;
57
+ ( sum, ( other < Self :: ZERO ) != ( self < sum) )
78
58
}
79
59
}
80
60
@@ -83,43 +63,34 @@ impl Subo for u128 {}
83
63
84
64
intrinsics ! {
85
65
pub extern "C" fn __rust_i128_add( a: i128 , b: i128 ) -> i128 {
86
- __rust_u128_add ( a as _ , b as _ ) as _
66
+ AddSub :: add ( a , b )
87
67
}
88
68
89
69
pub extern "C" fn __rust_i128_addo( a: i128 , b: i128 ) -> ( i128 , bool ) {
90
- let mut oflow = 0 ;
91
- let r = a. addo( b, & mut oflow) ;
92
- ( r, oflow != 0 )
70
+ a. addo( b)
93
71
}
94
72
95
73
pub extern "C" fn __rust_u128_add( a: u128 , b: u128 ) -> u128 {
96
- a . add( b)
74
+ AddSub :: add( a , b)
97
75
}
98
76
99
77
pub extern "C" fn __rust_u128_addo( a: u128 , b: u128 ) -> ( u128 , bool ) {
100
- let mut oflow = 0 ;
101
- let r = a. addo( b, & mut oflow) ;
102
- ( r, oflow != 0 )
78
+ a. addo( b)
103
79
}
104
80
105
-
106
81
pub extern "C" fn __rust_i128_sub( a: i128 , b: i128 ) -> i128 {
107
- __rust_u128_sub ( a as _ , b as _ ) as _
82
+ AddSub :: sub ( a , b )
108
83
}
109
84
110
85
pub extern "C" fn __rust_i128_subo( a: i128 , b: i128 ) -> ( i128 , bool ) {
111
- let mut oflow = 0 ;
112
- let r = a. subo( b, & mut oflow) ;
113
- ( r, oflow != 0 )
86
+ a. subo( b)
114
87
}
115
88
116
89
pub extern "C" fn __rust_u128_sub( a: u128 , b: u128 ) -> u128 {
117
- a . sub( b)
90
+ AddSub :: sub( a , b)
118
91
}
119
92
120
93
pub extern "C" fn __rust_u128_subo( a: u128 , b: u128 ) -> ( u128 , bool ) {
121
- let mut oflow = 0 ;
122
- let r = a. subo( b, & mut oflow) ;
123
- ( r, oflow != 0 )
94
+ a. subo( b)
124
95
}
125
96
}
0 commit comments