Skip to content

Commit 7a037d8

Browse files
committed
Under some compilers, cmath headers do not include the round() function. Implement a local version.
1 parent 7aa399a commit 7a037d8

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

src/libaatm/include/ATMCommon.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,12 @@
3939
#define ATM_NAMESPACE atm
4040
#endif
4141

42+
#include <cmath>
43+
44+
ATM_NAMESPACE_BEGIN
45+
46+
double atm_round(double number);
47+
48+
ATM_NAMESPACE_END
49+
4250
#endif /*!_ATM_COMMON_H_*/

src/libaatm/src/ATMRefractiveIndex.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ using std::cout;
3636

3737
ATM_NAMESPACE_BEGIN
3838

39+
// round function
40+
double atm_round(double number) {
41+
return number < 0.0 ? ceil(number - 0.5) : floor(number + 0.5);
42+
}
43+
3944
// Constructors
4045

4146

@@ -176,7 +181,7 @@ ATM_NAMESPACE_BEGIN
176181
if(nu<1.0){
177182
vp=0;
178183
}else{
179-
vp = (int) round((nu+1.0)/2.0);
184+
vp = (int) atm_round((nu+1.0)/2.0);
180185
vp=vp-1;
181186
}
182187
return vp;

src/libaatm/src/ATMRefractiveIndexProfile.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -374,14 +374,14 @@ void RefractiveIndexProfile::mkRefractiveIndexProfile()
374374
if (v_chanFreq_.size()>1){
375375
if(nc==0){
376376
width = fabs(v_chanFreq_[nc+1]-v_chanFreq_[nc])*1e-9; // width en GHz para ATM
377-
npoints=(size_t)round(width*100); // One point every 10 MHz
377+
npoints=(size_t)atm_round(width*100); // One point every 10 MHz
378378
}else{
379379
if(nc==v_chanFreq_.size()-1){
380380
width = fabs(v_chanFreq_[nc]-v_chanFreq_[nc-1])*1e-9; // width en GHz para ATM
381-
npoints=(size_t)round(width*100); // One point every 10 MHz
381+
npoints=(size_t)atm_round(width*100); // One point every 10 MHz
382382
}else{
383383
width = fabs((v_chanFreq_[nc+1]-v_chanFreq_[nc-1])/2.0)*1e-9; // width en GHz para ATM
384-
npoints=(size_t)round(width*100); // One point every 10 MHz
384+
npoints=(size_t)atm_round(width*100); // One point every 10 MHz
385385
}
386386
}
387387
}else{

0 commit comments

Comments
 (0)