Skip to content

Commit

Permalink
Under some compilers, cmath headers do not include the round() functi…
Browse files Browse the repository at this point in the history
…on. Implement a local version.
  • Loading branch information
tskisner committed Nov 1, 2019
1 parent 7aa399a commit 7a037d8
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
8 changes: 8 additions & 0 deletions src/libaatm/include/ATMCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,12 @@
#define ATM_NAMESPACE atm
#endif

#include <cmath>

ATM_NAMESPACE_BEGIN

double atm_round(double number);

ATM_NAMESPACE_END

#endif /*!_ATM_COMMON_H_*/
7 changes: 6 additions & 1 deletion src/libaatm/src/ATMRefractiveIndex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ using std::cout;

ATM_NAMESPACE_BEGIN

// round function
double atm_round(double number) {
return number < 0.0 ? ceil(number - 0.5) : floor(number + 0.5);
}

// Constructors


Expand Down Expand Up @@ -176,7 +181,7 @@ ATM_NAMESPACE_BEGIN
if(nu<1.0){
vp=0;
}else{
vp = (int) round((nu+1.0)/2.0);
vp = (int) atm_round((nu+1.0)/2.0);
vp=vp-1;
}
return vp;
Expand Down
6 changes: 3 additions & 3 deletions src/libaatm/src/ATMRefractiveIndexProfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,14 +374,14 @@ void RefractiveIndexProfile::mkRefractiveIndexProfile()
if (v_chanFreq_.size()>1){
if(nc==0){
width = fabs(v_chanFreq_[nc+1]-v_chanFreq_[nc])*1e-9; // width en GHz para ATM
npoints=(size_t)round(width*100); // One point every 10 MHz
npoints=(size_t)atm_round(width*100); // One point every 10 MHz
}else{
if(nc==v_chanFreq_.size()-1){
width = fabs(v_chanFreq_[nc]-v_chanFreq_[nc-1])*1e-9; // width en GHz para ATM
npoints=(size_t)round(width*100); // One point every 10 MHz
npoints=(size_t)atm_round(width*100); // One point every 10 MHz
}else{
width = fabs((v_chanFreq_[nc+1]-v_chanFreq_[nc-1])/2.0)*1e-9; // width en GHz para ATM
npoints=(size_t)round(width*100); // One point every 10 MHz
npoints=(size_t)atm_round(width*100); // One point every 10 MHz
}
}
}else{
Expand Down

0 comments on commit 7a037d8

Please sign in to comment.