crest icon indicating copy to clipboard operation
crest copied to clipboard

Question about kMinValue array

Open nobe0716 opened this issue 10 years ago • 1 comments

Hello, I have been modified yicies_solver for my term project.

I found that kMinValue[0](Minimum value of U_CHAR) does not give me correct value(0)


for(size_t i = 0 ; i < 1 ; ++i)
{
    fprintf(stdout, "\tkMinValue[%u, %s]: %lld\n", i, type_names[i], kMinValue[i]);
    fprintf(stdout, "\tkMaxValue[%u, %s]: %lld\n", i, type_names[i], kMaxValue[i]);
}

from above codes, I saw the result live below I know that kMaxValue is initialized at basic_types.cc as numeric_limits::min() but I wonder why I got the wrong result.

kMinValue[0, U_CHAR]: 154468404
kMaxValue[0, U_CHAR]: 255

Thanks.

nobe0716 avatar May 25 '15 07:05 nobe0716

If you are printing the value make sure you use it converted to an integer. This is because by default, the C++ i/o streams convert 8 bit integer values to their ASCII counterpart which can cause some problems, that can be seen with this:

#include <iostream>
#include <limits>
#include <cassert>

using namespace std;
using std::numeric_limits;

int main(){
	cout << numeric_limits<unsigned char>::min() << endl;

	cout << (int)numeric_limits<unsigned char>::min() << endl;
    return 0;
}

In this case the first print returns \00 and the second print returns the correct value: 0.

lmagoncalo avatar Dec 01 '18 03:12 lmagoncalo