- Timestamp:
- 06/22/23 03:27:28 (18 months ago)
- Location:
- cpp
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
cpp/common/nonstd_math.h
r1053 r1253 38 38 std::string doubleToString(double x, int precision); 39 39 double round(const double x, const int precision); 40 static inline void clipNegativeZeroIfNeeded(double& value, const double range_low) 41 { 42 if (value == 0.0 && range_low == 0.0) // if we have range_low==0.0 and we get value==-0.0 (which is ==0.0) 43 value = 0.0; //turn -0.0 to 0.0 so that it does not look like exceeding the allowed range (even though -0.0==0.0). This code unnecessarily also "overwrites" value==0.0 with 0.0, but it is faster and simpler than additionally checking std::signbit(value) just to distinguish -0.0 from 0.0. 44 //these conditions are not intended for range_low==-0.0, as we assume nobody would define allowed ranges using -0.0. 45 } 40 46 41 47 -
cpp/frams/param/param.cpp
r1217 r1253 11 11 #include <frams/util/sstringutils.h> 12 12 #include <common/virtfile/stringfile.h> 13 #include <common/nonstd_math.h> 13 14 14 15 #ifdef _DEBUG … … 358 359 { 359 360 SString ret = getName(); 360 if (ret.size() >0) //name might be unavailable, happened in GenMan sub-Params361 if (ret.size() > 0) //name might be unavailable, happened in GenMan sub-Params 361 362 ret += "."; 362 363 ret += id(prop); … … 367 368 { 368 369 SString name_dot_prop = nameDotProperty(prop); 369 if (getName() ==NULL || getLongName()==NULL) //name/longname might be unavailable, happened in GenMan sub-Params370 if (getName() == NULL || getLongName() == NULL) //name/longname might be unavailable, happened in GenMan sub-Params 370 371 return name_dot_prop; 371 372 372 373 if (strcmp(getName(), getLongName()) == 0) 373 374 { … … 422 423 // t+=SString(getName()); t+=':'; 423 424 for (i = 0; p = id(i); i++) 424 if ((!((fl = flags(i)) & PARAM_DONTSAVE)) && type(i)[0] !='p')425 if ((!((fl = flags(i)) & PARAM_DONTSAVE)) && type(i)[0] != 'p') 425 426 { 426 427 if (defdata && isequal(i, defdata)) … … 716 717 int ParamInterface::findGroupId(const char* name) 717 718 { 718 for(int i=0;i<getGroupCount();i++)719 if (!strcmp(grname(i),name))720 return i;721 return -1;719 for (int i = 0; i < getGroupCount(); i++) 720 if (!strcmp(grname(i), name)) 721 return i; 722 return -1; 722 723 } 723 724 … … 1131 1132 if (x < mn) { x = mn; result = PSET_HITMIN; } 1132 1133 else if (x > mx) { x = mx; result = PSET_HITMAX; } 1134 clipNegativeZeroIfNeeded(x, mn); //by the official standard, 0.0 == -0.0 and so it is not true that -0.0 < 0.0, so -0.0 would not be clipped to 0.0, i.e., if we defined the allowed range to be, for example, [0.0, 1.0], then without this call, x==-0.0 would be accepted. Since we never allow x==-0.0 for mn==0 past this point, we don't need to check below if the value changed from -0.0 to 0.0 (which would require comparing old and new std::signbit(x) etc.), because -0.0 could have never been set earlier. 1133 1135 } 1134 1136
Note: See TracChangeset
for help on using the changeset viewer.