|
2 | 2 | // |
3 | 3 | // times.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 | // |
@@ -43,7 +44,7 @@ namespace sugar{ |
43 | 44 | STORAGE lhs_ = lhs[i] ; |
44 | 45 | if( traits::is_na<RTYPE>(lhs_) ) return lhs_ ; |
45 | 46 | STORAGE rhs_ = rhs[i] ; |
46 | | - return traits::is_na<RTYPE>(rhs_) ? rhs_ : (lhs_ * rhs_) ; |
| 47 | + return traits::is_na<RTYPE>(rhs_) ? rhs_ : RCPP_SAFE_MUL(lhs_, rhs_) ; |
47 | 48 | } |
48 | 49 |
|
49 | 50 | inline R_xlen_t size() const { return lhs.size() ; } |
@@ -96,7 +97,7 @@ namespace sugar{ |
96 | 97 | inline STORAGE operator[]( R_xlen_t i ) const { |
97 | 98 | STORAGE rhs_ = rhs[i] ; |
98 | 99 | if( traits::is_na<RTYPE>(rhs_) ) return rhs_ ; |
99 | | - return lhs[i] * rhs_ ; |
| 100 | + return RCPP_SAFE_MUL(lhs[i], rhs_); |
100 | 101 | } |
101 | 102 |
|
102 | 103 | inline R_xlen_t size() const { return lhs.size() ; } |
@@ -148,7 +149,7 @@ namespace sugar{ |
148 | 149 | inline STORAGE operator[]( R_xlen_t i ) const { |
149 | 150 | STORAGE lhs_ = lhs[i] ; |
150 | 151 | if( traits::is_na<RTYPE>(lhs_) ) return lhs_ ; |
151 | | - return lhs_ * rhs[i] ; |
| 152 | + return RCPP_SAFE_MUL(lhs_, rhs[i]); |
152 | 153 | } |
153 | 154 |
|
154 | 155 | inline R_xlen_t size() const { return lhs.size() ; } |
@@ -197,7 +198,7 @@ namespace sugar{ |
197 | 198 | lhs(lhs_.get_ref()), rhs(rhs_.get_ref()){} |
198 | 199 |
|
199 | 200 | inline STORAGE operator[]( R_xlen_t i ) const { |
200 | | - return lhs[i] * rhs[i] ; |
| 201 | + return RCPP_SAFE_MUL(lhs[i], rhs[i]); |
201 | 202 | } |
202 | 203 |
|
203 | 204 | inline R_xlen_t size() const { return lhs.size() ; } |
@@ -247,7 +248,7 @@ namespace sugar{ |
247 | 248 | inline STORAGE operator[]( R_xlen_t i ) const { |
248 | 249 | if( rhs_na ) return rhs ; |
249 | 250 | STORAGE x = lhs[i] ; |
250 | | - return Rcpp::traits::is_na<RTYPE>(x) ? x : (x * rhs) ; |
| 251 | + return Rcpp::traits::is_na<RTYPE>(x) ? x : RCPP_SAFE_MUL(x, rhs) ; |
251 | 252 | } |
252 | 253 |
|
253 | 254 | inline R_xlen_t size() const { return lhs.size() ; } |
@@ -293,7 +294,7 @@ namespace sugar{ |
293 | 294 | lhs(lhs_.get_ref()), rhs(rhs_), rhs_na( Rcpp::traits::is_na<RTYPE>(rhs_) ) {} |
294 | 295 |
|
295 | 296 | inline STORAGE operator[]( R_xlen_t i ) const { |
296 | | - return rhs_na ? rhs : (rhs * lhs[i] ) ; |
| 297 | + return rhs_na ? rhs : (rhs * lhs[i]); |
297 | 298 | } |
298 | 299 |
|
299 | 300 | inline R_xlen_t size() const { return lhs.size() ; } |
@@ -345,7 +346,7 @@ namespace sugar{ |
345 | 346 |
|
346 | 347 | inline STORAGE operator[]( R_xlen_t i ) const { |
347 | 348 | STORAGE x = lhs[i] ; |
348 | | - return Rcpp::traits::is_na<RTYPE>(x) ? x : (x * rhs) ; |
| 349 | + return Rcpp::traits::is_na<RTYPE>(x) ? x : RCPP_SAFE_MUL(x, rhs); |
349 | 350 | } |
350 | 351 |
|
351 | 352 | inline R_xlen_t size() const { return lhs.size() ; } |
@@ -391,7 +392,7 @@ namespace sugar{ |
391 | 392 | lhs(lhs_.get_ref()), rhs(rhs_) {} |
392 | 393 |
|
393 | 394 | inline STORAGE operator[]( R_xlen_t i ) const { |
394 | | - return rhs * lhs[i] ; |
| 395 | + return RCPP_SAFE_MUL(rhs, lhs[i]); |
395 | 396 | } |
396 | 397 |
|
397 | 398 | inline R_xlen_t size() const { return lhs.size() ; } |
|
0 commit comments