|
2 | 2 | // |
3 | 3 | // minus.h: Rcpp R/C++ interface class library -- operator- |
4 | 4 | // |
5 | | -// Copyright (C) 2010 - 2011 Dirk Eddelbuettel and Romain Francois |
| 5 | +// Copyright (C) 2010 - 2025 Dirk Eddelbuettel and Romain Francois |
| 6 | +// Copyright (C) 2026 Dirk Eddelbuettel, Romain Francois and Iñaki Ucar |
6 | 7 | // |
7 | 8 | // This file is part of Rcpp. |
8 | 9 | // |
@@ -42,7 +43,7 @@ namespace sugar{ |
42 | 43 | STORAGE x = lhs[i] ; |
43 | 44 | if( Rcpp::traits::is_na<RTYPE>( x ) ) return x ; |
44 | 45 | STORAGE y = rhs[i] ; |
45 | | - return Rcpp::traits::is_na<RTYPE>( y ) ? y : ( x - y ) ; |
| 46 | + return Rcpp::traits::is_na<RTYPE>( y ) ? y : RCPP_SAFE_SUB(x, y); |
46 | 47 | } |
47 | 48 |
|
48 | 49 | inline R_xlen_t size() const { return lhs.size() ; } |
@@ -91,7 +92,7 @@ namespace sugar{ |
91 | 92 | inline STORAGE operator[]( R_xlen_t i ) const { |
92 | 93 | STORAGE y = rhs[i] ; |
93 | 94 | if( Rcpp::traits::is_na<RTYPE>( y ) ) return y ; |
94 | | - return lhs[i] - y ; |
| 95 | + return RCPP_SAFE_SUB(lhs[i], y); |
95 | 96 | } |
96 | 97 |
|
97 | 98 | inline R_xlen_t size() const { return lhs.size() ; } |
@@ -140,7 +141,7 @@ namespace sugar{ |
140 | 141 | inline STORAGE operator[]( R_xlen_t i ) const { |
141 | 142 | STORAGE x = lhs[i] ; |
142 | 143 | if( Rcpp::traits::is_na<RTYPE>( x ) ) return x ; |
143 | | - return x - rhs[i] ; |
| 144 | + return RCPP_SAFE_SUB(x, rhs[i]); |
144 | 145 | } |
145 | 146 |
|
146 | 147 | inline R_xlen_t size() const { return lhs.size() ; } |
@@ -188,7 +189,7 @@ namespace sugar{ |
188 | 189 | lhs(lhs_.get_ref()), rhs(rhs_.get_ref()) {} |
189 | 190 |
|
190 | 191 | inline STORAGE operator[]( R_xlen_t i ) const { |
191 | | - return lhs[i] - rhs[i] ; |
| 192 | + return RCPP_SAFE_SUB(lhs[i], rhs[i]); |
192 | 193 | } |
193 | 194 |
|
194 | 195 | inline R_xlen_t size() const { return lhs.size() ; } |
@@ -238,7 +239,7 @@ namespace sugar{ |
238 | 239 | inline STORAGE operator[]( R_xlen_t i ) const { |
239 | 240 | if( rhs_na ) return rhs ; |
240 | 241 | STORAGE x = lhs[i] ; |
241 | | - return Rcpp::traits::is_na<RTYPE>(x) ? x : (x - rhs) ; |
| 242 | + return Rcpp::traits::is_na<RTYPE>(x) ? x : RCPP_SAFE_SUB(x, rhs); |
242 | 243 | } |
243 | 244 |
|
244 | 245 | inline R_xlen_t size() const { return lhs.size() ; } |
@@ -284,7 +285,7 @@ namespace sugar{ |
284 | 285 | inline STORAGE operator[]( R_xlen_t i ) const { |
285 | 286 | if( rhs_na ) return rhs ; |
286 | 287 | STORAGE x = lhs[i] ; |
287 | | - return Rcpp::traits::is_na<RTYPE>(x) ? x : (x - rhs) ; |
| 288 | + return Rcpp::traits::is_na<RTYPE>(x) ? x : RCPP_SAFE_SUB(x, rhs); |
288 | 289 | } |
289 | 290 |
|
290 | 291 | inline R_xlen_t size() const { return lhs.size() ; } |
@@ -333,7 +334,7 @@ namespace sugar{ |
333 | 334 |
|
334 | 335 | inline STORAGE operator[]( R_xlen_t i ) const { |
335 | 336 | if( lhs_na ) return lhs ; |
336 | | - return lhs - rhs[i] ; |
| 337 | + return RCPP_SAFE_SUB(lhs, rhs[i]); |
337 | 338 | } |
338 | 339 | inline R_xlen_t size() const { return rhs.size() ; } |
339 | 340 |
|
@@ -377,7 +378,7 @@ namespace sugar{ |
377 | 378 |
|
378 | 379 | inline STORAGE operator[]( R_xlen_t i ) const { |
379 | 380 | if( lhs_na ) return lhs ; |
380 | | - return lhs - rhs[i] ; |
| 381 | + return RCPP_SAFE_SUB(lhs, rhs[i]); |
381 | 382 | } |
382 | 383 |
|
383 | 384 | inline R_xlen_t size() const { return rhs.size() ; } |
|
0 commit comments