Changeset 764 for cpp/frams/genetics
 Timestamp:
 03/28/18 02:29:34 (3 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

cpp/frams/genetics/oper_fx.cpp
r758 r764 147 147 { 148 148 double result = mutateCreepNoLimit(type, current, stddev, limit_precision_3digits); 149 //TODO consider that when boundary is touched (reflect+absorb below), the requested precision (3 digits) may change. Is it good or bad? 150 //reflect: 151 if (result > mx) result = mx  (result  mx); else 152 if (result < mn) result = mn + (mn  result); 153 //absorb (just in case 'result' exceeded the allowed range so much): 154 if (result > mx) result = mx; else 155 if (result < mn) result = mn; 149 if (result<mn  result>mx) //exceeds boundary, so bring to the allowed range 150 { 151 //reflect: 152 if (result > mx) result = mx  (result  mx); else 153 if (result < mn) result = mn + (mn  result); 154 //wrap (just in case 'result' exceeded the allowed range so much that after reflection above it exceeded the other boundary): 155 if (result > mx) result = mn + fmod(result  mx, mx  mn); else 156 if (result < mn) result = mn + fmod(mn  result, mx  mn); 157 if (limit_precision_3digits) 158 { 159 //reflect and wrap above may have changed the (limited) precision, so try to round again (maybe unnecessarily, because we don't know if reflect+wrap above were triggered) 160 double result_try = floor(result * 1000 + 0.5) / 1000.0; //round 161 if (mn <= result_try && result_try <= mx) result = result_try; //after rounding still witin allowed range, so keep rounded value 162 } 163 } 156 164 return result; 157 165 }
Note: See TracChangeset
for help on using the changeset viewer.