eeros-project/eeros-framework

In Integrator, absolute min is not the real absolute min. (possible changes in pull request from me)

Opened this issue · 0 comments

In file includes/eeros/control/I.hpp on lines 162, 166, 170, 174.
In a valuetype of integer

If a minus is placed in front of the maximum value of an interger type, this always results in min+1:
Example:
int8_t min => -128
int8_t -max => -127

Test code (tested with https://www.programiz.com/cpp-programming/online-compiler/):

#include <iostream>
#include <inttypes.h>
#include <limits>
#include <string>
                
int main() {
// Write C++ code here
  typedef int32_t testtype;
    
  testtype upperLimit = std::numeric_limits<testtype>::max();
  testtype lowerLimit = -upperLimit;
                    
  std::cout << "Max:               " << std::to_string(upperLimit) << std::endl;
  std::cout << "Min (-max):       " << std::to_string(lowerLimit) << std::endl << std::endl;
                    
  testtype lowerLimit1 = std::numeric_limits<testtype>::lowest();
  std::cout << "Min (correct):    " << std::to_string(lowerLimit1) << std::endl << std::endl;

  std::cout << "Difference min's: " << std::to_string(lowerLimit - lowerLimit1)<< std::endl;
  
                
  return 0;
}